ldc-cocotte/tests/Feature/App/Http/Controllers/Bo/SlidesControllerTest.php

120 lines
3.4 KiB
PHP
Raw Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
use App\Models\Slide;
use App\Models\User;
use Domain\Enums\UserRole;
describe('SlidesController', function () {
beforeEach(function () {
// GIVEN
$this->user = User::factory()->create(['role' => UserRole::SuperAdmin]);
$this->actingAs($this->user, 'backend');
});
it('can access index', function () {
// WHEN
$response = $this->get('/bo/slides');
// THEN
expect($response->status())->toBe(200);
$response->assertViewIs('bo.slides.index');
});
it('can access create', function () {
// WHEN
$response = $this->get('/bo/slides/create');
// THEN
expect($response->status())->toBe(200);
$response->assertViewIs('bo.slides.create');
});
it('can store a slide', function () {
// 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
$slide = Slide::where('title', 'New Slide Title')->first();
expect($slide)->not->toBeNull();
$response->assertRedirect("/bo/slides/{$slide->id}/edit");
});
it('can access edit', function () {
// 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');
});
it('can update a slide', function () {
// 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");
});
it('can delete a slide', function () {
// GIVEN
$slide = Slide::factory()->create();
// WHEN
$response = $this->delete("/bo/slides/{$slide->id}");
// THEN
expect(Slide::find($slide->id))->toBeNull();
$response->assertRedirect('/bo/slides');
});
it('can change order', function () {
// 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
expect($response->status())->toBe(302);
$response->assertRedirect('/bo/slides');
});
});