diff --git a/core/modules/simpletest/files/img-test.webp b/core/modules/simpletest/files/img-test.webp deleted file mode 100644 index c9c799c..0000000 Binary files a/core/modules/simpletest/files/img-test.webp and /dev/null differ diff --git a/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php b/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php index a7fb86f..2fae80f 100644 --- a/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php +++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php @@ -52,11 +52,6 @@ protected function setUp() { // Set the image factory service. $this->imageFactory = $this->container->get('image.factory'); - - // For PHP 7.1+, ensure test PHP has webp extension installed. - if (PHP_VERSION_ID >= 70100) { - $this->assertTrue(function_exists('imagewebp')); - } } protected function checkRequirements() { @@ -70,6 +65,23 @@ protected function checkRequirements() { } /** + * Builds a WebP format test image using GD primitives. + */ + protected function buildWebpTestImage() { + $res = imagecreatetruecolor(40, 20); + $red = imagecolorallocatealpha($res, 255, 0, 0, 0); + $green = imagecolorallocatealpha($res, 0, 255, 0, 0); + $blue = imagecolorallocatealpha($res, 0, 0, 255, 0); + $yellow_transparent = imagecolorallocatealpha($res, 255, 255, 0, 127); + imagefilledrectangle($res, 0, 0, 19, 9, $red); + imagefilledrectangle($res, 20, 0, 39, 9, $green); + imagefilledrectangle($res, 20, 10, 39, 19, $blue); + imagefilledrectangle($res, 0, 10, 19, 19, $yellow_transparent); + imagesavealpha($res, TRUE); + imagewebp($res, Settings::get('file_public_path') . '/sourceimagetest/img-test.webp'); + } + + /** * Function to compare two colors by RGBa. */ function colorsAreEqual($color_a, $color_b) { @@ -151,9 +163,6 @@ function testManipulations() { 'image-test-no-transparency.gif', 'image-test.jpg', ); - if ($image->getToolkit()->isWebpSupported()) { - $files[] = 'img-test.webp'; - } // Setup a list of tests to perform on each type. $operations = array( @@ -295,6 +304,17 @@ function testManipulations() { ); } + // Prepare a directory with source test images. + $directory = Settings::get('file_public_path') . '/sourceimagetest'; + file_prepare_directory($directory, FILE_CREATE_DIRECTORY); + foreach ($files as $file) { + file_unmanaged_copy(drupal_get_path('module', 'simpletest') . '/files/' . $file, $directory, FILE_EXISTS_RENAME); + } + if ($image->getToolkit()->isWebpSupported()) { + $this->buildWebpTestImage(); + $files[] = 'img-test.webp'; + } + // Prepare a directory for test file results. $directory = Settings::get('file_public_path') . '/imagetest'; file_prepare_directory($directory, FILE_CREATE_DIRECTORY); @@ -302,7 +322,7 @@ function testManipulations() { foreach ($files as $file) { foreach ($operations as $op => $values) { // Load up a fresh image. - $image = $this->imageFactory->get(drupal_get_path('module', 'simpletest') . '/files/' . $file); + $image = $this->imageFactory->get(Settings::get('file_public_path') . '/sourceimagetest/' . $file); $toolkit = $image->getToolkit(); if (!$image->isValid()) { $this->fail(SafeMarkup::format('Could not load image %file.', array('%file' => $file)));