Skip to content

Commit

Permalink
[11.x] Add support for AVIF image format in validation
Browse files Browse the repository at this point in the history
  • Loading branch information
robertotcestari committed Aug 22, 2024
1 parent 2835e2b commit 907b414
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ public function validateHexColor($attribute, $value)
*/
public function validateImage($attribute, $value)
{
return $this->validateMimes($attribute, $value, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']);
return $this->validateMimes($attribute, $value, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'avif']);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Validation/ValidationFileRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ public function testImage()
File::image(),
UploadedFile::fake()->image('foo.png'),
);

$this->passes(
File::image(),
UploadedFile::fake()->image('foo.avif'),
['validation.image']
);
}

public function testSize()
Expand Down
13 changes: 3 additions & 10 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4846,12 +4846,6 @@ public function testValidateImage()
$v = new Validator($trans, ['x' => $file2], ['x' => 'image']);
$this->assertTrue($v->passes());

$file2 = $this->getMockBuilder(UploadedFile::class)->onlyMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file2->expects($this->any())->method('guessExtension')->willReturn('jpg');
$file2->expects($this->any())->method('getClientOriginalExtension')->willReturn('jpg');
$v = new Validator($trans, ['x' => $file2], ['x' => 'image']);
$this->assertTrue($v->passes());

$file3 = $this->getMockBuilder(UploadedFile::class)->onlyMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file3->expects($this->any())->method('guessExtension')->willReturn('gif');
$file3->expects($this->any())->method('getClientOriginalExtension')->willReturn('gif');
Expand Down Expand Up @@ -4883,10 +4877,9 @@ public function testValidateImage()
$v = new Validator($trans, ['x' => $file7], ['x' => 'Image']);
$this->assertTrue($v->passes());

$file2 = $this->getMockBuilder(UploadedFile::class)->onlyMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file2->expects($this->any())->method('guessExtension')->willReturn('jpg');
$file2->expects($this->any())->method('getClientOriginalExtension')->willReturn('jpg');
$v = new Validator($trans, ['x' => $file2], ['x' => 'Image']);
$file8 = $this->getMockBuilder(UploadedFile::class)->onlyMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file8->expects($this->any())->method('guessExtension')->willReturn('avif');
$file8->expects($this->any())->method('getClientOriginalExtension')->willReturn('avif'); $v = new Validator($trans, ['x' => $file8], ['x' => 'Image']);
$this->assertTrue($v->passes());
}

Expand Down

0 comments on commit 907b414

Please sign in to comment.