Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Media/AllowedMimeTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ abstract class AllowedMimeTypes
'text/x-scriptzsh' => 'zsh',
];

/**
* Get all allowed types
*
* @return array
*/
public static function getAllowedTypes()
{
return array_keys(self::$allowed_mime_types);
}

public static function registerMimeTypes(string $key, array $mime_types): void
{
Expand Down
21 changes: 11 additions & 10 deletions tests/Feature/AdminModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Javaabu\Helpers\AdminModel\AdminModel;
use Javaabu\Helpers\AdminModel\IsAdminModel;
use Javaabu\Helpers\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class CategoryWithDateCast extends Model implements AdminModel
{
Expand Down Expand Up @@ -121,7 +122,7 @@ class AdminModelTest extends TestCase
{
use RefreshDatabase;

/** @test */
#[Test]
public function it_can_get_list_of_date_fields(): void
{
$this->assertEquals([
Expand All @@ -131,7 +132,7 @@ public function it_can_get_list_of_date_fields(): void
], CategoryWithDateCast::getDateFieldsList());
}

/** @test */
#[Test]
public function it_can_determine_if_an_attribute_is_an_allowed_date_field(): void
{
$this->assertTrue(CategoryWithDateCast::isAllowedDateField('published_at'));
Expand All @@ -140,23 +141,23 @@ public function it_can_determine_if_an_attribute_is_an_allowed_date_field(): voi
$this->assertFalse(CategoryWithDateCast::isAllowedDateField('name'));
}

/** @test */
#[Test]
public function it_can_determine_date_fields_from_date_casts(): void
{
$category = new CategoryWithDateCast();

$this->assertEquals(['published_at', 'created_at', 'updated_at'], $category->getDateAttributes());
}

/** @test */
#[Test]
public function it_can_determine_date_fields_from_datetime_casts(): void
{
$category = new CategoryWithDateTimeCast();

$this->assertEquals(['published_at', 'created_at', 'updated_at'], $category->getDateAttributes());
}

/** @test */
#[Test]
public function it_can_filter_models_by_date_range(): void
{
$category = new CategoryWithDateCast([
Expand All @@ -171,7 +172,7 @@ public function it_can_filter_models_by_date_range(): void
$this->assertEquals($category->id, $found->id);
}

/** @test */
#[Test]
public function it_can_search_models_using_a_partial_match(): void
{
$category = new CategoryWithSearchable(['name' => 'Apple', 'slug' => 'some-slug']);
Expand All @@ -182,7 +183,7 @@ public function it_can_search_models_using_a_partial_match(): void
$this->assertEquals($category->id, $found->id);
}

/** @test */
#[Test]
public function it_can_search_models_using_a_single_searchable(): void
{
$category = new CategoryWithSearchable(['name' => 'Apple', 'slug' => 'some-slug']);
Expand All @@ -194,7 +195,7 @@ public function it_can_search_models_using_a_single_searchable(): void
$this->assertNull(CategoryWithSearchable::search('some-slug')->first());
}

/** @test */
#[Test]
public function it_can_search_models_using_a_string_searchable(): void
{
$category = new CategoryWithStringSearchable(['name' => 'Apple', 'slug' => 'some-slug']);
Expand All @@ -206,7 +207,7 @@ public function it_can_search_models_using_a_string_searchable(): void
$this->assertNull(CategoryWithStringSearchable::search('some-slug')->first());
}

/** @test */
#[Test]
public function it_can_search_models_using_multiple_searchables(): void
{
$category = new CategoryWithMultipleSearchable(['name' => 'Apple', 'slug' => 'some-slug']);
Expand All @@ -221,7 +222,7 @@ public function it_can_search_models_using_multiple_searchables(): void
$this->assertEquals($category->id, $found->id);
}

/** @test */
#[Test]
public function it_can_search_models_without_searchable(): void
{
$category = new CategoryWithoutSearchable(['name' => 'Apple', 'slug' => 'some-slug']);
Expand Down
35 changes: 25 additions & 10 deletions tests/Feature/AllowedMimeTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Javaabu\Helpers\Media\AllowedMimeTypes;
use Javaabu\Helpers\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class AllowedMimeTypesTest extends TestCase
{
Expand All @@ -15,20 +16,20 @@ protected function setUp(): void
$this->app['config']->set('defaults.max_image_file_size', 1024 * 2);
}

/** @test */
#[Test]
public function it_can_get_the_max_file_size_based_on_multiple_file_types(): void
{
$this->assertEquals(1024 * 10, AllowedMimeTypes::getMaxFileSize(['document', 'image']));
}

/** @test */
#[Test]
public function it_can_get_the_max_file_size_based_on_file_type(): void
{
$this->assertEquals(1024 * 2, AllowedMimeTypes::getMaxFileSize('image'));
$this->assertEquals(1024 * 10, AllowedMimeTypes::getMaxFileSize('document'));
}

/** @test */
#[Test]
public function it_can_register_mimetypes(): void
{
// not registered
Expand All @@ -40,7 +41,7 @@ public function it_can_register_mimetypes(): void
$this->assertEquals(['text/plain'], AllowedMimeTypes::getAllowedMimeTypes('paper'));
}

/** @test */
#[Test]
public function it_can_register_file_size_settings(): void
{
// not registered
Expand All @@ -52,7 +53,7 @@ public function it_can_register_file_size_settings(): void
$this->assertEquals('max_document_file_size', AllowedMimeTypes::getFileSizeSetting('paper'));
}

/** @test */
#[Test]
public function it_can_register_mime_type_extensions(): void
{
// not registered
Expand All @@ -64,34 +65,34 @@ public function it_can_register_mime_type_extensions(): void
$this->assertEquals('pp', AllowedMimeTypes::getExtension('text/paper'));
}

/** @test */
#[Test]
public function it_can_get_file_size_setting_from_type(): void
{
$this->assertEquals('max_image_file_size', AllowedMimeTypes::getFileSizeSetting('icon'));
$this->assertEquals('max_image_file_size', AllowedMimeTypes::getFileSizeSetting('image'));
$this->assertEquals('max_upload_file_size', AllowedMimeTypes::getFileSizeSetting('document'));
}

/** @test */
#[Test]
public function it_can_get_file_extension_from_mime_type(): void
{
$this->assertEquals('jpeg', AllowedMimeTypes::getExtension('image/jpeg'));
}

/** @test */
#[Test]
public function it_can_get_file_extensions_from_mime_types(): void
{
$this->assertEquals(['jpeg', 'ico'], AllowedMimeTypes::getExtensions(['image/jpeg', 'image/x-icon', 'image/x-ico']));
}

/** @test */
#[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 */
#[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']);
Expand All @@ -101,4 +102,18 @@ public function it_can_check_if_a_given_mime_type_as_an_array_is_an_allowed_mime
$this->assertTrue($result);
}

#[Test]
public function it_can_get_all_allowed_types()
{
$result = AllowedMimeTypes::getAllowedTypes();
$this->assertEquals([
'image',
'icon',
'document',
'video',
'audio',
'excel',
'paper',
], $result);
}
}
3 changes: 2 additions & 1 deletion tests/Feature/HelpersServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Javaabu\Helpers\Tests\Feature;

use Javaabu\Helpers\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class HelpersServiceProviderTest extends TestCase
{
Expand All @@ -20,7 +21,7 @@ protected function tearDown(): void
parent::tearDown();
}

/** @test */
#[Test]
public function it_loads_local_helpers()
{
$this->withoutExceptionHandling();
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/ValidatorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Javaabu\Helpers\Tests\Feature;

use Javaabu\Helpers\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class ValidatorsTest extends TestCase
{
Expand Down Expand Up @@ -38,7 +39,7 @@ protected function tearDown(): void
parent::tearDown();
}

/** @test */
#[Test]
public function it_can_validate_a_slug()
{
$validator = validator(
Expand All @@ -53,7 +54,7 @@ public function it_can_validate_a_slug()
);
}

/** @test */
#[Test]
public function it_can_load_localized_validation()
{
$this->app->setLocale('dv');
Expand Down
7 changes: 4 additions & 3 deletions tests/Unit/EnumsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use Javaabu\Helpers\Enums\IsStatusEnum;
use Javaabu\Helpers\Enums\PublishStatuses;
use Javaabu\Helpers\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class EnumsTest extends TestCase
{
/** @test */
#[Test]
public function it_can_generate_enum_label()
{
$this->assertEquals('Pending', PublishStatuses::PENDING->getLabel());
Expand All @@ -21,7 +22,7 @@ public function it_can_generate_enum_label()
], PublishStatuses::getLabels());
}

/** @test */
#[Test]
public function it_can_see_that_an_enum_is_a_status_enum()
{
$this->assertTrue(in_array(IsStatusEnum::class, class_implements(PublishStatuses::class)));
Expand All @@ -31,7 +32,7 @@ public function it_can_see_that_an_enum_is_a_status_enum()
$this->assertTrue(method_exists(PublishStatuses::class, 'getColor'));
}

/** @test */
#[Test]
public function it_can_get_enum_color()
{
// Check if enum implements HasColor
Expand Down
7 changes: 4 additions & 3 deletions tests/Unit/HasCachedSoftDeleteCountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
use Illuminate\Foundation\Testing\RefreshDatabase;
use Javaabu\Helpers\Tests\TestCase;
use Javaabu\Helpers\Tests\TestSupport\Models\Post;
use PHPUnit\Framework\Attributes\Test;

class HasCachedSoftDeleteCountTest extends TestCase
{
use RefreshDatabase;

/** @test */
#[Test]
public function it_can_check_whether_a_model_has_soft_deletes()
{
$post = new Post([
Expand All @@ -30,7 +31,7 @@ public function it_can_check_whether_a_model_has_soft_deletes()
$this->assertFalse(Post::hasRecordsInTrash());
}

/** @test */
#[Test]
public function it_clears_the_cached_soft_deletes_when_a_model_is_deleted()
{
$post = new Post([
Expand All @@ -47,7 +48,7 @@ public function it_clears_the_cached_soft_deletes_when_a_model_is_deleted()
$this->assertFalse(cache()->has(Post::getSoftDeleteCacheKey()));
}

/** @test */
#[Test]
public function it_clears_the_cached_soft_deletes_when_a_model_is_restored()
{
$post = new Post([
Expand Down
Loading