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:
92
tests/Support/AssetTestHelpers.php
Normal file
92
tests/Support/AssetTestHelpers.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
127
tests/Support/CmsTestHelpers.php
Normal file
127
tests/Support/CmsTestHelpers.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Support;
|
||||
|
||||
use App\Domain\Cms\Entities\Content;
|
||||
use App\Domain\Cms\Entities\ContentType;
|
||||
use App\Domain\Cms\Enums\ContentStatus;
|
||||
use App\Domain\Cms\ValueObjects\BlockData;
|
||||
use App\Domain\Cms\ValueObjects\BlockId;
|
||||
use App\Domain\Cms\ValueObjects\BlockType;
|
||||
use App\Domain\Cms\ValueObjects\ContentBlock;
|
||||
use App\Domain\Cms\ValueObjects\ContentBlocks;
|
||||
use App\Domain\Cms\ValueObjects\ContentId;
|
||||
use App\Domain\Cms\ValueObjects\ContentSlug;
|
||||
use App\Domain\Cms\ValueObjects\ContentTypeId;
|
||||
use App\Domain\Cms\ValueObjects\Locale;
|
||||
use App\Framework\Core\ValueObjects\Timestamp;
|
||||
use App\Framework\DateTime\Clock;
|
||||
|
||||
final class CmsTestHelpers
|
||||
{
|
||||
public static function createContent(
|
||||
Clock $clock,
|
||||
?ContentId $id = null,
|
||||
?ContentTypeId $contentTypeId = null,
|
||||
?ContentSlug $slug = null,
|
||||
?string $title = null,
|
||||
?ContentBlocks $blocks = null,
|
||||
?ContentStatus $status = null,
|
||||
?Locale $defaultLocale = null
|
||||
): Content {
|
||||
return new Content(
|
||||
id: $id ?? ContentId::generate($clock),
|
||||
contentTypeId: $contentTypeId ?? ContentTypeId::fromString('page'),
|
||||
slug: $slug ?? ContentSlug::fromString('test-page'),
|
||||
title: $title ?? 'Test Page',
|
||||
blocks: $blocks ?? self::createSimpleBlocks(),
|
||||
status: $status ?? ContentStatus::DRAFT,
|
||||
authorId: null,
|
||||
publishedAt: null,
|
||||
metaData: null,
|
||||
defaultLocale: $defaultLocale ?? Locale::english(),
|
||||
createdAt: Timestamp::now(),
|
||||
updatedAt: Timestamp::now()
|
||||
);
|
||||
}
|
||||
|
||||
public static function createContentType(
|
||||
?ContentTypeId $id = null,
|
||||
?string $name = null,
|
||||
?string $slug = null,
|
||||
bool $isSystem = false
|
||||
): ContentType {
|
||||
return new ContentType(
|
||||
id: $id ?? ContentTypeId::fromString('page'),
|
||||
name: $name ?? 'Page',
|
||||
slug: $slug ?? 'page',
|
||||
description: 'A test page content type',
|
||||
isSystem: $isSystem,
|
||||
createdAt: Timestamp::now(),
|
||||
updatedAt: Timestamp::now()
|
||||
);
|
||||
}
|
||||
|
||||
public static function createSimpleBlocks(): ContentBlocks
|
||||
{
|
||||
return ContentBlocks::fromArray([
|
||||
[
|
||||
'id' => 'hero-1',
|
||||
'type' => 'hero',
|
||||
'data' => ['title' => 'Hero Title'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function createHeroBlock(
|
||||
?BlockId $blockId = null,
|
||||
?string $title = null
|
||||
): ContentBlock {
|
||||
return ContentBlock::create(
|
||||
type: BlockType::hero(),
|
||||
blockId: $blockId ?? BlockId::fromString('hero-1'),
|
||||
data: BlockData::fromArray(['title' => $title ?? 'Hero Title'])
|
||||
);
|
||||
}
|
||||
|
||||
public static function createTextBlock(
|
||||
?BlockId $blockId = null,
|
||||
?string $content = null
|
||||
): ContentBlock {
|
||||
return ContentBlock::create(
|
||||
type: BlockType::text(),
|
||||
blockId: $blockId ?? BlockId::fromString('text-1'),
|
||||
data: BlockData::fromArray(['content' => $content ?? 'Text content'])
|
||||
);
|
||||
}
|
||||
|
||||
public static function createImageBlock(
|
||||
?BlockId $blockId = null,
|
||||
?string $imageId = null
|
||||
): ContentBlock {
|
||||
return ContentBlock::create(
|
||||
type: BlockType::image(),
|
||||
blockId: $blockId ?? BlockId::fromString('image-1'),
|
||||
data: BlockData::fromArray(['imageId' => $imageId ?? 'img-123'])
|
||||
);
|
||||
}
|
||||
|
||||
public static function createContentTranslation(
|
||||
ContentId $contentId,
|
||||
?Locale $locale = null,
|
||||
?string $title = null,
|
||||
?ContentBlocks $blocks = null
|
||||
): \App\Domain\Cms\Entities\ContentTranslation {
|
||||
return new \App\Domain\Cms\Entities\ContentTranslation(
|
||||
contentId: $contentId,
|
||||
locale: $locale ?? Locale::german(),
|
||||
title: $title ?? 'Deutscher Titel',
|
||||
blocks: $blocks ?? self::createSimpleBlocks(),
|
||||
createdAt: Timestamp::now(),
|
||||
updatedAt: Timestamp::now()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user