Skip to content

Commit 88b7160

Browse files
Enhance Email and Image Dimensions Validation Tests (#54897)
* Added new test cases for special values, constraint order, value overriding in `ValidationDimensionsRuleTest`. * Add more email validation cases to the testBasic method.
1 parent 18a3622 commit 88b7160

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

tests/Validation/ValidationDimensionsRuleTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,42 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
5353
$this->assertSame('dimensions:min_ratio=0.5,max_ratio=0.33333333333333', (string) $rule);
5454
}
5555

56+
public function testItCorrectlyFormatsWithSpecialValues()
57+
{
58+
$rule = new Dimensions();
59+
60+
$this->assertSame('dimensions:', (string) $rule);
61+
62+
$rule = Rule::dimensions()->width(-100)->height(-200);
63+
64+
$this->assertSame('dimensions:width=-100,height=-200', (string) $rule);
65+
66+
$rule = Rule::dimensions()->width('300')->height('400');
67+
68+
$this->assertSame('dimensions:width=300,height=400', (string) $rule);
69+
}
70+
71+
public function testDimensionsRuleMaintainsCorrectOrder()
72+
{
73+
$rule = Rule::dimensions()->minWidth(100)->width(200)->maxWidth(300);
74+
75+
$this->assertSame('dimensions:min_width=100,width=200,max_width=300', (string) $rule);
76+
}
77+
78+
public function testOverridingValues()
79+
{
80+
$rule = Rule::dimensions()->width(100)->width(500);
81+
82+
$this->assertSame('dimensions:width=500', (string) $rule);
83+
}
84+
85+
public function testRatioBetweenOverridesMinAndMaxRatio()
86+
{
87+
$rule = Rule::dimensions()->minRatio(0.5)->maxRatio(2.0)->ratioBetween(1, 1.5);
88+
89+
$this->assertSame('dimensions:min_ratio=1,max_ratio=1.5', (string) $rule);
90+
}
91+
5692
public function testGeneratesTheCorrectValidationMessages()
5793
{
5894
$rule = Rule::dimensions()

tests/Validation/ValidationEmailRuleTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ public function testBasic()
3333
['The '.self::ATTRIBUTE_REPLACED.' must be a valid email address.']
3434
);
3535

36+
$this->fails(
37+
Email::default(),
38+
12345,
39+
[Email::class]
40+
);
41+
42+
$this->fails(
43+
Rule::email(),
44+
12345,
45+
[Email::class]
46+
);
47+
3648
$this->passes(
3749
Email::default(),
3850
'taylor@laravel.com'
@@ -43,6 +55,16 @@ public function testBasic()
4355
'taylor@laravel.com'
4456
);
4557

58+
$this->passes(
59+
Rule::email(),
60+
['taylor@laravel.com'],
61+
);
62+
63+
$this->passes(
64+
Email::default(),
65+
['taylor@laravel.com'],
66+
);
67+
4668
$this->passes(Email::default(), null);
4769

4870
$this->passes(Rule::email(), null);

0 commit comments

Comments
 (0)