Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Adding minRatio & maxRatio rules on Dimension validation ruleset #52482

Merged
merged 10 commits into from
Sep 5, 2024
Prev Previous commit
Next Next commit
test(dim-ratio): add more tests for coverage for the new methods on t…
…he Dimension rule test
  • Loading branch information
CamKem committed Aug 14, 2024
commit 3602d831c1d44e5d989c836a9a6322c56f8c4bed
9 changes: 9 additions & 0 deletions tests/Validation/ValidationDimensionsRuleTest.php
Original file line number Diff line number Diff line change
@@ -38,5 +38,14 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
$rule->width('200');
});
$this->assertSame('dimensions:height=100', (string) $rule);

$rule = Rule::dimensions()
->minRatio(1/2)
->maxRatio(1/3);
$this->assertSame('dimensions:min_ratio=0.5,max_ratio=0.33333333333333', (string) $rule);

$rule = Rule::dimensions()
->ratioRange(min: 1/2, max: 1/3);
$this->assertSame('dimensions:min_ratio=0.5,max_ratio=0.33333333333333', (string) $rule);
}
}
56 changes: 56 additions & 0 deletions tests/Validation/ValidationImageFileRuleTest.php
Original file line number Diff line number Diff line change
@@ -44,6 +44,62 @@ public function testDimensionsWithCustomImageSizeMethod()
);
}

public function testDimentionWithTheRatioMethod()
{
$this->fails(
File::image()->dimensions(Rule::dimensions()->ratio(1)),
UploadedFile::fake()->image('foo.png', 105, 100),
['validation.dimensions'],
);

$this->passes(
File::image()->dimensions(Rule::dimensions()->ratio(1)),
UploadedFile::fake()->image('foo.png', 100, 100),
);
}

public function testDimentionWithTheMinRatioMethod()
{
$this->fails(
File::image()->dimensions(Rule::dimensions()->minRatio(1/2)),
UploadedFile::fake()->image('foo.png', 100, 100),
['validation.dimensions'],
);

$this->passes(
File::image()->dimensions(Rule::dimensions()->minRatio(1/2)),
UploadedFile::fake()->image('foo.png', 100, 200),
);
}

public function testDimentionWithTheMaxRatioMethod()
{
$this->fails(
File::image()->dimensions(Rule::dimensions()->maxRatio(1/2)),
UploadedFile::fake()->image('foo.png', 100, 300),
['validation.dimensions'],
);

$this->passes(
File::image()->dimensions(Rule::dimensions()->maxRatio(1/2)),
UploadedFile::fake()->image('foo.png', 100, 100),
);
}

public function testDimentionWithTheRatioRangeMethod()
{
$this->fails(
File::image()->dimensions(Rule::dimensions()->ratioRange(1/2, 1/3)),
UploadedFile::fake()->image('foo.png', 100, 100),
['validation.dimensions'],
);

$this->passes(
File::image()->dimensions(Rule::dimensions()->ratioRange(1/2, 1/3)),
UploadedFile::fake()->image('foo.png', 100, 200),
);
}

protected function fails($rule, $values, $messages)
{
$this->assertValidationRules($rule, $values, false, $messages);