- 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)
97 lines
3.2 KiB
PHP
97 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Domain\Cms\Rendering\TextBlockRenderer;
|
|
use App\Domain\Cms\ValueObjects\BlockData;
|
|
use App\Domain\Cms\ValueObjects\BlockId;
|
|
use App\Domain\Cms\ValueObjects\BlockSettings;
|
|
use App\Domain\Cms\ValueObjects\BlockType;
|
|
use App\Domain\Cms\ValueObjects\ContentBlock;
|
|
|
|
describe('TextBlockRenderer', function () {
|
|
it('renders text block with content', function () {
|
|
$renderer = new TextBlockRenderer();
|
|
$block = ContentBlock::create(
|
|
type: BlockType::text(),
|
|
blockId: BlockId::fromString('text-1'),
|
|
data: BlockData::fromArray(['content' => 'Text content'])
|
|
);
|
|
|
|
$result = $renderer->render($block);
|
|
|
|
expect($result)->toHaveKeys(['component', 'data']);
|
|
expect($result['component'])->toBe('cms/text');
|
|
expect($result['data']['content'])->toBe('Text content');
|
|
});
|
|
|
|
it('renders text block with alignment', function () {
|
|
$renderer = new TextBlockRenderer();
|
|
$block = ContentBlock::create(
|
|
type: BlockType::text(),
|
|
blockId: BlockId::fromString('text-1'),
|
|
data: BlockData::fromArray([
|
|
'content' => 'Text content',
|
|
'alignment' => 'center',
|
|
])
|
|
);
|
|
|
|
$result = $renderer->render($block);
|
|
|
|
expect($result['data']['content'])->toBe('Text content');
|
|
expect($result['data']['alignment'])->toBe('center');
|
|
});
|
|
|
|
it('renders text block with maxWidth setting', function () {
|
|
$renderer = new TextBlockRenderer();
|
|
$block = ContentBlock::create(
|
|
type: BlockType::text(),
|
|
blockId: BlockId::fromString('text-1'),
|
|
data: BlockData::fromArray(['content' => 'Text content']),
|
|
settings: BlockSettings::fromArray(['maxWidth' => 800])
|
|
);
|
|
|
|
$result = $renderer->render($block);
|
|
|
|
expect($result['data']['maxWidth'])->toBe(800);
|
|
});
|
|
|
|
it('handles snake_case maxWidth setting', function () {
|
|
$renderer = new TextBlockRenderer();
|
|
$block = ContentBlock::create(
|
|
type: BlockType::text(),
|
|
blockId: BlockId::fromString('text-1'),
|
|
data: BlockData::fromArray(['content' => 'Text content']),
|
|
settings: BlockSettings::fromArray(['max_width' => 800])
|
|
);
|
|
|
|
$result = $renderer->render($block);
|
|
|
|
expect($result['data']['maxWidth'])->toBe(800);
|
|
});
|
|
|
|
it('provides default values for missing fields', function () {
|
|
$renderer = new TextBlockRenderer();
|
|
$block = ContentBlock::create(
|
|
type: BlockType::text(),
|
|
blockId: BlockId::fromString('text-1'),
|
|
data: BlockData::fromArray(['content' => 'Text content'])
|
|
);
|
|
|
|
$result = $renderer->render($block);
|
|
|
|
expect($result['data']['content'])->toBe('Text content');
|
|
expect($result['data']['alignment'])->toBe('left');
|
|
expect($result['data']['maxWidth'])->toBeNull();
|
|
});
|
|
|
|
it('supports text block type', function () {
|
|
$renderer = new TextBlockRenderer();
|
|
|
|
expect($renderer->supports('text'))->toBeTrue();
|
|
expect($renderer->supports('hero'))->toBeFalse();
|
|
expect($renderer->supports('image'))->toBeFalse();
|
|
});
|
|
});
|
|
|