108 lines
4.4 KiB
PHP
108 lines
4.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Dto;
|
|
|
|
use App\Dto\SlideDto;
|
|
use App\Lib\PublicS3Disk;
|
|
use App\Models\Slide;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Uwil\Storage\Lib\ValueObjects\StorageFilePath;
|
|
|
|
describe('SlideDto integration', function (): void {
|
|
beforeEach(function (): void {
|
|
Carbon::setTestNow('2026-11-01 12:00:00');
|
|
config(['filesystems.disks.s3.url' => 'https://cdn.test']);
|
|
Storage::forgetDisk(['s3', 's3-public']);
|
|
app()->forgetInstance(PublicS3Disk::class);
|
|
});
|
|
|
|
afterEach(function (): void {
|
|
Carbon::setTestNow();
|
|
});
|
|
|
|
it('creates a DTO from Slide model with booted application and resolves public S3 URL', function (): void {
|
|
// GIVEN
|
|
$dateStart = Carbon::parse('2026-06-01 10:00:00');
|
|
$dateEnd = Carbon::parse('2026-06-30 20:00:00');
|
|
|
|
$slide = new Slide();
|
|
$slide->id = 42;
|
|
$slide->title = 'Bannière Été';
|
|
$slide->text = '<p>Découvrez notre nouvelle collection</p>';
|
|
$slide->picture = new StorageFilePath('storage/modelfiles/slides/26/06/01/ab/summer.jpg');
|
|
$slide->picture_alt = 'Collection Été';
|
|
$slide->picture_title = 'Bannière promotionnelle été';
|
|
$slide->link = 'https://example.com/ete';
|
|
$slide->link_label = 'Voir les offres';
|
|
$slide->link_new_tab = true;
|
|
$slide->connected = false;
|
|
$slide->date_start = $dateStart;
|
|
$slide->date_end = $dateEnd;
|
|
$slide->order = 3;
|
|
$slide->status = true;
|
|
|
|
// WHEN
|
|
$dto = SlideDto::fromModel($slide);
|
|
|
|
// THEN
|
|
expect($dto->id)->toBe(42)
|
|
->and($dto->title)->toBe('Bannière Été')
|
|
->and($dto->text)->toBe('<p>Découvrez notre nouvelle collection</p>')
|
|
->and($dto->picture)->toBe('https://cdn.test/public/storage/modelfiles/slides/26/06/01/ab/summer.jpg')
|
|
->and($dto->picture_alt)->toBe('Collection Été')
|
|
->and($dto->picture_title)->toBe('Bannière promotionnelle été')
|
|
->and($dto->link)->toBe('https://example.com/ete')
|
|
->and($dto->link_label)->toBe('Voir les offres')
|
|
->and($dto->link_new_tab)->toBeTrue()
|
|
->and($dto->connected)->toBeFalse()
|
|
->and($dto->date_start)->toEqual($dateStart)
|
|
->and($dto->date_end)->toEqual($dateEnd)
|
|
->and($dto->order)->toBe(3)
|
|
->and($dto->status)->toBeTrue()
|
|
->and($dto->isVisible())->toBeFalse()
|
|
->and($dto->getRouteKey())->toBe(42)
|
|
->and($dto->getRouteKeyName())->toBe('id')
|
|
->and($dto->resolveRouteBinding(42))->toBeNull()
|
|
->and($dto->resolveChildRouteBinding('child', 'val', 'field'))->toBeNull()
|
|
->and($dto->toArray())->toEqual([
|
|
'id' => 42,
|
|
'title' => 'Bannière Été',
|
|
'text' => '<p>Découvrez notre nouvelle collection</p>',
|
|
'picture' => 'https://cdn.test/public/storage/modelfiles/slides/26/06/01/ab/summer.jpg',
|
|
'picture_alt' => 'Collection Été',
|
|
'picture_title' => 'Bannière promotionnelle été',
|
|
'link' => 'https://example.com/ete',
|
|
'link_label' => 'Voir les offres',
|
|
'link_new_tab' => true,
|
|
'connected' => false,
|
|
'date_start' => $dateStart,
|
|
'date_end' => $dateEnd,
|
|
'order' => 3,
|
|
'status' => true,
|
|
'is_visible' => false,
|
|
]);
|
|
});
|
|
|
|
it('creates a DTO from Slide model when picture is null', function (): void {
|
|
// GIVEN
|
|
$slide = new Slide();
|
|
$slide->id = 43;
|
|
$slide->title = 'Slide sans image';
|
|
$slide->text = '<p>Texte uniquement</p>';
|
|
$slide->picture = null;
|
|
$slide->link_new_tab = false;
|
|
$slide->connected = false;
|
|
$slide->order = 1;
|
|
$slide->status = true;
|
|
|
|
// WHEN
|
|
$dto = SlideDto::fromModel($slide);
|
|
|
|
// THEN
|
|
expect($dto->picture)->toBeNull()
|
|
->and($dto->title)->toBe('Slide sans image');
|
|
});
|
|
});
|