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:
89
tests/Unit/Domain/Cms/Services/SlugGeneratorTest.php
Normal file
89
tests/Unit/Domain/Cms/Services/SlugGeneratorTest.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Domain\Cms\Repositories\ContentRepository;
|
||||
use App\Domain\Cms\Services\SlugGenerator;
|
||||
use App\Domain\Cms\ValueObjects\ContentSlug;
|
||||
|
||||
describe('SlugGenerator', function () {
|
||||
beforeEach(function () {
|
||||
$this->repository = Mockery::mock(ContentRepository::class);
|
||||
$this->slugGenerator = new SlugGenerator($this->repository);
|
||||
});
|
||||
|
||||
it('generates slug from title', function () {
|
||||
$slug = $this->slugGenerator->generateFromTitle('My Awesome Page');
|
||||
|
||||
expect($slug)->toBeInstanceOf(ContentSlug::class);
|
||||
expect($slug->toString())->toBe('my-awesome-page');
|
||||
});
|
||||
|
||||
it('handles special characters in title', function () {
|
||||
$slug = $this->slugGenerator->generateFromTitle('Hello & World!');
|
||||
|
||||
expect($slug->toString())->toBe('hello-world');
|
||||
});
|
||||
|
||||
it('handles empty title', function () {
|
||||
$slug = $this->slugGenerator->generateFromTitle('');
|
||||
|
||||
expect($slug->toString())->toStartWith('content-');
|
||||
});
|
||||
|
||||
it('truncates long titles', function () {
|
||||
$longTitle = str_repeat('a', 300);
|
||||
$slug = $this->slugGenerator->generateFromTitle($longTitle);
|
||||
|
||||
expect(strlen($slug->toString()))->toBeLessThanOrEqual(255);
|
||||
});
|
||||
|
||||
it('generates unique slug when base slug exists', function () {
|
||||
$this->repository->shouldReceive('existsSlug')
|
||||
->once()
|
||||
->with(Mockery::on(fn ($slug) => $slug->toString() === 'my-page'))
|
||||
->andReturn(true);
|
||||
|
||||
$this->repository->shouldReceive('existsSlug')
|
||||
->once()
|
||||
->with(Mockery::on(fn ($slug) => $slug->toString() === 'my-page-1'))
|
||||
->andReturn(false);
|
||||
|
||||
$slug = $this->slugGenerator->generateUniqueFromTitle('My Page');
|
||||
|
||||
expect($slug->toString())->toBe('my-page-1');
|
||||
});
|
||||
|
||||
it('generates unique slug with multiple collisions', function () {
|
||||
$this->repository->shouldReceive('existsSlug')
|
||||
->once()
|
||||
->with(Mockery::on(fn ($slug) => $slug->toString() === 'my-page'))
|
||||
->andReturn(true);
|
||||
|
||||
$this->repository->shouldReceive('existsSlug')
|
||||
->once()
|
||||
->with(Mockery::on(fn ($slug) => $slug->toString() === 'my-page-1'))
|
||||
->andReturn(true);
|
||||
|
||||
$this->repository->shouldReceive('existsSlug')
|
||||
->once()
|
||||
->with(Mockery::on(fn ($slug) => $slug->toString() === 'my-page-2'))
|
||||
->andReturn(false);
|
||||
|
||||
$slug = $this->slugGenerator->generateUniqueFromTitle('My Page');
|
||||
|
||||
expect($slug->toString())->toBe('my-page-2');
|
||||
});
|
||||
|
||||
it('returns base slug when it does not exist', function () {
|
||||
$this->repository->shouldReceive('existsSlug')
|
||||
->once()
|
||||
->with(Mockery::on(fn ($slug) => $slug->toString() === 'my-page'))
|
||||
->andReturn(false);
|
||||
|
||||
$slug = $this->slugGenerator->generateUniqueFromTitle('My Page');
|
||||
|
||||
expect($slug->toString())->toBe('my-page');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user