diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php index 89eb44b..2c6a2e4 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -343,11 +343,10 @@ function testImageFieldDefaultImage() { // Add a default image to the public image field. $images = $this->drupalGetTestFiles('image'); - // $images[0] = image-test.png - // $images[2] = image-test.gif $alt = $this->randomString(512); $title = $this->randomString(1024); $edit = array( + // Get the path of the 'image-test.png' file. 'files[settings_default_image_uuid]' => drupal_realpath($images[0]->uri), 'settings[default_image][alt]' => $alt, 'settings[default_image][title]' => $title, @@ -380,6 +379,7 @@ function testImageFieldDefaultImage() { // Create alt text for the image. $alt = $this->randomMachineName(); + // Upload the 'image-test.gif' file. $nid = $this->uploadNodeImage($images[2], $field_name, 'article', $alt); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); @@ -415,6 +415,7 @@ function testImageFieldDefaultImage() { $this->createImageField($private_field_name, 'article', array('uri_scheme' => 'private')); // Add a default image to the new field. $edit = array( + // Get the path of the 'image-test.gif' file. 'files[settings_default_image_uuid]' => drupal_realpath($images[2]->uri), 'settings[default_image][alt]' => $alt, 'settings[default_image][title]' => $title, diff --git a/core/modules/system/src/Tests/Image/ToolkitGdTest.php b/core/modules/system/src/Tests/Image/ToolkitGdTest.php index cc328f7..5ea777f 100644 --- a/core/modules/system/src/Tests/Image/ToolkitGdTest.php +++ b/core/modules/system/src/Tests/Image/ToolkitGdTest.php @@ -26,13 +26,6 @@ class ToolkitGdTest extends KernelTestBase { */ protected $imageFactory; - /** - * A directory for saving processed test image files. - * - * @var string - */ - protected $directory; - // Colors that are used in testing. protected $black = array(0, 0, 0, 0); protected $red = array(255, 0, 0, 0); @@ -41,9 +34,9 @@ class ToolkitGdTest extends KernelTestBase { protected $yellow = array(255, 255, 0, 0); protected $white = array(255, 255, 255, 0); protected $transparent = array(0, 0, 0, 127); - protected $whiteTransparent = array(255, 255, 255, 127); // Used as rotate background colors. protected $fuchsia = array(255, 0, 255, 0); + protected $rotateTransparent = array(255, 255, 255, 127); protected $width = 40; protected $height = 20; @@ -63,10 +56,6 @@ protected function setUp() { // Set the image factory service. $this->imageFactory = $this->container->get('image.factory'); - - // Prepare a directory for test file results. - $this->directory = $this->publicFilesDirectory .'/imagetest'; - file_prepare_directory($this->directory, FILE_CREATE_DIRECTORY); } protected function checkRequirements() { @@ -230,7 +219,7 @@ function testManipulations() { 'arguments' => array('degrees' => 5), 'width' => 42, 'height' => 24, - 'corners' => array_fill(0, 4, $this->whiteTransparent), + 'corners' => array_fill(0, 4, $this->rotateTransparent), ), 'rotate_transparent_90' => array( 'function' => 'rotate', @@ -263,6 +252,10 @@ function testManipulations() { ); } + // Prepare a directory for test file results. + $directory = $this->publicFilesDirectory .'/imagetest'; + file_prepare_directory($directory, FILE_CREATE_DIRECTORY); + foreach ($files as $file) { foreach ($operations as $op => $values) { // Load up a fresh image. @@ -319,7 +312,7 @@ function testManipulations() { $correct_dimensions_object = FALSE; } - $file_path = $this->directory . '/' . $op . image_type_to_extension($image->getToolkit()->getType()); + $file_path = $directory . '/' . $op . image_type_to_extension($image->getToolkit()->getType()); $image->save($file_path); $this->assertTrue($correct_dimensions_real, SafeMarkup::format('Image %file after %action action has proper dimensions.', array('%file' => $file, '%action' => $op))); @@ -386,7 +379,7 @@ function testManipulations() { $image = $this->imageFactory->get(); $image->createNew(50, 20, image_type_to_extension($type, FALSE), '#ffff00'); $file = 'from_null' . image_type_to_extension($type); - $file_path = $this->directory . '/' . $file ; + $file_path = $directory . '/' . $file ; $this->assertEqual(50, $image->getWidth(), SafeMarkup::format('Image file %file has the correct width.', array('%file' => $file))); $this->assertEqual(20, $image->getHeight(), SafeMarkup::format('Image file %file has the correct height.', array('%file' => $file))); $this->assertEqual(image_type_to_mime_type($type), $image->getMimeType(), SafeMarkup::format('Image file %file has the correct MIME type.', array('%file' => $file))); @@ -449,6 +442,10 @@ public function testResourceDestruction() { * Tests for GIF images with transparency. */ function testGifTransparentImages() { + // Prepare a directory for test file results. + $directory = $this->publicFilesDirectory .'/imagetest'; + file_prepare_directory($directory, FILE_CREATE_DIRECTORY); + // Test loading an indexed GIF image with transparent color set. // Color at top-right pixel should be fully transparent. $file = 'image-test-transparent-indexed.gif'; @@ -456,22 +453,22 @@ function testGifTransparentImages() { $resource = $image->getToolkit()->getResource(); $color_index = imagecolorat($resource, $image->getWidth() - 1, 0); $color = array_values(imagecolorsforindex($resource, $color_index)); - $this->assertEqual($this->whiteTransparent, $color, SafeMarkup::format('Image %file after load has full transparent color at corner 1.', array('%file' => $file))); + $this->assertEqual($this->rotateTransparent, $color, "Image {$file} after load has full transparent color at corner 1."); // Test deliberately creating a GIF image with no transparent color set. // Color at top-right pixel should be fully transparent while in memory, // fully opaque after flushing image to file. $file = 'image-test-no-transparent-color-set.gif'; - $file_path = $this->directory . '/' . $file ; + $file_path = $directory . '/' . $file ; // Create image. $image = $this->imageFactory->get(); $image->createNew(50, 20, 'gif', NULL); $resource = $image->getToolkit()->getResource(); $color_index = imagecolorat($resource, $image->getWidth() - 1, 0); $color = array_values(imagecolorsforindex($resource, $color_index)); - $this->assertEqual($this->whiteTransparent, $color, 'New GIF image with no transparent color set after creation has full transparent color at corner 1.'); + $this->assertEqual($this->whiteTransparent, $color, "New GIF image with no transparent color set after creation has full transparent color at corner 1."); // Save image. - $this->assertTrue($image->save($file_path), SafeMarkup::format('New GIF image %file was saved.', array('%file' => $file))); + $this->assertTrue($image->save($file_path), "New GIF image {$file} was saved."); // Reload image. $image_reloaded = $this->imageFactory->get($file_path); $resource = $image_reloaded->getToolkit()->getResource(); @@ -479,7 +476,7 @@ function testGifTransparentImages() { $color = array_values(imagecolorsforindex($resource, $color_index)); // Check explicitly for alpha == 0 as the rest of the color has been // compressed and may have slight difference from full white. - $this->assertEqual(0, $color[3], SafeMarkup::format('New GIF image %file after reload has no transparent color at corner 1.', array('%file' => $file))); + $this->assertEqual(0, $color[3], "New GIF image {$file} after reload has no transparent color at corner 1."); // Test loading an image whose transparent color index is out of range. // This image was generated by taking an initial image with a palette size