Files
michaelschiemer/tests/Unit/Domain/Cms/Rendering/HeroBlockRendererTest.php
Michael Schiemer 2d53270056 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)
2025-11-10 02:12:28 +01:00

104 lines
3.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Domain\Cms\Rendering\HeroBlockRenderer;
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('HeroBlockRenderer', function () {
it('renders hero block with title', function () {
$renderer = new HeroBlockRenderer();
$block = ContentBlock::create(
type: BlockType::hero(),
blockId: BlockId::fromString('hero-1'),
data: BlockData::fromArray(['title' => 'Hero Title'])
);
$result = $renderer->render($block);
expect($result)->toHaveKeys(['component', 'data']);
expect($result['component'])->toBe('cms/hero');
expect($result['data']['title'])->toBe('Hero Title');
});
it('renders hero block with all fields', function () {
$renderer = new HeroBlockRenderer();
$block = ContentBlock::create(
type: BlockType::hero(),
blockId: BlockId::fromString('hero-1'),
data: BlockData::fromArray([
'title' => 'Hero Title',
'subtitle' => 'Hero Subtitle',
'backgroundImage' => 'img-123',
'ctaText' => 'Click Me',
'ctaLink' => '/signup',
]),
settings: BlockSettings::fromArray([
'fullWidth' => true,
'padding' => 'large',
])
);
$result = $renderer->render($block);
expect($result['data']['title'])->toBe('Hero Title');
expect($result['data']['subtitle'])->toBe('Hero Subtitle');
expect($result['data']['backgroundImage'])->toBe('img-123');
expect($result['data']['ctaText'])->toBe('Click Me');
expect($result['data']['ctaLink'])->toBe('/signup');
expect($result['data']['fullWidth'])->toBeTrue();
expect($result['data']['padding'])->toBe('large');
});
it('handles snake_case field names', function () {
$renderer = new HeroBlockRenderer();
$block = ContentBlock::create(
type: BlockType::hero(),
blockId: BlockId::fromString('hero-1'),
data: BlockData::fromArray([
'title' => 'Hero Title',
'background_image' => 'img-123',
'cta_text' => 'Click Me',
'cta_link' => '/signup',
]),
settings: BlockSettings::fromArray(['full_width' => true])
);
$result = $renderer->render($block);
expect($result['data']['backgroundImage'])->toBe('img-123');
expect($result['data']['ctaText'])->toBe('Click Me');
expect($result['data']['ctaLink'])->toBe('/signup');
expect($result['data']['fullWidth'])->toBeTrue();
});
it('provides default values for missing fields', function () {
$renderer = new HeroBlockRenderer();
$block = ContentBlock::create(
type: BlockType::hero(),
blockId: BlockId::fromString('hero-1'),
data: BlockData::fromArray(['title' => 'Hero Title'])
);
$result = $renderer->render($block);
expect($result['data']['title'])->toBe('Hero Title');
expect($result['data']['subtitle'])->toBeNull();
expect($result['data']['fullWidth'])->toBeFalse();
expect($result['data']['padding'])->toBe('medium');
});
it('supports hero block type', function () {
$renderer = new HeroBlockRenderer();
expect($renderer->supports('hero'))->toBeTrue();
expect($renderer->supports('text'))->toBeFalse();
expect($renderer->supports('image'))->toBeFalse();
});
});