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,92 @@
<?php
declare(strict_types=1);
namespace Tests\Support;
use App\Domain\Asset\Entities\Asset;
use App\Domain\Asset\Entities\AssetTag;
use App\Domain\Asset\Entities\AssetVariant;
use App\Domain\Asset\ValueObjects\AssetId;
use App\Domain\Asset\ValueObjects\AssetMetadata;
use App\Domain\Asset\ValueObjects\VariantName;
use App\Framework\Core\ValueObjects\FileSize;
use App\Framework\Core\ValueObjects\Hash;
use App\Framework\Core\ValueObjects\HashAlgorithm;
use App\Framework\Core\ValueObjects\Timestamp;
use App\Framework\DateTime\Clock;
use App\Framework\Http\MimeType;
use App\Framework\Storage\ValueObjects\BucketName;
use App\Framework\Storage\ValueObjects\ObjectKey;
final class AssetTestHelpers
{
public static function createAsset(
Clock $clock,
?AssetId $id = null,
?BucketName $bucket = null,
?ObjectKey $key = null,
?MimeType $mime = null,
?FileSize $bytes = null,
?Hash $sha256 = null,
?AssetMetadata $meta = null
): Asset {
return new Asset(
id: $id ?? AssetId::generate($clock),
bucket: $bucket ?? BucketName::fromString('media'),
key: $key ?? ObjectKey::fromString('orig/2025/01/15/test.jpg'),
mime: $mime ?? MimeType::IMAGE_JPEG,
bytes: $bytes ?? FileSize::fromBytes(1024),
sha256: $sha256 ?? Hash::create('test-content', HashAlgorithm::SHA256),
meta: $meta ?? AssetMetadata::empty(),
createdAt: Timestamp::now()
);
}
public static function createAssetVariant(
AssetId $assetId,
?VariantName $variant = null,
?BucketName $bucket = null,
?ObjectKey $key = null,
?MimeType $mime = null,
?FileSize $bytes = null,
?AssetMetadata $meta = null
): AssetVariant {
return new AssetVariant(
assetId: $assetId,
variant: $variant ?? VariantName::fromString('1200w.webp'),
bucket: $bucket ?? BucketName::fromString('variants'),
key: $key ?? ObjectKey::fromString('variants/2025/01/15/test/1200w.webp'),
mime: $mime ?? MimeType::IMAGE_WEBP,
bytes: $bytes ?? FileSize::fromBytes(512),
meta: $meta ?? AssetMetadata::fromArray(['width' => 1200, 'height' => 675])
);
}
public static function createAssetTag(
AssetId $assetId,
string $tag
): AssetTag {
return new AssetTag(
assetId: $assetId,
tag: $tag
);
}
public static function createTestImageContent(): string
{
// Return a minimal valid JPEG header
return "\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xFF\xD9";
}
public static function createAssetWithDimensions(
Clock $clock,
int $width,
int $height
): Asset {
$meta = AssetMetadata::empty()->withDimensions($width, $height);
return self::createAsset($clock, meta: $meta);
}
}