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:
53
tests/Unit/Domain/Cms/ValueObjects/ContentSlugTest.php
Normal file
53
tests/Unit/Domain/Cms/ValueObjects/ContentSlugTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Domain\Cms\ValueObjects\ContentSlug;
|
||||
|
||||
describe('ContentSlug', function () {
|
||||
it('can be created from valid string', function () {
|
||||
$slug = ContentSlug::fromString('my-awesome-page');
|
||||
|
||||
expect($slug->toString())->toBe('my-awesome-page');
|
||||
expect((string) $slug)->toBe('my-awesome-page');
|
||||
});
|
||||
|
||||
it('accepts lowercase letters, numbers, hyphens, and underscores', function () {
|
||||
$validSlugs = ['page', 'blog-post', 'product_123', 'my-content-slug'];
|
||||
|
||||
foreach ($validSlugs as $slugStr) {
|
||||
$slug = ContentSlug::fromString($slugStr);
|
||||
expect($slug->toString())->toBe($slugStr);
|
||||
}
|
||||
});
|
||||
|
||||
it('throws exception for empty string', function () {
|
||||
expect(fn () => ContentSlug::fromString(''))
|
||||
->toThrow(InvalidArgumentException::class, 'Content slug cannot be empty');
|
||||
});
|
||||
|
||||
it('throws exception for uppercase letters', function () {
|
||||
expect(fn () => ContentSlug::fromString('My-Page'))
|
||||
->toThrow(InvalidArgumentException::class, 'Content slug must contain only lowercase letters, numbers, hyphens, and underscores');
|
||||
});
|
||||
|
||||
it('throws exception for spaces', function () {
|
||||
expect(fn () => ContentSlug::fromString('my page'))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
});
|
||||
|
||||
it('throws exception for special characters', function () {
|
||||
expect(fn () => ContentSlug::fromString('my@page'))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
});
|
||||
|
||||
it('can compare two ContentSlugs for equality', function () {
|
||||
$slug1 = ContentSlug::fromString('my-page');
|
||||
$slug2 = ContentSlug::fromString('my-page');
|
||||
$slug3 = ContentSlug::fromString('other-page');
|
||||
|
||||
expect($slug1->equals($slug2))->toBeTrue();
|
||||
expect($slug1->equals($slug3))->toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user