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)
This commit is contained in:
2025-11-10 02:12:28 +01:00
parent 74d50a29cc
commit 2d53270056
53 changed files with 5699 additions and 15 deletions

View File

@@ -0,0 +1,102 @@
<?php
declare(strict_types=1);
use App\Domain\Cms\ValueObjects\BlockSettings;
describe('BlockSettings', function () {
it('can be created from array', function () {
$settings = BlockSettings::fromArray(['fullWidth' => true, 'padding' => 20]);
expect($settings->toArray())->toBe(['fullWidth' => true, 'padding' => 20]);
});
it('can be created as empty', function () {
$settings = BlockSettings::empty();
expect($settings->toArray())->toBe([]);
expect($settings->has('key'))->toBeFalse();
});
it('can get values by key', function () {
$settings = BlockSettings::fromArray(['fullWidth' => true, 'padding' => 20]);
expect($settings->get('fullWidth'))->toBeTrue();
expect($settings->get('padding'))->toBe(20);
expect($settings->get('missing'))->toBeNull();
expect($settings->get('missing', 'default'))->toBe('default');
});
it('can check if key exists', function () {
$settings = BlockSettings::fromArray(['fullWidth' => true]);
expect($settings->has('fullWidth'))->toBeTrue();
expect($settings->has('missing'))->toBeFalse();
});
it('can add new key-value pair', function () {
$settings = BlockSettings::fromArray(['fullWidth' => true]);
$newSettings = $settings->with('padding', 20);
expect($newSettings->get('fullWidth'))->toBeTrue();
expect($newSettings->get('padding'))->toBe(20);
expect($settings->has('padding'))->toBeFalse(); // Original unchanged
});
it('can remove key', function () {
$settings = BlockSettings::fromArray(['fullWidth' => true, 'padding' => 20]);
$newSettings = $settings->without('fullWidth');
expect($newSettings->has('fullWidth'))->toBeFalse();
expect($newSettings->has('padding'))->toBeTrue();
expect($settings->has('fullWidth'))->toBeTrue(); // Original unchanged
});
it('accepts scalar values', function () {
$settings = BlockSettings::fromArray([
'string' => 'test',
'int' => 123,
'float' => 45.67,
'bool' => true,
'null' => null,
]);
expect($settings->get('string'))->toBe('test');
expect($settings->get('int'))->toBe(123);
expect($settings->get('float'))->toBe(45.67);
expect($settings->get('bool'))->toBeTrue();
expect($settings->get('null'))->toBeNull();
});
it('accepts arrays of scalar values', function () {
$settings = BlockSettings::fromArray([
'classes' => ['container', 'full-width'],
'numbers' => [1, 2, 3],
]);
expect($settings->get('classes'))->toBe(['container', 'full-width']);
expect($settings->get('numbers'))->toBe([1, 2, 3]);
});
it('accepts nested arrays', function () {
$settings = BlockSettings::fromArray([
'style' => [
'margin' => 10,
'padding' => 20,
],
]);
expect($settings->get('style'))->toBe(['margin' => 10, 'padding' => 20]);
});
it('throws exception for non-string keys', function () {
expect(fn () => BlockSettings::fromArray([0 => 'value']))
->toThrow(InvalidArgumentException::class, 'BlockSettings keys must be strings');
});
it('throws exception for non-serializable values', function () {
expect(fn () => BlockSettings::fromArray(['key' => fopen('php://memory', 'r')]))
->toThrow(InvalidArgumentException::class, 'BlockSettings value for key');
});
});