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:
86
tests/Unit/Domain/Asset/Services/MetadataExtractorTest.php
Normal file
86
tests/Unit/Domain/Asset/Services/MetadataExtractorTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Domain\Asset\Services\MetadataExtractor;
|
||||
|
||||
describe('MetadataExtractor', function () {
|
||||
beforeEach(function () {
|
||||
$this->extractor = new MetadataExtractor();
|
||||
});
|
||||
|
||||
it('extracts image dimensions from valid image', function () {
|
||||
// Create a minimal valid JPEG (1x1 pixel)
|
||||
$imageContent = "\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xFF\xD9";
|
||||
|
||||
// Create a real 1x1 pixel image using GD
|
||||
$img = imagecreatetruecolor(100, 200);
|
||||
ob_start();
|
||||
imagejpeg($img);
|
||||
$imageContent = ob_get_clean();
|
||||
imagedestroy($img);
|
||||
|
||||
$meta = $this->extractor->extractImageMetadata($imageContent);
|
||||
|
||||
expect($meta->getWidth())->toBe(100);
|
||||
expect($meta->getHeight())->toBe(200);
|
||||
});
|
||||
|
||||
it('returns empty metadata for invalid image content', function () {
|
||||
$meta = $this->extractor->extractImageMetadata('invalid-image-content');
|
||||
|
||||
expect($meta->getWidth())->toBeNull();
|
||||
expect($meta->getHeight())->toBeNull();
|
||||
});
|
||||
|
||||
it('extracts EXIF data when available', function () {
|
||||
// Create a minimal JPEG
|
||||
$img = imagecreatetruecolor(100, 100);
|
||||
ob_start();
|
||||
imagejpeg($img);
|
||||
$imageContent = ob_get_clean();
|
||||
imagedestroy($img);
|
||||
|
||||
$meta = $this->extractor->extractImageMetadata($imageContent);
|
||||
|
||||
// EXIF might not be available in test environment, but method should not throw
|
||||
expect($meta)->toBeInstanceOf(\App\Domain\Asset\ValueObjects\AssetMetadata::class);
|
||||
});
|
||||
|
||||
it('returns empty metadata for video content', function () {
|
||||
$meta = $this->extractor->extractVideoMetadata('video-content');
|
||||
|
||||
expect($meta->toArray())->toBe([]);
|
||||
});
|
||||
|
||||
it('returns empty metadata for audio content', function () {
|
||||
$meta = $this->extractor->extractAudioMetadata('audio-content');
|
||||
|
||||
expect($meta->toArray())->toBe([]);
|
||||
});
|
||||
|
||||
it('returns null for blurhash generation', function () {
|
||||
$img = imagecreatetruecolor(100, 100);
|
||||
ob_start();
|
||||
imagejpeg($img);
|
||||
$imageContent = ob_get_clean();
|
||||
imagedestroy($img);
|
||||
|
||||
$blurhash = $this->extractor->generateBlurhash($imageContent);
|
||||
|
||||
expect($blurhash)->toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for dominant color extraction', function () {
|
||||
$img = imagecreatetruecolor(100, 100);
|
||||
ob_start();
|
||||
imagejpeg($img);
|
||||
$imageContent = ob_get_clean();
|
||||
imagedestroy($img);
|
||||
|
||||
$color = $this->extractor->extractDominantColor($imageContent);
|
||||
|
||||
expect($color)->toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user