Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 00a5c3a

Browse files
committed
Add integration test for watermark with alpha
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
1 parent 519f3e1 commit 00a5c3a

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

dev/tests/integration/testsuite/Magento/Framework/Image/Adapter/InterfaceTest.php

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,97 @@ public function rotateDataProvider()
337337
);
338338
}
339339

340+
/**
341+
* Test if alpha transparency is correctly handled
342+
*
343+
* @param string $image
344+
* @param string $watermark
345+
* @param int $alphaPercentage
346+
* @param array $comparePoint1
347+
* @param array $comparePoint2
348+
* @param string $adapterType
349+
*
350+
* @dataProvider imageWatermarkWithAlphaTransparencyDataProvider
351+
* @depends testOpen
352+
* @depends testImageSize
353+
*/
354+
public function testWatermarkWithAlphaTransparency(
355+
$image,
356+
$watermark,
357+
$alphaPercentage,
358+
$comparePoint1,
359+
$comparePoint2,
360+
$adapterType
361+
) {
362+
$imageAdapter = $this->_getAdapter($adapterType);
363+
$imageAdapter->open($image);
364+
365+
$watermarkAdapter = $this->_getAdapter($adapterType);
366+
$watermarkAdapter->open($watermark);
367+
368+
list($comparePoint1X, $comparePoint1Y) = $comparePoint1;
369+
list($comparePoint2X, $comparePoint2Y) = $comparePoint2;
370+
371+
$imageAdapter
372+
->setWatermarkImageOpacity($alphaPercentage)
373+
->setWatermarkPosition(\Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_TOP_LEFT)
374+
->watermark($watermark);
375+
376+
$comparePoint1Color = $imageAdapter->getColorAt($comparePoint1X, $comparePoint1Y);
377+
unset($comparePoint1Color['alpha']);
378+
379+
$comparePoint2Color = $imageAdapter->getColorAt($comparePoint2X, $comparePoint2Y);
380+
unset($comparePoint2Color['alpha']);
381+
382+
$result = $this->_compareColors($comparePoint1Color, $comparePoint2Color);
383+
$message = sprintf(
384+
'%s should be different to %s due to alpha transparency',
385+
join(',', $comparePoint1Color),
386+
join(',', $comparePoint2Color)
387+
);
388+
$this->assertFalse($result, $message);
389+
}
390+
391+
public function imageWatermarkWithAlphaTransparencyDataProvider()
392+
{
393+
return $this->_prepareData(
394+
[
395+
// Watermark with alpha channel, 25%
396+
[
397+
$this->_getFixture('watermark_alpha_base_image.jpg'),
398+
$this->_getFixture('watermark_alpha.png'),
399+
25,
400+
[ 23, 3 ],
401+
[ 23, 30 ]
402+
],
403+
// Watermark with alpha channel, 50%
404+
[
405+
$this->_getFixture('watermark_alpha_base_image.jpg'),
406+
$this->_getFixture('watermark_alpha.png'),
407+
50,
408+
[ 23, 3 ],
409+
[ 23, 30 ]
410+
],
411+
// Watermark with no alpha channel, 50%
412+
[
413+
$this->_getFixture('watermark_alpha_base_image.jpg'),
414+
$this->_getFixture('watermark.png'),
415+
50,
416+
[ 3, 3 ],
417+
[ 23,3 ]
418+
],
419+
// Watermark with no alpha channel, 100%
420+
[
421+
$this->_getFixture('watermark_alpha_base_image.jpg'),
422+
$this->_getFixture('watermark.png'),
423+
100,
424+
[ 3, 3 ],
425+
[ 3, 60 ]
426+
],
427+
]
428+
);
429+
}
430+
340431
/**
341432
* Checks if watermark exists on the right position
342433
*
@@ -350,10 +441,10 @@ public function rotateDataProvider()
350441
* @param int $colorY
351442
* @param string $adapterType
352443
*
353-
* @dataProvider imageWatermarkDataProvider
444+
* @dataProvider imageWatermarkPositionDataProvider
354445
* @depends testOpen
355446
*/
356-
public function testWatermark(
447+
public function testWatermarkPosition(
357448
$image,
358449
$watermark,
359450
$width,
@@ -387,7 +478,7 @@ public function testWatermark(
387478
$this->assertFalse($result, $message);
388479
}
389480

390-
public function imageWatermarkDataProvider()
481+
public function imageWatermarkPositionDataProvider()
391482
{
392483
return $this->_prepareData(
393484
[
Loading
Loading

0 commit comments

Comments
 (0)