Skip to content

Commit

Permalink
[4.x] Uniform image validation (#9290)
Browse files Browse the repository at this point in the history
  • Loading branch information
royduin authored Jan 19, 2024
1 parent 67fd0a2 commit 95b81e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ArrayAccess;
use Facades\Statamic\Assets\Attributes;
use Facades\Statamic\Imaging\ImageValidator;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
Expand Down Expand Up @@ -485,7 +486,7 @@ public function isPreviewable()
*/
public function isImage()
{
return $this->extensionIsOneOf(['jpg', 'jpeg', 'png', 'gif', 'webp']);
return ImageValidator::isValidExtension($this->extension());
}

/**
Expand Down
8 changes: 5 additions & 3 deletions tests/Assets/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ private function uploadFileTest()
Storage::disk('test')->assertMissing('path/to/asset.jpg');

// This should only get called when glide processing source image on upload...
ImageValidator::shouldReceive('isValidImage')->never();
ImageValidator::partialMock()->shouldReceive('isValidImage')->never();

$return = $asset->upload(UploadedFile::fake()->image('asset.jpg', 13, 15));

Expand Down Expand Up @@ -1663,7 +1663,8 @@ public function it_can_upload_an_image_into_a_container_with_glide_config()
Facades\AssetContainer::shouldReceive('findByHandle')->with('test_container')->andReturn($this->container);
Storage::disk('test')->assertMissing('path/to/asset.jpg');

ImageValidator::shouldReceive('isValidImage')
ImageValidator::partialMock()
->shouldReceive('isValidImage')
->with('jpg', 'image/jpeg')
->andReturnTrue()
->once();
Expand Down Expand Up @@ -1710,7 +1711,8 @@ public function it_can_upload_an_image_into_a_container_with_new_extension_forma
Facades\AssetContainer::shouldReceive('findByHandle')->with('test_container')->andReturn($this->container);
Storage::disk('test')->assertMissing('path/to/asset.jpg');

ImageValidator::shouldReceive('isValidImage')
ImageValidator::partialMock()
->shouldReceive('isValidImage')
->with('jpg', 'image/jpeg')
->andReturnTrue()
->once();
Expand Down

0 comments on commit 95b81e6

Please sign in to comment.