@@ -3955,6 +3955,166 @@ public function testValidationExistsIsNotCalledUnnecessarily()
3955
3955
$ this ->assertTrue ($ v ->passes ());
3956
3956
}
3957
3957
3958
+ public function testValidateGtMessagesAreCorrect ()
3959
+ {
3960
+ $ trans = $ this ->getIlluminateArrayTranslator ();
3961
+ $ trans ->addLines ([
3962
+ 'validation.gt.numeric ' => 'The :attribute field must be greater than :value. ' ,
3963
+ 'validation.gt.string ' => 'The :attribute field must be greater than :value characters. ' ,
3964
+ 'validation.gt.file ' => 'The :attribute field must be greater than :value kilobytes. ' ,
3965
+ 'validation.gt.array ' => 'The :attribute field must have more than :value items. ' ,
3966
+ ], 'en ' );
3967
+
3968
+ $ file = $ this ->getMockBuilder (UploadedFile::class)->onlyMethods (['getSize ' , 'isValid ' ])->setConstructorArgs ([__FILE__ , false ])->getMock ();
3969
+ $ file ->expects ($ this ->any ())->method ('getSize ' )->willReturn (8919 );
3970
+ $ file ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
3971
+ $ otherFile = $ this ->getMockBuilder (UploadedFile::class)->onlyMethods (['getSize ' , 'isValid ' ])->setConstructorArgs ([__FILE__ , false ])->getMock ();
3972
+ $ otherFile ->expects ($ this ->any ())->method ('getSize ' )->willReturn (9216 );
3973
+ $ otherFile ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
3974
+
3975
+ $ v = new Validator ($ trans , [
3976
+ 'numeric ' => 7 ,
3977
+ 'string ' => 'abcd ' ,
3978
+ 'file ' => $ file ,
3979
+ 'array ' => [1 , 2 , 3 ],
3980
+ 'other_numeric ' => 10 ,
3981
+ 'other_string ' => 'abcde ' ,
3982
+ 'other_file ' => $ otherFile ,
3983
+ 'other_array ' => [1 , 2 , 3 , 4 ],
3984
+ ], [
3985
+ 'numeric ' => 'gt:other_numeric ' ,
3986
+ 'string ' => 'gt:other_string ' ,
3987
+ 'file ' => 'gt:other_file ' ,
3988
+ 'array ' => 'array|gt:other_array ' ,
3989
+ ]);
3990
+
3991
+ $ this ->assertFalse ($ v ->passes ());
3992
+ $ this ->assertEquals ('The numeric field must be greater than 10. ' , $ v ->messages ()->first ('numeric ' ));
3993
+ $ this ->assertEquals ('The string field must be greater than 5 characters. ' , $ v ->messages ()->first ('string ' ));
3994
+ $ this ->assertEquals ('The file field must be greater than 9 kilobytes. ' , $ v ->messages ()->first ('file ' ));
3995
+ $ this ->assertEquals ('The array field must have more than 4 items. ' , $ v ->messages ()->first ('array ' ));
3996
+ }
3997
+
3998
+ public function testValidateGteMessagesAreCorrect ()
3999
+ {
4000
+ $ trans = $ this ->getIlluminateArrayTranslator ();
4001
+ $ trans ->addLines ([
4002
+ 'validation.gte.numeric ' => 'The :attribute field must be greater than or equal to :value. ' ,
4003
+ 'validation.gte.string ' => 'The :attribute field must be greater than or equal to :value characters. ' ,
4004
+ 'validation.gte.file ' => 'The :attribute field must be greater than or equal to :value kilobytes. ' ,
4005
+ 'validation.gte.array ' => 'The :attribute field must have :value items or more. ' ,
4006
+ ], 'en ' );
4007
+
4008
+ $ file = $ this ->getMockBuilder (UploadedFile::class)->onlyMethods (['getSize ' , 'isValid ' ])->setConstructorArgs ([__FILE__ , false ])->getMock ();
4009
+ $ file ->expects ($ this ->any ())->method ('getSize ' )->willReturn (8919 );
4010
+ $ file ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
4011
+ $ otherFile = $ this ->getMockBuilder (UploadedFile::class)->onlyMethods (['getSize ' , 'isValid ' ])->setConstructorArgs ([__FILE__ , false ])->getMock ();
4012
+ $ otherFile ->expects ($ this ->any ())->method ('getSize ' )->willReturn (9216 );
4013
+ $ otherFile ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
4014
+
4015
+ $ v = new Validator ($ trans , [
4016
+ 'numeric ' => 7 ,
4017
+ 'string ' => 'abcd ' ,
4018
+ 'file ' => $ file ,
4019
+ 'array ' => [1 , 2 , 3 ],
4020
+ 'other_numeric ' => 10 ,
4021
+ 'other_string ' => 'abcde ' ,
4022
+ 'other_file ' => $ otherFile ,
4023
+ 'other_array ' => [1 , 2 , 3 , 4 ],
4024
+ ], [
4025
+ 'numeric ' => 'gte:other_numeric ' ,
4026
+ 'string ' => 'gte:other_string ' ,
4027
+ 'file ' => 'gte:other_file ' ,
4028
+ 'array ' => 'array|gte:other_array ' ,
4029
+ ]);
4030
+
4031
+ $ this ->assertFalse ($ v ->passes ());
4032
+ $ this ->assertEquals ('The numeric field must be greater than or equal to 10. ' , $ v ->messages ()->first ('numeric ' ));
4033
+ $ this ->assertEquals ('The string field must be greater than or equal to 5 characters. ' , $ v ->messages ()->first ('string ' ));
4034
+ $ this ->assertEquals ('The file field must be greater than or equal to 9 kilobytes. ' , $ v ->messages ()->first ('file ' ));
4035
+ $ this ->assertEquals ('The array field must have 4 items or more. ' , $ v ->messages ()->first ('array ' ));
4036
+ }
4037
+
4038
+ public function testValidateLtMessagesAreCorrect ()
4039
+ {
4040
+ $ trans = $ this ->getIlluminateArrayTranslator ();
4041
+ $ trans ->addLines ([
4042
+ 'validation.lt.numeric ' => 'The :attribute field must be less than :value. ' ,
4043
+ 'validation.lt.string ' => 'The :attribute field must be less than :value characters. ' ,
4044
+ 'validation.lt.file ' => 'The :attribute field must be less than :value kilobytes. ' ,
4045
+ 'validation.lt.array ' => 'The :attribute field must have less than :value items. ' ,
4046
+ ], 'en ' );
4047
+
4048
+ $ file = $ this ->getMockBuilder (UploadedFile::class)->onlyMethods (['getSize ' , 'isValid ' ])->setConstructorArgs ([__FILE__ , false ])->getMock ();
4049
+ $ file ->expects ($ this ->any ())->method ('getSize ' )->willReturn (8919 );
4050
+ $ file ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
4051
+ $ otherFile = $ this ->getMockBuilder (UploadedFile::class)->onlyMethods (['getSize ' , 'isValid ' ])->setConstructorArgs ([__FILE__ , false ])->getMock ();
4052
+ $ otherFile ->expects ($ this ->any ())->method ('getSize ' )->willReturn (8192 );
4053
+ $ otherFile ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
4054
+
4055
+ $ v = new Validator ($ trans , [
4056
+ 'numeric ' => 7 ,
4057
+ 'string ' => 'abcd ' ,
4058
+ 'file ' => $ file ,
4059
+ 'array ' => [1 , 2 , 3 ],
4060
+ 'other_numeric ' => 5 ,
4061
+ 'other_string ' => 'abc ' ,
4062
+ 'other_file ' => $ otherFile ,
4063
+ 'other_array ' => [1 , 2 ],
4064
+ ], [
4065
+ 'numeric ' => 'lt:other_numeric ' ,
4066
+ 'string ' => 'lt:other_string ' ,
4067
+ 'file ' => 'lt:other_file ' ,
4068
+ 'array ' => 'array|lt:other_array ' ,
4069
+ ]);
4070
+
4071
+ $ this ->assertFalse ($ v ->passes ());
4072
+ $ this ->assertEquals ('The numeric field must be less than 5. ' , $ v ->messages ()->first ('numeric ' ));
4073
+ $ this ->assertEquals ('The string field must be less than 3 characters. ' , $ v ->messages ()->first ('string ' ));
4074
+ $ this ->assertEquals ('The file field must be less than 8 kilobytes. ' , $ v ->messages ()->first ('file ' ));
4075
+ $ this ->assertEquals ('The array field must have less than 2 items. ' , $ v ->messages ()->first ('array ' ));
4076
+ }
4077
+
4078
+ public function testValidateLteMessagesAreCorrect ()
4079
+ {
4080
+ $ trans = $ this ->getIlluminateArrayTranslator ();
4081
+ $ trans ->addLines ([
4082
+ 'validation.lte.numeric ' => 'The :attribute field must be less than or equal to :value. ' ,
4083
+ 'validation.lte.string ' => 'The :attribute field must be less than or equal to :value characters. ' ,
4084
+ 'validation.lte.file ' => 'The :attribute field must be less than or equal to :value kilobytes. ' ,
4085
+ 'validation.lte.array ' => 'The :attribute field must not have more than :value items. ' ,
4086
+ ], 'en ' );
4087
+
4088
+ $ file = $ this ->getMockBuilder (UploadedFile::class)->onlyMethods (['getSize ' , 'isValid ' ])->setConstructorArgs ([__FILE__ , false ])->getMock ();
4089
+ $ file ->expects ($ this ->any ())->method ('getSize ' )->willReturn (8919 );
4090
+ $ file ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
4091
+ $ otherFile = $ this ->getMockBuilder (UploadedFile::class)->onlyMethods (['getSize ' , 'isValid ' ])->setConstructorArgs ([__FILE__ , false ])->getMock ();
4092
+ $ otherFile ->expects ($ this ->any ())->method ('getSize ' )->willReturn (8192 );
4093
+ $ otherFile ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
4094
+
4095
+ $ v = new Validator ($ trans , [
4096
+ 'numeric ' => 7 ,
4097
+ 'string ' => 'abcd ' ,
4098
+ 'file ' => $ file ,
4099
+ 'array ' => [1 , 2 , 3 ],
4100
+ 'other_numeric ' => 5 ,
4101
+ 'other_string ' => 'abc ' ,
4102
+ 'other_file ' => $ otherFile ,
4103
+ 'other_array ' => [1 , 2 ],
4104
+ ], [
4105
+ 'numeric ' => 'lte:other_numeric ' ,
4106
+ 'string ' => 'lte:other_string ' ,
4107
+ 'file ' => 'lte:other_file ' ,
4108
+ 'array ' => 'array|lte:other_array ' ,
4109
+ ]);
4110
+
4111
+ $ this ->assertFalse ($ v ->passes ());
4112
+ $ this ->assertEquals ('The numeric field must be less than or equal to 5. ' , $ v ->messages ()->first ('numeric ' ));
4113
+ $ this ->assertEquals ('The string field must be less than or equal to 3 characters. ' , $ v ->messages ()->first ('string ' ));
4114
+ $ this ->assertEquals ('The file field must be less than or equal to 8 kilobytes. ' , $ v ->messages ()->first ('file ' ));
4115
+ $ this ->assertEquals ('The array field must not have more than 2 items. ' , $ v ->messages ()->first ('array ' ));
4116
+ }
4117
+
3958
4118
public function testValidateIp ()
3959
4119
{
3960
4120
$ trans = $ this ->getIlluminateArrayTranslator ();
@@ -8917,6 +9077,9 @@ public function testItTrimsSpaceFromParameters()
8917
9077
'foo ' => '4 ' ,
8918
9078
' foo ' => ' 5 ' ,
8919
9079
' foo ' => ' 6 ' ,
9080
+ 'foo_str ' => 'abcd ' ,
9081
+ ' foo_str ' => ' abcd ' ,
9082
+ ' foo_str ' => ' abcd ' ,
8920
9083
], [
8921
9084
'min ' => 'numeric|min: 20 ' ,
8922
9085
'min_str ' => 'min: 5 ' ,
@@ -8925,16 +9088,16 @@ public function testItTrimsSpaceFromParameters()
8925
9088
'between_str ' => "between: \t 5, 6 \n" ,
8926
9089
'gt ' => 'numeric|gt: 4 ' ,
8927
9090
'gt_field ' => 'numeric|gt:foo ' ,
8928
- 'gt_str ' => 'gt:foo ' ,
9091
+ 'gt_str ' => 'gt:foo_str ' ,
8929
9092
'lt ' => 'numeric|lt: 6 ' ,
8930
9093
'lt_field ' => 'numeric|lt: foo ' ,
8931
- 'lt_str ' => 'lt: foo ' ,
9094
+ 'lt_str ' => 'lt: foo_str ' ,
8932
9095
'gte ' => 'numeric|gte: 5 ' ,
8933
9096
'gte_field ' => 'numeric|gte: foo ' ,
8934
- 'gte_str ' => 'gte: foo ' ,
9097
+ 'gte_str ' => 'gte: foo_str ' ,
8935
9098
'lte ' => 'numeric|lte: 5 ' ,
8936
9099
'lte_field ' => 'numeric|lte: foo ' ,
8937
- 'lte_str ' => 'lte: foo ' ,
9100
+ 'lte_str ' => 'lte: foo_str ' ,
8938
9101
'max ' => 'numeric|max: 20 ' ,
8939
9102
'max_str ' => 'max: 5 ' ,
8940
9103
'size ' => 'numeric|size: 20 ' ,
@@ -8967,6 +9130,9 @@ public function testItTrimsSpaceFromParameters()
8967
9130
'foo ' => '4 ' ,
8968
9131
' foo ' => ' 5 ' ,
8969
9132
' foo ' => ' 6 ' ,
9133
+ 'foo_str ' => 'abcd ' ,
9134
+ ' foo_str ' => ' abcd ' ,
9135
+ ' foo_str ' => ' abcd ' ,
8970
9136
], [
8971
9137
'min ' => 'numeric|min: 21 ' ,
8972
9138
'min_str ' => 'min: 6 ' ,
@@ -8975,16 +9141,16 @@ public function testItTrimsSpaceFromParameters()
8975
9141
'between_str ' => "between: \t 6, 7 \n" ,
8976
9142
'gt ' => 'numeric|gt: 5 ' ,
8977
9143
'gt_field ' => 'numeric|gt: foo ' ,
8978
- 'gt_str ' => 'gt: foo ' ,
9144
+ 'gt_str ' => 'gt: foo_str ' ,
8979
9145
'lt ' => 'numeric|lt: 5 ' ,
8980
9146
'lt_field ' => 'numeric|lt: foo ' ,
8981
- 'lt_str ' => 'lt: foo ' ,
9147
+ 'lt_str ' => 'lt: foo_str ' ,
8982
9148
'gte ' => 'numeric|gte: 6 ' ,
8983
9149
'gte_field ' => 'numeric|gte: foo ' ,
8984
- 'gte_str ' => 'gte: foo ' ,
9150
+ 'gte_str ' => 'gte: foo_str ' ,
8985
9151
'lte ' => 'numeric|lte: 4 ' ,
8986
9152
'lte_field ' => 'numeric|lte:foo ' ,
8987
- 'lte_str ' => 'lte:foo ' ,
9153
+ 'lte_str ' => 'lte:foo_str ' ,
8988
9154
'max ' => 'numeric|max: 19 ' ,
8989
9155
'max_str ' => 'max: 4 ' ,
8990
9156
'size ' => 'numeric|size: 19 ' ,
0 commit comments