- Updated DataTableService to accept a Pagination object for pagination parameters. - Refactored paginateQuery method to utilize pageSize and pageNumber from Pagination. refactor: replace ActionExecutor with Executor in controller traits - Updated ChangesModelOrder, TogglesModelStar, and TogglesModelStatus traits to use Executor interface instead of ActionExecutor. feat: add PictureMetadata and Slug value objects - Introduced PictureMetadata for managing image metadata with validation. - Added Slug value object for slug generation and validation. feat: update breadcrumbs to support RangeDto - Modified breadcrumbs-bo.php to accept RangeDto in the edit route. test: add tests for RangesController - Added tests for accessing, creating, updating, and deleting ranges. - Included tests for toggling range status. test: add integration tests for range actions - Created tests for CreateRange, DeleteRange, and UpdateRange actions. - Validated input handling and database interactions. test: add unit tests for range input classes - Implemented tests for CreateRangeInput and UpdateRangeInput to validate input constraints. test: add unit tests for value objects - Added tests for PictureMetadata and Slug to ensure proper validation and instantiation. test: add unit tests for RangeDto - Created tests to verify RangeDto mapping from Range model. test: add unit tests for RangePolicy - Implemented tests for RangePolicy to validate permissions based on user roles.
169 lines
5.1 KiB
PHP
169 lines
5.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\Range;
|
|
use App\Models\User;
|
|
use Domain\Enums\UserRole;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
describe('RangesController', function () {
|
|
beforeEach(function () {
|
|
/** @var \Tests\TestCase $this */
|
|
// GIVEN
|
|
$this->user = User::factory()->create(['role' => UserRole::SuperAdmin]);
|
|
$this->actingAs($this->user, 'backend');
|
|
});
|
|
|
|
it('can access index', function () {
|
|
/** @var \Tests\TestCase $this */
|
|
// WHEN
|
|
$response = $this->get('/bo/ranges');
|
|
|
|
// THEN
|
|
expect($response->status())->toBe(200);
|
|
});
|
|
|
|
it('can access create', function () {
|
|
/** @var \Tests\TestCase $this */
|
|
// WHEN
|
|
$response = $this->get('/bo/ranges/create');
|
|
|
|
// THEN
|
|
expect($response->status())->toBe(200);
|
|
});
|
|
|
|
it('can store a range', function () {
|
|
/** @var \Tests\TestCase $this */
|
|
// GIVEN
|
|
$data = [
|
|
'name' => 'New Range',
|
|
'status' => true,
|
|
'picture' => UploadedFile::fake()->image('picture.jpg', 500, 500),
|
|
'picture_alt' => 'some alt text',
|
|
'picture_title' => 'some title text',
|
|
];
|
|
|
|
// WHEN
|
|
$response = $this->post('/bo/ranges', $data);
|
|
|
|
// THEN
|
|
$range = Range::query()->where('name', 'New Range')->first();
|
|
expect($response->isRedirect())->toBeTrue()
|
|
->and($range)->not->toBeNull()
|
|
->and($range?->slug)->toBe('new-range');
|
|
});
|
|
|
|
it('can access edit', function () {
|
|
/** @var \Tests\TestCase $this */
|
|
// GIVEN
|
|
$range = new Range();
|
|
$range->name = 'My Range';
|
|
$range->status = true;
|
|
$range->picture_alt = 'alt text here';
|
|
$range->picture_title = 'title text here';
|
|
$range->save();
|
|
|
|
// WHEN
|
|
$response = $this->get("/bo/ranges/{$range->slug}/edit");
|
|
|
|
// THEN
|
|
expect($response->status())->toBe(200);
|
|
});
|
|
|
|
it('can update a range', function () {
|
|
/** @var \Tests\TestCase $this */
|
|
// GIVEN
|
|
$range = new Range();
|
|
$range->name = 'My Range';
|
|
$range->status = true;
|
|
$range->picture_alt = 'alt text here';
|
|
$range->picture_title = 'title text here';
|
|
$range->save();
|
|
|
|
$data = [
|
|
'name' => 'Updated Range',
|
|
'status' => false,
|
|
'picture' => UploadedFile::fake()->image('picture.jpg', 500, 500),
|
|
'picture_alt' => 'some alt text updated',
|
|
'picture_title' => 'some title text updated',
|
|
];
|
|
|
|
// WHEN
|
|
$response = $this->put("/bo/ranges/{$range->slug}", $data);
|
|
|
|
// THEN
|
|
$range->refresh();
|
|
expect($response->isRedirect())->toBeTrue()
|
|
->and($range->name)->toBe('Updated Range')
|
|
->and($range->status)->toBeFalse();
|
|
});
|
|
|
|
it('can delete a range', function () {
|
|
/** @var \Tests\TestCase $this */
|
|
// GIVEN
|
|
$range = new Range();
|
|
$range->name = 'My Range';
|
|
$range->status = true;
|
|
$range->picture_alt = 'alt text here';
|
|
$range->picture_title = 'title text here';
|
|
$range->save();
|
|
|
|
// WHEN
|
|
$response = $this->delete("/bo/ranges/{$range->slug}");
|
|
|
|
// THEN
|
|
expect($response->isRedirect())->toBeTrue()
|
|
->and(Range::query()->find($range->id))->toBeNull();
|
|
});
|
|
|
|
it('can change order', function () {
|
|
/** @var \Tests\TestCase $this */
|
|
// GIVEN
|
|
$range1 = new Range();
|
|
$range1->name = 'My Range 1';
|
|
$range1->status = true;
|
|
$range1->order = 1;
|
|
$range1->picture_alt = 'alt';
|
|
$range1->picture_title = 'title';
|
|
$range1->save();
|
|
|
|
$range2 = new Range();
|
|
$range2->name = 'My Range 2';
|
|
$range2->status = true;
|
|
$range2->order = 2;
|
|
$range2->picture_alt = 'alt';
|
|
$range2->picture_title = 'title';
|
|
$range2->save();
|
|
|
|
// WHEN
|
|
$response = $this->from('/bo/ranges')->patch("/bo/ranges/{$range2->slug}/up");
|
|
|
|
// THEN
|
|
expect($response->status())->toBe(302);
|
|
$response->assertRedirect('/bo/ranges');
|
|
});
|
|
|
|
it('can toggle status', function () {
|
|
/** @var \Tests\TestCase $this */
|
|
// GIVEN
|
|
$range = new Range();
|
|
$range->name = 'My Range';
|
|
$range->status = false;
|
|
$range->picture_alt = 'alt';
|
|
$range->picture_title = 'title';
|
|
$range->save();
|
|
|
|
// WHEN
|
|
$response = $this->from('/bo/ranges')->patch("/bo/ranges/{$range->slug}/toggle-status");
|
|
|
|
// THEN
|
|
expect($response->status())->toBe(302);
|
|
$response->assertRedirect('/bo/ranges');
|
|
$range->refresh();
|
|
expect($range->status)->toBeTrue();
|
|
});
|
|
});
|