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:
138
tests/Unit/Domain/Asset/Storage/ObjectStorageAdapterTest.php
Normal file
138
tests/Unit/Domain/Asset/Storage/ObjectStorageAdapterTest.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Domain\Asset\Entities\Asset;
|
||||
use App\Domain\Asset\Storage\ObjectStorageAdapter;
|
||||
use App\Domain\Asset\ValueObjects\AssetId;
|
||||
use App\Domain\Asset\ValueObjects\AssetMetadata;
|
||||
use App\Framework\Core\ValueObjects\FileSize;
|
||||
use App\Framework\Core\ValueObjects\Hash;
|
||||
use App\Framework\Core\ValueObjects\HashAlgorithm;
|
||||
use App\Framework\Core\ValueObjects\Timestamp;
|
||||
use App\Framework\DateTime\SystemClock;
|
||||
use App\Framework\Http\MimeType;
|
||||
use App\Framework\Storage\ObjectStorage;
|
||||
use App\Framework\Storage\ValueObjects\BucketName;
|
||||
use App\Framework\Storage\ValueObjects\ObjectKey;
|
||||
|
||||
describe('ObjectStorageAdapter', function () {
|
||||
beforeEach(function () {
|
||||
$this->clock = new SystemClock();
|
||||
$this->objectStorage = Mockery::mock(ObjectStorage::class);
|
||||
$this->adapter = new ObjectStorageAdapter($this->objectStorage);
|
||||
});
|
||||
|
||||
it('puts asset content to storage', function () {
|
||||
$asset = AssetTestHelpers::createAsset($this->clock);
|
||||
$content = 'test-content';
|
||||
|
||||
$this->objectStorage->shouldReceive('put')
|
||||
->once()
|
||||
->with($asset->bucket->toString(), $asset->key->toString(), $content)
|
||||
->andReturnNull();
|
||||
|
||||
$this->adapter->put($asset, $content);
|
||||
});
|
||||
|
||||
it('gets asset content from storage', function () {
|
||||
$asset = AssetTestHelpers::createAsset($this->clock);
|
||||
$content = 'test-content';
|
||||
|
||||
$this->objectStorage->shouldReceive('get')
|
||||
->once()
|
||||
->with($asset->bucket->toString(), $asset->key->toString())
|
||||
->andReturn($content);
|
||||
|
||||
$result = $this->adapter->get($asset);
|
||||
|
||||
expect($result)->toBe($content);
|
||||
});
|
||||
|
||||
it('checks if asset exists in storage', function () {
|
||||
$asset = AssetTestHelpers::createAsset($this->clock);
|
||||
|
||||
$this->objectStorage->shouldReceive('exists')
|
||||
->once()
|
||||
->with($asset->bucket->toString(), $asset->key->toString())
|
||||
->andReturn(true);
|
||||
|
||||
expect($this->adapter->exists($asset))->toBeTrue();
|
||||
});
|
||||
|
||||
it('deletes asset from storage', function () {
|
||||
$asset = AssetTestHelpers::createAsset($this->clock);
|
||||
|
||||
$this->objectStorage->shouldReceive('delete')
|
||||
->once()
|
||||
->with($asset->bucket->toString(), $asset->key->toString())
|
||||
->andReturnNull();
|
||||
|
||||
$this->adapter->delete($asset);
|
||||
});
|
||||
|
||||
it('gets URL from object storage', function () {
|
||||
$asset = AssetTestHelpers::createAsset($this->clock);
|
||||
$url = 'https://storage.example.com/media/orig/test.jpg';
|
||||
|
||||
$this->objectStorage->shouldReceive('url')
|
||||
->once()
|
||||
->with($asset->bucket->toString(), $asset->key->toString())
|
||||
->andReturn($url);
|
||||
|
||||
$result = $this->adapter->getUrl($asset);
|
||||
|
||||
expect($result)->toBe($url);
|
||||
});
|
||||
|
||||
it('falls back to CDN URL when object storage returns null', function () {
|
||||
$asset = AssetTestHelpers::createAsset($this->clock);
|
||||
$cdnBaseUrl = 'https://cdn.example.com';
|
||||
$adapter = new ObjectStorageAdapter($this->objectStorage, $cdnBaseUrl);
|
||||
|
||||
$this->objectStorage->shouldReceive('url')
|
||||
->once()
|
||||
->with($asset->bucket->toString(), $asset->key->toString())
|
||||
->andReturn(null);
|
||||
|
||||
$result = $adapter->getUrl($asset);
|
||||
|
||||
expect($result)->toContain($cdnBaseUrl);
|
||||
expect($result)->toContain($asset->bucket->toString());
|
||||
expect($result)->toContain($asset->key->toString());
|
||||
});
|
||||
|
||||
it('falls back to storage path when no CDN configured', function () {
|
||||
$asset = AssetTestHelpers::createAsset($this->clock);
|
||||
|
||||
$this->objectStorage->shouldReceive('url')
|
||||
->once()
|
||||
->with($asset->bucket->toString(), $asset->key->toString())
|
||||
->andReturn(null);
|
||||
|
||||
$result = $this->adapter->getUrl($asset);
|
||||
|
||||
expect($result)->toContain($asset->bucket->toString());
|
||||
expect($result)->toContain($asset->key->toString());
|
||||
});
|
||||
|
||||
it('gets signed URL from object storage', function () {
|
||||
$asset = AssetTestHelpers::createAsset($this->clock);
|
||||
$signedUrl = 'https://storage.example.com/media/orig/test.jpg?signature=abc123';
|
||||
$expiresIn = 3600;
|
||||
|
||||
$this->objectStorage->shouldReceive('temporaryUrl')
|
||||
->once()
|
||||
->with(
|
||||
$asset->bucket->toString(),
|
||||
$asset->key->toString(),
|
||||
Mockery::type(\DateInterval::class)
|
||||
)
|
||||
->andReturn($signedUrl);
|
||||
|
||||
$result = $this->adapter->getSignedUrl($asset, $expiresIn);
|
||||
|
||||
expect($result)->toBe($signedUrl);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user