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:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Domain\Asset\ValueObjects\AssetId;
|
||||
use App\Domain\Asset\ValueObjects\ObjectKeyGenerator;
|
||||
use App\Domain\Asset\ValueObjects\VariantName;
|
||||
use App\Framework\DateTime\SystemClock;
|
||||
use App\Framework\Storage\ValueObjects\ObjectKey;
|
||||
|
||||
describe('ObjectKeyGenerator', function () {
|
||||
it('generates key for original asset', function () {
|
||||
$clock = new SystemClock();
|
||||
$assetId = AssetId::generate($clock);
|
||||
$now = new \DateTimeImmutable();
|
||||
|
||||
$key = ObjectKeyGenerator::generateKey($assetId, 'jpg');
|
||||
|
||||
expect($key)->toBeInstanceOf(ObjectKey::class);
|
||||
expect($key->toString())->toContain('orig');
|
||||
expect($key->toString())->toContain($now->format('Y'));
|
||||
expect($key->toString())->toContain($now->format('m'));
|
||||
expect($key->toString())->toContain($now->format('d'));
|
||||
expect($key->toString())->toContain($assetId->toString());
|
||||
expect($key->toString())->toEndWith('.jpg');
|
||||
});
|
||||
|
||||
it('generates key with custom prefix', function () {
|
||||
$clock = new SystemClock();
|
||||
$assetId = AssetId::generate($clock);
|
||||
|
||||
$key = ObjectKeyGenerator::generateKey($assetId, 'png', 'custom');
|
||||
|
||||
expect($key->toString())->toStartWith('custom/');
|
||||
});
|
||||
|
||||
it('removes leading dot from extension', function () {
|
||||
$clock = new SystemClock();
|
||||
$assetId = AssetId::generate($clock);
|
||||
|
||||
$key1 = ObjectKeyGenerator::generateKey($assetId, '.jpg');
|
||||
$key2 = ObjectKeyGenerator::generateKey($assetId, 'jpg');
|
||||
|
||||
expect($key1->toString())->toBe($key2->toString());
|
||||
});
|
||||
|
||||
it('generates variant key', function () {
|
||||
$clock = new SystemClock();
|
||||
$assetId = AssetId::generate($clock);
|
||||
$variant = VariantName::fromString('1200w.webp');
|
||||
$now = new \DateTimeImmutable();
|
||||
|
||||
$key = ObjectKeyGenerator::generateVariantKey($assetId, $variant);
|
||||
|
||||
expect($key)->toBeInstanceOf(ObjectKey::class);
|
||||
expect($key->toString())->toContain('variants');
|
||||
expect($key->toString())->toContain($now->format('Y'));
|
||||
expect($key->toString())->toContain($now->format('m'));
|
||||
expect($key->toString())->toContain($now->format('d'));
|
||||
expect($key->toString())->toContain($assetId->toString());
|
||||
expect($key->toString())->toEndWith('/1200w.webp');
|
||||
});
|
||||
|
||||
it('generates variant key with custom prefix', function () {
|
||||
$clock = new SystemClock();
|
||||
$assetId = AssetId::generate($clock);
|
||||
$variant = VariantName::fromString('thumb@1x');
|
||||
|
||||
$key = ObjectKeyGenerator::generateVariantKey($assetId, $variant, 'custom-variants');
|
||||
|
||||
expect($key->toString())->toStartWith('custom-variants/');
|
||||
});
|
||||
|
||||
it('generates keys with date-based structure', function () {
|
||||
$clock = new SystemClock();
|
||||
$assetId = AssetId::generate($clock);
|
||||
$now = new \DateTimeImmutable();
|
||||
|
||||
$key = ObjectKeyGenerator::generateKey($assetId, 'jpg');
|
||||
|
||||
$expectedPattern = sprintf(
|
||||
'/^orig\/%s\/%s\/%s\/%s\.jpg$/',
|
||||
$now->format('Y'),
|
||||
$now->format('m'),
|
||||
$now->format('d'),
|
||||
preg_quote($assetId->toString(), '/')
|
||||
);
|
||||
|
||||
expect($key->toString())->toMatch($expectedPattern);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user