Skip to content

Commit

Permalink
Merge pull request #114 from netglue/113-fix-null-image-dimensions
Browse files Browse the repository at this point in the history
Fix Image Constraints
  • Loading branch information
gsteel authored Jun 28, 2022
2 parents da53dd0 + 594db8d commit 5a22c7a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ public static function img(string $label, ?string $placeholder = null, ?int $x =
'config' => array_filter([
'label' => $label,
'placeholder' => $placeholder,
'constraint' => array_filter([
'constraint' => [
'width' => $x,
'height' => $y,
]),
],
'thumbnails' => $views,
]),
];
Expand All @@ -303,11 +303,11 @@ public static function img(string $label, ?string $placeholder = null, ?int $x =
/** @return array<string, mixed> */
public static function imgView(string $name, ?int $x = null, ?int $y = null): array
{
return array_filter([
return [
'name' => $name,
'width' => $x,
'height' => $y,
]);
];
}

/** @param array<array-key, string> $types */
Expand Down
27 changes: 27 additions & 0 deletions test/Unit/TypeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,31 @@ public function testImageConstraintIsAbsentInRichTextWhenNeitherXNorYAreProvided
self::assertIsArray($config);
self::assertArrayNotHasKey('imageConstraint', $config);
}

public function testImageSpecDeclaresNullOnConstraintsWhenGivenNull(): void
{
$data = T::img('Foo', null, 100, null, []);
$expect = [
'type' => 'Image',
'config' => [
'label' => 'Foo',
'constraint' => [
'width' => 100,
'height' => null,
],
],
];
self::assertEquals($expect, $data);
}

public function testThatImageViewsContainNullConstraintsWhenNullIsGiven(): void
{
$data = T::imgView('Foo', null, 100);
$expect = [
'name' => 'Foo',
'width' => null,
'height' => 100,
];
self::assertEquals($expect, $data);
}
}

0 comments on commit 5a22c7a

Please sign in to comment.