- 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)
99 lines
3.3 KiB
PHP
99 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Domain\Asset\Entities\AssetVariant;
|
|
use App\Domain\Asset\Repositories\DatabaseAssetVariantRepository;
|
|
use App\Domain\Asset\ValueObjects\AssetId;
|
|
use App\Domain\Asset\ValueObjects\VariantName;
|
|
use App\Framework\Database\ConnectionInterface;
|
|
use App\Framework\Database\ResultInterface;
|
|
|
|
describe('DatabaseAssetVariantRepository', function () {
|
|
beforeEach(function () {
|
|
$this->clock = new \App\Framework\DateTime\SystemClock();
|
|
$this->connection = Mockery::mock(ConnectionInterface::class);
|
|
$this->repository = new DatabaseAssetVariantRepository($this->connection);
|
|
});
|
|
|
|
it('saves variant to database', function () {
|
|
$assetId = AssetId::generate($this->clock);
|
|
$variant = AssetTestHelpers::createAssetVariant($assetId);
|
|
|
|
$this->connection->shouldReceive('execute')
|
|
->once()
|
|
->with(Mockery::type(\App\Framework\Database\ValueObjects\SqlQuery::class))
|
|
->andReturn(1);
|
|
|
|
$this->repository->save($variant);
|
|
});
|
|
|
|
it('finds variants by asset id', function () {
|
|
$assetId = AssetId::generate($this->clock);
|
|
$row = [
|
|
'asset_id' => $assetId->toString(),
|
|
'variant' => '1200w.webp',
|
|
'bucket' => 'variants',
|
|
'key' => 'variants/2025/01/15/test/1200w.webp',
|
|
'mime' => 'image/webp',
|
|
'bytes' => 512,
|
|
'meta' => json_encode(['width' => 1200, 'height' => 675]),
|
|
];
|
|
|
|
$result = Mockery::mock(ResultInterface::class);
|
|
$result->shouldReceive('fetchAll')
|
|
->once()
|
|
->andReturn([$row]);
|
|
|
|
$this->connection->shouldReceive('query')
|
|
->once()
|
|
->andReturn($result);
|
|
|
|
$found = $this->repository->findByAsset($assetId);
|
|
|
|
expect($found)->toBeArray();
|
|
expect($found)->toHaveCount(1);
|
|
expect($found[0])->toBeInstanceOf(AssetVariant::class);
|
|
});
|
|
|
|
it('finds specific variant by asset id and variant name', function () {
|
|
$assetId = AssetId::generate($this->clock);
|
|
$variantName = VariantName::fromString('1200w.webp');
|
|
$row = [
|
|
'asset_id' => $assetId->toString(),
|
|
'variant' => '1200w.webp',
|
|
'bucket' => 'variants',
|
|
'key' => 'variants/2025/01/15/test/1200w.webp',
|
|
'mime' => 'image/webp',
|
|
'bytes' => 512,
|
|
'meta' => json_encode(['width' => 1200, 'height' => 675]),
|
|
];
|
|
|
|
$result = Mockery::mock(ResultInterface::class);
|
|
$result->shouldReceive('fetch')
|
|
->once()
|
|
->andReturn($row);
|
|
|
|
$this->connection->shouldReceive('query')
|
|
->once()
|
|
->andReturn($result);
|
|
|
|
$found = $this->repository->findByAssetAndVariant($assetId, $variantName);
|
|
|
|
expect($found)->toBeInstanceOf(AssetVariant::class);
|
|
expect($found->variant->equals($variantName))->toBeTrue();
|
|
});
|
|
|
|
it('deletes all variants for asset', function () {
|
|
$assetId = AssetId::generate($this->clock);
|
|
|
|
$this->connection->shouldReceive('execute')
|
|
->once()
|
|
->with(Mockery::type(\App\Framework\Database\ValueObjects\SqlQuery::class))
|
|
->andReturn(1);
|
|
|
|
$this->repository->deleteByAsset($assetId);
|
|
});
|
|
});
|
|
|