Skip to content

Commit

Permalink
fix: position and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo authored and nicolo committed Jul 25, 2024
1 parent 06725db commit 5aaf384
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/View/Helper/PosterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down
27 changes: 27 additions & 0 deletions tests/TestCase/View/Helper/PosterHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.
*
Expand Down

0 comments on commit 5aaf384

Please sign in to comment.