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:
69
tests/Unit/Domain/Cms/ValueObjects/BlockIdTest.php
Normal file
69
tests/Unit/Domain/Cms/ValueObjects/BlockIdTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Domain\Cms\ValueObjects\BlockId;
|
||||
|
||||
describe('BlockId', function () {
|
||||
it('can be created from valid string', function () {
|
||||
$blockId = BlockId::fromString('hero-1');
|
||||
|
||||
expect($blockId->toString())->toBe('hero-1');
|
||||
expect((string) $blockId)->toBe('hero-1');
|
||||
});
|
||||
|
||||
it('accepts lowercase letters, numbers, hyphens, and underscores', function () {
|
||||
$validIds = ['block-1', 'text_block', 'image123', 'my-block-id'];
|
||||
|
||||
foreach ($validIds as $id) {
|
||||
$blockId = BlockId::fromString($id);
|
||||
expect($blockId->toString())->toBe($id);
|
||||
}
|
||||
});
|
||||
|
||||
it('can generate unique block IDs', function () {
|
||||
$blockId1 = BlockId::generate('hero');
|
||||
$blockId2 = BlockId::generate('hero');
|
||||
|
||||
expect($blockId1->toString())->toStartWith('hero_');
|
||||
expect($blockId2->toString())->toStartWith('hero_');
|
||||
expect($blockId1->toString())->not->toBe($blockId2->toString());
|
||||
});
|
||||
|
||||
it('generates block IDs with custom prefix', function () {
|
||||
$blockId = BlockId::generate('custom');
|
||||
|
||||
expect($blockId->toString())->toStartWith('custom_');
|
||||
});
|
||||
|
||||
it('throws exception for empty string', function () {
|
||||
expect(fn () => BlockId::fromString(''))
|
||||
->toThrow(InvalidArgumentException::class, 'Block ID cannot be empty');
|
||||
});
|
||||
|
||||
it('throws exception for uppercase letters', function () {
|
||||
expect(fn () => BlockId::fromString('Block-1'))
|
||||
->toThrow(InvalidArgumentException::class, 'Block ID must contain only lowercase letters, numbers, hyphens, and underscores');
|
||||
});
|
||||
|
||||
it('throws exception for special characters', function () {
|
||||
expect(fn () => BlockId::fromString('block@1'))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
});
|
||||
|
||||
it('throws exception for block ID exceeding 100 characters', function () {
|
||||
$longId = str_repeat('a', 101);
|
||||
expect(fn () => BlockId::fromString($longId))
|
||||
->toThrow(InvalidArgumentException::class, 'Block ID cannot exceed 100 characters');
|
||||
});
|
||||
|
||||
it('can compare two BlockIds for equality', function () {
|
||||
$id1 = BlockId::fromString('block-1');
|
||||
$id2 = BlockId::fromString('block-1');
|
||||
$id3 = BlockId::fromString('block-2');
|
||||
|
||||
expect($id1->equals($id2))->toBeTrue();
|
||||
expect($id1->equals($id3))->toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user