Files
michaelschiemer/tests/Unit/Domain/Cms/Repositories/DatabaseContentTranslationRepositoryTest.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

98 lines
3.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Domain\Cms\Entities\ContentTranslation;
use App\Domain\Cms\Repositories\DatabaseContentTranslationRepository;
use App\Domain\Cms\ValueObjects\ContentId;
use App\Domain\Cms\ValueObjects\Locale;
use App\Framework\Database\ConnectionInterface;
use App\Framework\Database\ResultInterface;
use Tests\Support\CmsTestHelpers;
describe('DatabaseContentTranslationRepository', function () {
beforeEach(function () {
$this->clock = new \App\Framework\DateTime\SystemClock();
$this->connection = Mockery::mock(ConnectionInterface::class);
$this->repository = new DatabaseContentTranslationRepository($this->connection);
});
it('saves translation to database', function () {
$contentId = ContentId::generate($this->clock);
$translation = CmsTestHelpers::createContentTranslation($contentId);
$this->connection->shouldReceive('execute')
->once()
->with(Mockery::type(\App\Framework\Database\ValueObjects\SqlQuery::class))
->andReturn(1);
$this->repository->save($translation);
});
it('finds translation by content id and locale', function () {
$contentId = ContentId::generate($this->clock);
$locale = Locale::german();
$row = [
'content_id' => $contentId->toString(),
'locale' => 'de',
'title' => 'Deutscher Titel',
'blocks' => json_encode([['id' => 'hero-1', 'type' => 'hero', 'data' => ['title' => 'Hero']]]),
'created_at' => '2025-01-15 10:00:00',
'updated_at' => '2025-01-15 10:00:00',
];
$result = Mockery::mock(ResultInterface::class);
$result->shouldReceive('fetch')
->once()
->andReturn($row);
$this->connection->shouldReceive('query')
->once()
->andReturn($result);
$found = $this->repository->findByContentAndLocale($contentId, $locale);
expect($found)->toBeInstanceOf(ContentTranslation::class);
expect($found->locale->equals($locale))->toBeTrue();
});
it('finds all translations for content', function () {
$contentId = ContentId::generate($this->clock);
$row = [
'content_id' => $contentId->toString(),
'locale' => 'de',
'title' => 'Deutscher Titel',
'blocks' => json_encode([['id' => 'hero-1', 'type' => 'hero', 'data' => ['title' => 'Hero']]]),
'created_at' => '2025-01-15 10:00:00',
'updated_at' => '2025-01-15 10:00:00',
];
$result = Mockery::mock(ResultInterface::class);
$result->shouldReceive('fetchAll')
->once()
->andReturn([$row]);
$this->connection->shouldReceive('query')
->once()
->andReturn($result);
$found = $this->repository->findByContent($contentId);
expect($found)->toBeArray();
expect($found)->toHaveCount(1);
});
it('deletes translation', function () {
$contentId = ContentId::generate($this->clock);
$locale = Locale::german();
$this->connection->shouldReceive('execute')
->once()
->with(Mockery::type(\App\Framework\Database\ValueObjects\SqlQuery::class))
->andReturn(1);
$this->repository->delete($contentId, $locale);
});
});