2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-16 14:26:35 +01:00
|
|
|
namespace Tests\Feature\App\Http\Controllers\Bo;
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
use App\Dto\SlideDto;
|
2026-11-14 16:06:34 +01:00
|
|
|
use App\Http\Requests\Bo\Slides\StoreSlideRequest;
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Models\Slide;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Domain\Enums\UserRole;
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
describe('SlidesController', function (): void {
|
|
|
|
|
beforeEach(function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
// GIVEN
|
|
|
|
|
$this->user = User::factory()->create(['role' => UserRole::SuperAdmin]);
|
|
|
|
|
$this->actingAs($this->user, 'backend');
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
it('can access index', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
|
|
|
|
Slide::factory()->create();
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get('/bo/slides');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($response->status())->toBe(200);
|
|
|
|
|
$response->assertViewIs('bo.slides.index');
|
2026-09-29 15:29:43 +02:00
|
|
|
$response->assertViewHas('slides', fn ($slides) => $slides->items()[0] instanceof SlideDto);
|
2026-10-02 19:44:29 +02:00
|
|
|
$response->assertSee(__('Visible'));
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
it('can access create', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get('/bo/slides/create');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($response->status())->toBe(200);
|
|
|
|
|
$response->assertViewIs('bo.slides.create');
|
2026-11-14 16:06:34 +01:00
|
|
|
$extensions = implode(', ', array_map(
|
|
|
|
|
static fn (string $ext): string => '.' . ltrim($ext, '.'),
|
|
|
|
|
StoreSlideRequest::ALLOWED_EXTENSIONS,
|
|
|
|
|
));
|
|
|
|
|
$expectedHelper = __('Allowed extensions: :extensions (:maxSize MB max). Required dimensions: :width px by :height px', [
|
|
|
|
|
'extensions' => $extensions,
|
|
|
|
|
'maxSize' => StoreSlideRequest::MAX_FILE_SIZE_KB / 1024,
|
|
|
|
|
'width' => StoreSlideRequest::PICTURE_WIDTH,
|
|
|
|
|
'height' => StoreSlideRequest::PICTURE_HEIGHT,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertSee(json_encode($expectedHelper), false);
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
it('can store a slide', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
// GIVEN
|
|
|
|
|
$data = [
|
|
|
|
|
'title' => 'New Slide Title',
|
|
|
|
|
'text' => 'This is the new slide text',
|
|
|
|
|
'link' => 'https://example.com',
|
|
|
|
|
'link_label' => 'Click here',
|
|
|
|
|
'link_new_tab' => false,
|
|
|
|
|
'connected' => false,
|
|
|
|
|
'is_mobile' => false,
|
|
|
|
|
'is_published' => true,
|
|
|
|
|
'client_timezone' => 'Europe/Paris',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->post('/bo/slides', $data);
|
|
|
|
|
|
|
|
|
|
// THEN
|
2026-09-29 15:29:43 +02:00
|
|
|
$slide = Slide::query()->where('title', 'New Slide Title')->first();
|
2026-06-14 21:32:07 +02:00
|
|
|
expect($slide)->not->toBeNull();
|
|
|
|
|
$response->assertRedirect("/bo/slides/{$slide->id}/edit");
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
it('can access edit', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
// GIVEN
|
|
|
|
|
$slide = Slide::factory()->create();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get("/bo/slides/{$slide->id}/edit");
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($response->status())->toBe(200);
|
|
|
|
|
$response->assertViewIs('bo.slides.edit');
|
2026-09-29 15:29:43 +02:00
|
|
|
$response->assertViewHas('slide', fn ($slideData) => $slideData instanceof SlideDto && $slideData->id === $slide->id);
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
it('can update a slide', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
// GIVEN
|
|
|
|
|
$slide = Slide::factory()->create();
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'title' => 'Updated Slide Title',
|
|
|
|
|
'text' => 'This is the new slide text updated',
|
|
|
|
|
'link' => 'https://example.com/updated',
|
|
|
|
|
'link_label' => 'Click here updated',
|
|
|
|
|
'link_new_tab' => true,
|
|
|
|
|
'connected' => true,
|
|
|
|
|
'is_mobile' => true,
|
|
|
|
|
'is_published' => false,
|
|
|
|
|
'client_timezone' => 'Europe/Paris',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->put("/bo/slides/{$slide->id}", $data);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$slide->refresh();
|
|
|
|
|
expect($slide->title)->toBe('Updated Slide Title');
|
|
|
|
|
$response->assertRedirect("/bo/slides/{$slide->id}/edit");
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
it('can delete a slide', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
// GIVEN
|
|
|
|
|
$slide = Slide::factory()->create();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->delete("/bo/slides/{$slide->id}");
|
|
|
|
|
|
|
|
|
|
// THEN
|
2026-09-29 15:29:43 +02:00
|
|
|
expect(Slide::query()->find($slide->id))->toBeNull();
|
2026-06-14 21:32:07 +02:00
|
|
|
$response->assertRedirect('/bo/slides');
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
it('can change order', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
// GIVEN
|
|
|
|
|
$slide1 = Slide::factory()->create(['order' => 1]);
|
|
|
|
|
$slide2 = Slide::factory()->create(['order' => 2]);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->from('/bo/slides')->patch("/bo/slides/{$slide2->id}/up");
|
|
|
|
|
|
|
|
|
|
// THEN
|
2026-11-16 12:46:06 +01:00
|
|
|
$slide1->refresh();
|
|
|
|
|
$slide2->refresh();
|
|
|
|
|
|
|
|
|
|
expect($response->status())->toBe(302)
|
|
|
|
|
->and($slide1->order)->toBe(2)
|
|
|
|
|
->and($slide2->order)->toBe(1);
|
2026-06-14 21:32:07 +02:00
|
|
|
$response->assertRedirect('/bo/slides');
|
|
|
|
|
});
|
|
|
|
|
});
|