|
8 | 8 | namespace Ibexa\Tests\Core\FieldType; |
9 | 9 |
|
10 | 10 | use Ibexa\Contracts\Core\IO\MimeTypeDetector; |
| 11 | +use Ibexa\Contracts\Core\Persistence\Content\FieldValue; |
11 | 12 | use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; |
12 | 13 | use Ibexa\Core\Base\Exceptions\InvalidArgumentException; |
13 | 14 | use Ibexa\Core\FieldType\Image\Type as ImageType; |
@@ -347,6 +348,62 @@ public function provideInputForFromHash(): iterable |
347 | 348 | ]; |
348 | 349 | } |
349 | 350 |
|
| 351 | + /** |
| 352 | + * @phpstan-return iterable<string, array{array<string, mixed>, mixed, mixed}> |
| 353 | + */ |
| 354 | + public function provideDataForFromPersistenceValue(): iterable |
| 355 | + { |
| 356 | + yield 'width and height as empty string are converted to null' => [ |
| 357 | + [ |
| 358 | + 'width' => '', |
| 359 | + 'height' => '', |
| 360 | + ], |
| 361 | + null, |
| 362 | + null, |
| 363 | + ]; |
| 364 | + |
| 365 | + yield 'width and height as zero are preserved' => [ |
| 366 | + [ |
| 367 | + 'width' => 0, |
| 368 | + 'height' => '0', |
| 369 | + ], |
| 370 | + 0, |
| 371 | + '0', |
| 372 | + ]; |
| 373 | + |
| 374 | + yield 'width and height as valid values are preserved' => [ |
| 375 | + [ |
| 376 | + 'width' => 100, |
| 377 | + 'height' => '200', |
| 378 | + ], |
| 379 | + 100, |
| 380 | + '200', |
| 381 | + ]; |
| 382 | + |
| 383 | + yield 'missing width and height keys default to null' => [ |
| 384 | + [], |
| 385 | + null, |
| 386 | + null, |
| 387 | + ]; |
| 388 | + } |
| 389 | + |
| 390 | + /** |
| 391 | + * @param array<string, mixed> $data |
| 392 | + * |
| 393 | + * @dataProvider provideDataForFromPersistenceValue |
| 394 | + */ |
| 395 | + public function testFromPersistenceValue(array $data, mixed $expectedWidth, mixed $expectedHeight): void |
| 396 | + { |
| 397 | + $fieldType = $this->getFieldTypeUnderTest(); |
| 398 | + |
| 399 | + $fieldValue = new FieldValue(['data' => $data]); |
| 400 | + $result = $fieldType->fromPersistenceValue($fieldValue); |
| 401 | + |
| 402 | + self::assertInstanceOf(ImageValue::class, $result); |
| 403 | + self::assertSame($expectedWidth, $result->width); |
| 404 | + self::assertSame($expectedHeight, $result->height); |
| 405 | + } |
| 406 | + |
350 | 407 | protected function provideFieldTypeIdentifier(): string |
351 | 408 | { |
352 | 409 | return 'ibexa_image'; |
|
0 commit comments