Skip to content

Commit

Permalink
[5.4] Add test for validation of ratio with no fractional part (#17980)
Browse files Browse the repository at this point in the history
* Convert fixtures to PNG format

* Add test for validation of ratio with no fractional part
  • Loading branch information
vlakoff authored and taylorotwell committed Feb 17, 2017
1 parent 4fbd2a3 commit eb1ea6e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ public function testClassBasedCustomReplacers()

public function testNestedAttributesAreReplacedInDimensions()
{
// Knowing that demo image.gif has width = 3 and height = 2
$uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/image.gif', '', null, null, null, true);
// Knowing that demo image.png has width = 3 and height = 2
$uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/image.png', '', null, null, null, true);

$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.dimensions' => ':min_width :max_height :ratio'], 'en');
Expand Down Expand Up @@ -1895,8 +1895,8 @@ public function testValidateImage()

public function testValidateImageDimensions()
{
// Knowing that demo image.gif has width = 3 and height = 2
$uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/image.gif', '', null, null, null, true);
// Knowing that demo image.png has width = 3 and height = 2
$uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/image.png', '', null, null, null, true);
$trans = $this->getIlluminateArrayTranslator();

$v = new Validator($trans, ['x' => 'file'], ['x' => 'dimensions']);
Expand Down Expand Up @@ -1944,8 +1944,16 @@ public function testValidateImageDimensions()
$v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:ratio=1']);
$this->assertTrue($v->fails());

// Knowing that demo image2.png has width = 4 and height = 2
$uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/image2.png', '', null, null, null, true);
$trans = $this->getIlluminateArrayTranslator();

// Ensure validation doesn't erroneously fail when ratio has no fractional part
$v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:ratio=2/1']);
$this->assertTrue($v->passes());

// This test fails without suppressing warnings on getimagesize() due to a read error.
$emptyUploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/empty.gif', '', null, null, null, true);
$emptyUploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/empty.png', '', null, null, null, true);
$trans = $this->getIlluminateArrayTranslator();

$v = new Validator($trans, ['x' => $emptyUploadedFile], ['x' => 'dimensions:min_width=1']);
Expand Down
File renamed without changes
Binary file removed tests/Validation/fixtures/image.gif
Binary file not shown.
Binary file added tests/Validation/fixtures/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Validation/fixtures/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit eb1ea6e

Please sign in to comment.