-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91e3859
commit 54628cf
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
modules/oe_theme_helper/tests/src/Functional/RetinaScaleEffectTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\Tests\oe_theme_helper\Functional; | ||
|
||
use Drupal\FunctionalTests\Image\ToolkitTestBase; | ||
|
||
/** | ||
* Tests that the Retina Scale effect upscales images appropriately. | ||
* | ||
* @group image | ||
*/ | ||
class RetinaScaleEffectTest extends ToolkitTestBase { | ||
/** | ||
* Modules to enable. | ||
* | ||
* @var array | ||
*/ | ||
public static $modules = ['image', 'oe_theme_helper']; | ||
|
||
/** | ||
* The image effect manager. | ||
* | ||
* @var \Drupal\image\ImageEffectManager | ||
*/ | ||
protected $manager; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
$this->manager = $this->container->get('plugin.manager.image.effect'); | ||
} | ||
|
||
/** | ||
* Test the retina_image_scale_effect() function. | ||
*/ | ||
public function testRetinaScaleEffect() { | ||
$this->assertImageEffect('retina_image_scale', [ | ||
// Set the desired width to be much higher than the image width. | ||
'width' => $this->image->getWidth() * 10, | ||
]); | ||
$this->assertToolkitOperationsCalled(['scale']); | ||
|
||
// Check the parameters. | ||
$calls = $this->imageTestGetAllCalls(); | ||
$this->assertEqual($calls['scale'][0][0], $this->image->getWidth() * 2, 'Width is double the original size.'); | ||
$this->assertEqual($calls['scale'][0][1], $this->image->getHeight() * 2, 'Height is double the original size.'); | ||
} | ||
|
||
/** | ||
* Test the image_scale_effect() function using a multiplier of 3. | ||
*/ | ||
public function testTripleMultiplierRetinaScaleEffect() { | ||
$this->assertImageEffect('retina_image_scale', [ | ||
// Set the desired width to be much higher than the image width. | ||
'width' => $this->image->getWidth() * 10, | ||
// Set a multiplier of three for the test. | ||
'multiplier' => 3, | ||
]); | ||
$this->assertToolkitOperationsCalled(['scale']); | ||
|
||
// Check the parameters. | ||
$calls = $this->imageTestGetAllCalls(); | ||
$this->assertEqual($calls['scale'][0][0], $this->image->getWidth() * 3, 'Width is triple the original size.'); | ||
$this->assertEqual($calls['scale'][0][1], $this->image->getHeight() * 3, 'Height is triple the original size.'); | ||
} | ||
|
||
/** | ||
* Asserts the effect processing of an image effect plugin. | ||
* | ||
* @param string $effect_name | ||
* The name of the image effect to test. | ||
* @param array $data | ||
* The data to pass to the image effect. | ||
* | ||
* @return bool | ||
* TRUE if the assertion succeeded, FALSE otherwise. | ||
*/ | ||
protected function assertImageEffect($effect_name, array $data) { | ||
/** @var \Drupal\image\ImageEffectInterface $effect */ | ||
$effect = $this->manager->createInstance($effect_name, ['data' => $data]); | ||
return $this->assertTrue($effect->applyEffect($this->image), 'Function returned the expected value.'); | ||
} | ||
|
||
} |