From 5aaf384c2faa7f34c4f6fb778a3ba50d85a240ce Mon Sep 17 00:00:00 2001 From: nicolo Date: Thu, 25 Jul 2024 11:58:04 +0200 Subject: [PATCH] fix: position and tests --- src/View/Helper/PosterHelper.php | 5 ++-- .../TestCase/View/Helper/PosterHelperTest.php | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/View/Helper/PosterHelper.php b/src/View/Helper/PosterHelper.php index c7ce8b3..283980d 100644 --- a/src/View/Helper/PosterHelper.php +++ b/src/View/Helper/PosterHelper.php @@ -185,7 +185,6 @@ protected function getStreamWidth(Media $media): int /** * Get sizes attribute for image. * - * @param \BEdita\Core\Model\Entity\Media $poster Poster entity. * @return string */ public function sizes(Media $poster): string @@ -388,14 +387,14 @@ public function position(ObjectEntity|null $object, string $variantPrefix = 'mob $objPosition = $getPositionValues($props); - $variant = $this->mobile($object); + $variant = $this->mobile($poster ?? $object); if ($variant) { $variantPosition = $getPositionValues($variant->custom_props, $variantPrefix) ?? ''; $objPosition = $variantPosition . ' ' . $objPosition; } - return $objPosition; + return trim($objPosition); } /** diff --git a/tests/TestCase/View/Helper/PosterHelperTest.php b/tests/TestCase/View/Helper/PosterHelperTest.php index 31f54eb..0468ec5 100644 --- a/tests/TestCase/View/Helper/PosterHelperTest.php +++ b/tests/TestCase/View/Helper/PosterHelperTest.php @@ -234,6 +234,33 @@ public function testSizes() $this->assertSame('(max-width: 767px) 320px', $this->Poster->sizes($image)); } + /** + * Test {@see PosterHelper::position()}. + * + * @return void + * @covers ::position() + */ + public function testPosition() + { + $image = $this->createImage(1500, 1000); + $this->setVariantProviderThumbnail($image, 640, 480); + $image['custom_props'] = [ + 'position_x' => '0', + 'position_y' => '100', + ]; + + $this->assertSame('left top', $this->Poster->position($image)); + + $image['has_variant_mobile'][0]['custom_props'] = [ + 'position_x' => '100', + 'position_y' => '0', + ]; + + $this->assertSame('mobile-right mobile-bottom left top', $this->Poster->position($image)); + + $this->assertSame('prefix-right prefix-bottom left top', $this->Poster->position($image, 'prefix-')); + } + /** * Test {@see PosterHelper::url()}. *