- 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.
84 lines
2.6 KiB
PHP
84 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Domain\Models\ValueObjects\PictureMetadata;
|
|
use InvalidArgumentException;
|
|
|
|
describe('PictureMetadata Value Object', function () {
|
|
test('it can be instantiated with null values', function () {
|
|
// GIVEN & WHEN
|
|
$metadata = new PictureMetadata();
|
|
|
|
// THEN
|
|
expect($metadata->alt)->toBeNull()
|
|
->and($metadata->title)->toBeNull();
|
|
});
|
|
|
|
test('it can be instantiated with valid alt and title', function () {
|
|
// GIVEN
|
|
$alt = 'Belle image de chat';
|
|
$title = 'Un chat qui joue';
|
|
|
|
// WHEN
|
|
$metadata = new PictureMetadata(alt: $alt, title: $title);
|
|
|
|
// THEN
|
|
expect($metadata->alt)->toBe($alt)
|
|
->and($metadata->title)->toBe($title);
|
|
});
|
|
|
|
test('it throws when alt is empty string', function () {
|
|
// GIVEN
|
|
$invalidAlt = ' ';
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new PictureMetadata(alt: $invalidAlt))
|
|
->toThrow(InvalidArgumentException::class, 'Picture alt cannot be empty when provided.');
|
|
});
|
|
|
|
test('it throws when alt is shorter than 4 characters', function () {
|
|
// GIVEN
|
|
$shortAlt = 'abc';
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new PictureMetadata(alt: $shortAlt))
|
|
->toThrow(InvalidArgumentException::class, 'Picture alt must be at least 4 characters.');
|
|
});
|
|
|
|
test('it throws when alt exceeds 75 characters', function () {
|
|
// GIVEN
|
|
$longAlt = str_repeat('a', 76);
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new PictureMetadata(alt: $longAlt))
|
|
->toThrow(InvalidArgumentException::class, 'Picture alt cannot exceed 75 characters.');
|
|
});
|
|
|
|
test('it throws when title is empty string', function () {
|
|
// GIVEN
|
|
$invalidTitle = ' ';
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new PictureMetadata(title: $invalidTitle))
|
|
->toThrow(InvalidArgumentException::class, 'Picture title cannot be empty when provided.');
|
|
});
|
|
|
|
test('it throws when title is shorter than 4 characters', function () {
|
|
// GIVEN
|
|
$shortTitle = 'xyz';
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new PictureMetadata(title: $shortTitle))
|
|
->toThrow(InvalidArgumentException::class, 'Picture title must be at least 4 characters.');
|
|
});
|
|
|
|
test('it throws when title exceeds 75 characters', function () {
|
|
// GIVEN
|
|
$longTitle = str_repeat('b', 76);
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new PictureMetadata(title: $longTitle))
|
|
->toThrow(InvalidArgumentException::class, 'Picture title cannot exceed 75 characters.');
|
|
});
|
|
});
|