Skip to content

Commit

Permalink
Add integration test for watermark with alpha
Browse files Browse the repository at this point in the history
Added integration tests for handling alpha transparency in watermarks.
Renamed the current test for watermarks as it only tests if the
watermark is correctly places
  • Loading branch information
elzekool committed Nov 19, 2017
1 parent 519f3e1 commit 00a5c3a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,97 @@ public function rotateDataProvider()
);
}

/**
* Test if alpha transparency is correctly handled
*
* @param string $image
* @param string $watermark
* @param int $alphaPercentage
* @param array $comparePoint1
* @param array $comparePoint2
* @param string $adapterType
*
* @dataProvider imageWatermarkWithAlphaTransparencyDataProvider
* @depends testOpen
* @depends testImageSize
*/
public function testWatermarkWithAlphaTransparency(
$image,
$watermark,
$alphaPercentage,
$comparePoint1,
$comparePoint2,
$adapterType
) {
$imageAdapter = $this->_getAdapter($adapterType);
$imageAdapter->open($image);

$watermarkAdapter = $this->_getAdapter($adapterType);
$watermarkAdapter->open($watermark);

list($comparePoint1X, $comparePoint1Y) = $comparePoint1;
list($comparePoint2X, $comparePoint2Y) = $comparePoint2;

$imageAdapter
->setWatermarkImageOpacity($alphaPercentage)
->setWatermarkPosition(\Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_TOP_LEFT)
->watermark($watermark);

$comparePoint1Color = $imageAdapter->getColorAt($comparePoint1X, $comparePoint1Y);
unset($comparePoint1Color['alpha']);

$comparePoint2Color = $imageAdapter->getColorAt($comparePoint2X, $comparePoint2Y);
unset($comparePoint2Color['alpha']);

$result = $this->_compareColors($comparePoint1Color, $comparePoint2Color);
$message = sprintf(
'%s should be different to %s due to alpha transparency',
join(',', $comparePoint1Color),
join(',', $comparePoint2Color)
);
$this->assertFalse($result, $message);
}

public function imageWatermarkWithAlphaTransparencyDataProvider()
{
return $this->_prepareData(
[
// Watermark with alpha channel, 25%
[
$this->_getFixture('watermark_alpha_base_image.jpg'),
$this->_getFixture('watermark_alpha.png'),
25,
[ 23, 3 ],
[ 23, 30 ]
],
// Watermark with alpha channel, 50%
[
$this->_getFixture('watermark_alpha_base_image.jpg'),
$this->_getFixture('watermark_alpha.png'),
50,
[ 23, 3 ],
[ 23, 30 ]
],
// Watermark with no alpha channel, 50%
[
$this->_getFixture('watermark_alpha_base_image.jpg'),
$this->_getFixture('watermark.png'),
50,
[ 3, 3 ],
[ 23,3 ]
],
// Watermark with no alpha channel, 100%
[
$this->_getFixture('watermark_alpha_base_image.jpg'),
$this->_getFixture('watermark.png'),
100,
[ 3, 3 ],
[ 3, 60 ]
],
]
);
}

/**
* Checks if watermark exists on the right position
*
Expand All @@ -350,10 +441,10 @@ public function rotateDataProvider()
* @param int $colorY
* @param string $adapterType
*
* @dataProvider imageWatermarkDataProvider
* @dataProvider imageWatermarkPositionDataProvider
* @depends testOpen
*/
public function testWatermark(
public function testWatermarkPosition(
$image,
$watermark,
$width,
Expand Down Expand Up @@ -387,7 +478,7 @@ public function testWatermark(
$this->assertFalse($result, $message);
}

public function imageWatermarkDataProvider()
public function imageWatermarkPositionDataProvider()
{
return $this->_prepareData(
[
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 00a5c3a

Please sign in to comment.