ReplaceEffectTest.php in Image Replace 8
File
src/Tests/ReplaceEffectTest.php
View source
<?php
namespace Drupal\image_replace\Tests;
use Drupal\image\Entity\ImageStyle;
class ReplaceEffectTest extends ImageReplaceTestBase {
public static $modules = [
'image_replace',
];
public function testReplaceEffect() {
list($original_file, $replacement_file) = $this
->createTestFiles();
$storage_service = \Drupal::service('image_replace.storage');
$file_system = \Drupal::service('file_system');
$style_name = 'image_replace_test';
$this
->createImageStyle($style_name);
$generated_url = ImageStyle::load($style_name)
->buildUrl($original_file
->getFileUri());
$generated_image_data = $this
->drupalGet($generated_url);
$this
->assertSession()
->statusCodeEquals(200);
$default_scheme = \Drupal::config('system.file')
->get('default_scheme');
$file_destination = $default_scheme . '://';
$generated_uri = $file_system
->saveData($generated_image_data, $file_destination);
$this
->assertTrue($this
->imageIsOriginal($generated_uri), 'The generated file should be the same as the original file if there is no replacement mapping.');
$storage_service
->add($style_name, $original_file
->getFileUri(), $replacement_file
->getFileUri());
ImageStyle::load($style_name)
->flush();
$generated_url = ImageStyle::load($style_name)
->buildUrl($original_file
->getFileUri());
$generated_image_data = $this
->drupalGet($generated_url);
$this
->assertSession()
->statusCodeEquals(200);
$generated_uri = $file_system
->saveData($generated_image_data, $file_destination);
$this
->assertTrue($this
->imageIsReplacement($generated_uri), 'The generated file should be the same as the replacement file.');
$storage_service
->remove($style_name, $original_file
->getFileUri(), $replacement_file
->getFileUri());
ImageStyle::load($style_name)
->flush();
$generated_url = ImageStyle::load($style_name)
->buildUrl($original_file
->getFileUri());
$generated_image_data = $this
->drupalGet($generated_url);
$this
->assertSession()
->statusCodeEquals(200);
$generated_uri = $file_system
->saveData($generated_image_data, $file_destination);
$this
->assertTrue($this
->imageIsOriginal($generated_uri), 'The generated file should be the same as the original file if the replacement mapping was removed.');
}
}