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:
2025-11-10 02:12:28 +01:00
parent 74d50a29cc
commit 2d53270056
53 changed files with 5699 additions and 15 deletions

View File

@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
use App\Domain\Asset\ValueObjects\VariantName;
describe('VariantName', function () {
it('can be created from valid string', function () {
$variant = VariantName::fromString('1200w.webp');
expect($variant->toString())->toBe('1200w.webp');
expect((string) $variant)->toBe('1200w.webp');
});
it('accepts variant names with scale', function () {
$variant = VariantName::fromString('thumb@1x');
expect($variant->toString())->toBe('thumb@1x');
expect($variant->getScale())->toBe('1x');
});
it('accepts variant names with scale and extension', function () {
$variant = VariantName::fromString('thumb@2x.webp');
expect($variant->toString())->toBe('thumb@2x.webp');
expect($variant->getScale())->toBe('2x');
expect($variant->getExtension())->toBe('webp');
});
it('accepts variant names without scale or extension', function () {
$variant = VariantName::fromString('cover');
expect($variant->toString())->toBe('cover');
expect($variant->getScale())->toBeNull();
expect($variant->getExtension())->toBeNull();
});
it('extracts extension correctly', function () {
expect(VariantName::fromString('image.webp')->getExtension())->toBe('webp');
expect(VariantName::fromString('image.jpg')->getExtension())->toBe('jpg');
expect(VariantName::fromString('waveform.json')->getExtension())->toBe('json');
});
it('extracts scale correctly', function () {
expect(VariantName::fromString('thumb@1x')->getScale())->toBe('1x');
expect(VariantName::fromString('thumb@2x')->getScale())->toBe('2x');
expect(VariantName::fromString('cover@3x.webp')->getScale())->toBe('3x');
});
it('throws exception for empty string', function () {
expect(fn () => VariantName::fromString(''))
->toThrow(InvalidArgumentException::class, 'Variant name cannot be empty');
});
it('throws exception for invalid format', function () {
expect(fn () => VariantName::fromString('invalid@format'))
->toThrow(InvalidArgumentException::class, 'Invalid variant name format');
expect(fn () => VariantName::fromString('UPPERCASE'))
->toThrow(InvalidArgumentException::class);
expect(fn () => VariantName::fromString('with spaces'))
->toThrow(InvalidArgumentException::class);
});
it('throws exception for variant name exceeding 100 characters', function () {
$longName = str_repeat('a', 101);
expect(fn () => VariantName::fromString($longName))
->toThrow(InvalidArgumentException::class, 'Variant name cannot exceed 100 characters');
});
it('can compare two VariantNames for equality', function () {
$variant1 = VariantName::fromString('1200w.webp');
$variant2 = VariantName::fromString('1200w.webp');
$variant3 = VariantName::fromString('800w.webp');
expect($variant1->equals($variant2))->toBeTrue();
expect($variant1->equals($variant3))->toBeFalse();
});
});