Skip to content

Commit

Permalink
isAllowedMimeType can actually check for multiple in one go. Update s…
Browse files Browse the repository at this point in the history
…ignature to allow for array params.

Also tests.
  • Loading branch information
athphane committed May 14, 2024
1 parent f40c2bd commit 6b08f6a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Media/AllowedMimeTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function getAllowedMimeTypesString(string $type, string $separator
* @param string $type
* @return boolean
*/
public static function isAllowedMimeType(string $mime_type, string $type): bool
public static function isAllowedMimeType(string $mime_type, array|string $type): bool
{
return in_array($mime_type, self::getAllowedMimeTypes($type));
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Feature/AllowedMimeTypesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Javaabu\Helpers\Tests\Feature;

use Javaabu\Helpers\Media\AllowedMimeTypes;
use Javaabu\Helpers\Tests\TestCase;

class AllowedMimeTypesTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
}

/** @test */
public function it_can_check_if_a_given_mime_type_as_a_string_is_an_allowed_mime_type(): void
{
$result = AllowedMimeTypes::isAllowedMimeType('image/jpeg', 'image');
$this->assertTrue($result);
}

/** @test */
public function it_can_check_if_a_given_mime_type_as_an_array_is_an_allowed_mime_type()
{
$result = AllowedMimeTypes::isAllowedMimeType('image/jpeg', ['image', 'video']);
$this->assertTrue($result);

$result = AllowedMimeTypes::isAllowedMimeType('video/mp4', ['image', 'video']);
$this->assertTrue($result);
}

}

0 comments on commit 6b08f6a

Please sign in to comment.