Some checks failed
Deploy Application / deploy (push) Has been cancelled
110 lines
3.3 KiB
PHP
110 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Application\Admin\Cms\Services\ContentPreviewService;
|
|
use App\Domain\Cms\Services\ContentRenderer;
|
|
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\Framework\DateTime\Clock;
|
|
|
|
describe('ContentPreviewService', function () {
|
|
beforeEach(function () {
|
|
$this->clock = new Clock();
|
|
|
|
// Create a mock ContentRenderer
|
|
$this->contentRenderer = Mockery::mock(ContentRenderer::class);
|
|
$this->service = new ContentPreviewService(
|
|
$this->contentRenderer,
|
|
$this->clock
|
|
);
|
|
});
|
|
|
|
it('renders preview HTML from ContentBlocks', function () {
|
|
$blocks = ContentBlocks::fromArray([
|
|
[
|
|
'id' => 'block-1',
|
|
'type' => 'text',
|
|
'data' => ['content' => '<p>Test content</p>'],
|
|
],
|
|
]);
|
|
|
|
$this->contentRenderer
|
|
->shouldReceive('render')
|
|
->once()
|
|
->andReturn('<div class="cms-text"><p>Test content</p></div>');
|
|
|
|
$html = $this->service->renderPreview($blocks);
|
|
|
|
expect($html)->toBeString();
|
|
expect($html)->not->toBeEmpty();
|
|
expect($html)->toContain('Test content');
|
|
});
|
|
|
|
it('renders multiple blocks in preview', function () {
|
|
$blocks = ContentBlocks::fromArray([
|
|
[
|
|
'id' => 'block-1',
|
|
'type' => 'hero',
|
|
'data' => ['title' => 'Hero Title'],
|
|
],
|
|
[
|
|
'id' => 'block-2',
|
|
'type' => 'text',
|
|
'data' => ['content' => '<p>Text content</p>'],
|
|
],
|
|
]);
|
|
|
|
$this->contentRenderer
|
|
->shouldReceive('render')
|
|
->once()
|
|
->andReturn('<div class="cms-hero">Hero Title</div><div class="cms-text"><p>Text content</p></div>');
|
|
|
|
$html = $this->service->renderPreview($blocks);
|
|
|
|
expect($html)->toBeString();
|
|
expect($html)->toContain('Hero Title');
|
|
expect($html)->toContain('Text content');
|
|
});
|
|
|
|
it('renders empty blocks as empty string', function () {
|
|
$blocks = ContentBlocks::fromArray([]);
|
|
|
|
$this->contentRenderer
|
|
->shouldReceive('render')
|
|
->once()
|
|
->andReturn('');
|
|
|
|
$html = $this->service->renderPreview($blocks);
|
|
|
|
expect($html)->toBe('');
|
|
});
|
|
|
|
it('does not use caching for preview', function () {
|
|
$blocks = ContentBlocks::fromArray([
|
|
[
|
|
'id' => 'block-1',
|
|
'type' => 'text',
|
|
'data' => ['content' => '<p>Test</p>'],
|
|
],
|
|
]);
|
|
|
|
$this->contentRenderer
|
|
->shouldReceive('render')
|
|
->once()
|
|
->andReturn('<div>Test</div>');
|
|
|
|
// Call twice - should render both times (no caching)
|
|
$html1 = $this->service->renderPreview($blocks);
|
|
$html2 = $this->service->renderPreview($blocks);
|
|
|
|
expect($html1)->toBe($html2);
|
|
// Verify render was called twice (no caching)
|
|
$this->contentRenderer->shouldHaveReceived('render')->twice();
|
|
});
|
|
});
|
|
|