simedkom/tests/Unit/MediaLibrary/CustomPathGeneratorTest.php
Yoga Pangestu 97cdfd6e0b test: add comprehensive test suite and model factories
- Add HasFactory trait to all model classes for factory support
- Create factory classes for all models (Classification, Company, ContentRecap, Department, IssueManagement, Journalist, Location, MediaMonitoring, MediaMonitoringTheme, PartnerMedia, SubClassification, SubLocation, Theme, User)
- Add unit tests for all models with relationship and attribute validation
- Add unit tests for all enums (Channel, ContentType, IsActive, IssueSentiment, MediaClassification, MediaType, SocialMedia)
- Add feature tests for factory integration and basic application functionality
- Add tests for Filament actions, columns, and media library utilities
- Add tests for model policies (Classification, Theme) and traits (WithComment, WithValue)
- Update phpunit.xml configuration for test environment
- Add test documentation and working tests reference guide
- Add ContentType enum casting to ContentRecap model
- Add MediaMonitoringTheme relationships and factory support
- Establish comprehensive testing infrastructure for improved code quality and reliability
2025-12-11 14:50:37 +07:00

68 lines
2.1 KiB
PHP

<?php
use App\MediaLibrary\CustomPathGenerator;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
describe('CustomPathGenerator', function () {
beforeEach(function () {
$this->pathGenerator = new CustomPathGenerator;
$this->media = new Media([
'id' => 1,
'model_type' => 'App\Models\MediaMonitoring',
'model_id' => 1,
'collection_name' => 'default',
'name' => 'test-file',
'file_name' => 'test-file.pdf',
'mime_type' => 'application/pdf',
'disk' => 'public',
'conversions_disk' => 'public',
'size' => 1024,
'custom_properties' => [
'feature' => 'media-monitoring',
'date' => '2024-01-15',
'doc_type' => 'document',
],
]);
});
it('generates correct path for media', function () {
$path = $this->pathGenerator->getPath($this->media);
expect($path)->toBeString()
->and($path)->toContain('media-monitoring')
->and($path)->toContain('document')
->and($path)->toContain('2024-01-15');
});
it('generates correct path for conversions', function () {
$path = $this->pathGenerator->getPathForConversions($this->media);
expect($path)->toBeString()
->and($path)->toContain('conversions');
});
it('generates correct path for responsive images', function () {
$path = $this->pathGenerator->getPathForResponsiveImages($this->media);
expect($path)->toBeString()
->and($path)->toContain('responsive');
});
it('handles missing custom properties gracefully', function () {
$mediaWithoutProps = new Media([
'id' => 2,
'model_type' => 'App\Models\Test',
'model_id' => 1,
'collection_name' => 'default',
'name' => 'test',
'file_name' => 'test.jpg',
'custom_properties' => [],
]);
$path = $this->pathGenerator->getPath($mediaWithoutProps);
expect($path)->toBeString()
->and($path)->toContain('misc');
});
});