feat(cms,asset): add comprehensive test suite and finalize modules
- Add comprehensive test suite for CMS and Asset modules using Pest Framework - Implement ContentTypeService::delete() protection against deletion of in-use content types - Add CannotDeleteContentTypeInUseException for better error handling - Fix DerivatPipelineRegistry::getAllPipelines() to handle object uniqueness correctly - Fix VariantName::getScale() to correctly parse scales with file extensions - Update CMS module documentation with new features, exceptions, and test coverage - Add CmsTestHelpers and AssetTestHelpers for test data factories - Fix BlockTypeRegistry to be immutable after construction - Update ContentTypeService to check for associated content before deletion - Improve BlockRendererRegistry initialization Test coverage: - Value Objects: All CMS and Asset value objects - Services: ContentService, ContentTypeService, SlugGenerator, BlockValidator, ContentLocalizationService, AssetService, DeduplicationService, MetadataExtractor - Repositories: All database repositories with mocked connections - Rendering: Block renderers and ContentRenderer - Controllers: API endpoints for both modules 254 tests passing, 38 remaining (mostly image processing pipeline tests)
This commit is contained in:
69
tests/Unit/Domain/Cms/ValueObjects/LocaleTest.php
Normal file
69
tests/Unit/Domain/Cms/ValueObjects/LocaleTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Domain\Cms\ValueObjects\Locale;
|
||||
|
||||
describe('Locale', function () {
|
||||
it('can be created from valid locale string', function () {
|
||||
$locale = Locale::fromString('en');
|
||||
|
||||
expect($locale->toString())->toBe('en');
|
||||
expect((string) $locale)->toBe('en');
|
||||
});
|
||||
|
||||
it('accepts locale with region', function () {
|
||||
$locale = Locale::fromString('en-US');
|
||||
|
||||
expect($locale->toString())->toBe('en-US');
|
||||
expect($locale->getLanguage())->toBe('en');
|
||||
expect($locale->getRegion())->toBe('US');
|
||||
});
|
||||
|
||||
it('has factory methods for common locales', function () {
|
||||
expect(Locale::english()->toString())->toBe('en');
|
||||
expect(Locale::german()->toString())->toBe('de');
|
||||
expect(Locale::french()->toString())->toBe('fr');
|
||||
expect(Locale::spanish()->toString())->toBe('es');
|
||||
});
|
||||
|
||||
it('extracts language from locale', function () {
|
||||
expect(Locale::fromString('en')->getLanguage())->toBe('en');
|
||||
expect(Locale::fromString('en-US')->getLanguage())->toBe('en');
|
||||
expect(Locale::fromString('de-CH')->getLanguage())->toBe('de');
|
||||
});
|
||||
|
||||
it('extracts region from locale with region', function () {
|
||||
expect(Locale::fromString('en-US')->getRegion())->toBe('US');
|
||||
expect(Locale::fromString('de-CH')->getRegion())->toBe('CH');
|
||||
});
|
||||
|
||||
it('returns null for region when locale has no region', function () {
|
||||
expect(Locale::fromString('en')->getRegion())->toBeNull();
|
||||
expect(Locale::fromString('de')->getRegion())->toBeNull();
|
||||
});
|
||||
|
||||
it('throws exception for invalid locale format', function () {
|
||||
expect(fn () => Locale::fromString('invalid'))
|
||||
->toThrow(InvalidArgumentException::class, 'Invalid locale format');
|
||||
|
||||
expect(fn () => Locale::fromString('EN'))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
|
||||
expect(fn () => Locale::fromString('en-us'))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
});
|
||||
|
||||
it('can compare two Locales for equality', function () {
|
||||
$locale1 = Locale::fromString('en');
|
||||
$locale2 = Locale::fromString('en');
|
||||
$locale3 = Locale::fromString('de');
|
||||
|
||||
expect($locale1->equals($locale2))->toBeTrue();
|
||||
expect($locale1->equals($locale3))->toBeFalse();
|
||||
|
||||
$locale4 = Locale::fromString('en-US');
|
||||
expect($locale1->equals($locale4))->toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user