diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php index 2d8544e..5a34571 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php @@ -221,7 +221,7 @@ public function getInfo(ImageInterface $image) { $data = getimagesize($image->getSource()); if (isset($data) && is_array($data)) { - // image_type_to_extension(IMAGETYPE_JPEG) always returns 'jpeg' event if + // image_type_to_extension(IMAGETYPE_JPEG) always returns 'jpeg' even if // the extension is 'jpg'. Extract the extension from the filename. if ($data[2] == IMAGETYPE_JPEG) { $extension = pathinfo($image->getSource(), PATHINFO_EXTENSION); @@ -230,7 +230,7 @@ public function getInfo(ImageInterface $image) { } else { $extension = image_type_to_extension($data[2], FALSE); - $extension = in_array($extension, self::getAvailableExtensions()) ? $extension : ''; + $extension = in_array($extension, static::getAvailableExtensions()) ? $extension : ''; } $details = array( 'width' => $data[0], diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php index 3fa69db..8681b27 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php @@ -50,14 +50,14 @@ * * @see system_image_toolkit_settings() */ - function settingsForm(); + public function settingsForm(); /** * Handles submissions for toolkit's settings form. * * @see system_image_toolkit_settings_submit() */ - function settingsFormSubmit($form, &$form_state); + public function settingsFormSubmit($form, &$form_state); /** * Scales an image to the specified size. @@ -73,7 +73,7 @@ function settingsFormSubmit($form, &$form_state); * @return bool * TRUE or FALSE, based on success. */ - function resize(ImageInterface $image, $width, $height); + public function resize(ImageInterface $image, $width, $height); /** * Rotates an image the given number of degrees. @@ -93,7 +93,7 @@ function resize(ImageInterface $image, $width, $height); * @return bool * TRUE or FALSE, based on success. */ - function rotate(ImageInterface $image, $degrees, $background = NULL); + public function rotate(ImageInterface $image, $degrees, $background = NULL); /** * Crops an image. @@ -115,7 +115,7 @@ function rotate(ImageInterface $image, $degrees, $background = NULL); * * @see image_crop() */ - function crop(ImageInterface $image, $x, $y, $width, $height); + public function crop(ImageInterface $image, $x, $y, $width, $height); /** * Converts an image resource to grayscale. @@ -140,7 +140,7 @@ function desaturate(ImageInterface $image); * @return bool * TRUE or FALSE, based on success. */ - function load(ImageInterface $image); + public function load(ImageInterface $image); /** * Writes an image resource to a destination file. @@ -153,7 +153,7 @@ function load(ImageInterface $image); * @return bool * TRUE or FALSE, based on success. */ - function save(ImageInterface $image, $destination); + public function save(ImageInterface $image, $destination); /** * Gets details about an image. @@ -179,7 +179,7 @@ function getInfo(ImageInterface $image); * @return bool * True if the GD toolkit is available on this machine. */ - static function isAvailable(); + public static function isAvailable(); /** * Returns a list of image extensions handled by the image toolkit. @@ -187,6 +187,6 @@ static function isAvailable(); * @return array * A array of available image extensions. */ - static function getAvailableExtensions(); + public static function getAvailableExtensions(); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php index 6917942..fa08dec 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php @@ -293,6 +293,33 @@ function testManipulations() { } } } + } + + /** + * Test allowed extensions. + */ + public function testExtensions() { + $toolkit = $this->container->get('image.toolkit.manager')->createInstance('gd'); + $image_factory = $this->container->get('image.factory')->setToolkit($toolkit); + // Define a list of files to be tested. + $files = array(); + foreach (array('png', 'gif', 'jpg') as $extension) { + $files[$extension] = drupal_get_path('module', 'simpletest') . '/files/image-test.' . $extension; + } + + // Add also a .jpeg extension file and a JPEG file without any extension. + foreach (array('jpeg', '') as $extension) { + $destination = 'public://image-test' . (empty($extension) ? '' : '.') . $extension; + file_unmanaged_copy($files['jpg'], $destination); + $files[$extension] = $destination; + } + + foreach ($files as $extension => $file) { + $image = $image_factory->get($file); + $expected = $extension ?: 'jpg'; + $this->assertEqual($image->getExtension(), $expected); + } } + } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php index 762288c..becf16b 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php @@ -46,7 +46,7 @@ public function getInfo(ImageInterface $image) { $data = getimagesize($image->getSource()); if (isset($data) && is_array($data)) { - // image_type_to_extension(IMAGETYPE_JPEG) always returns 'jpeg' event if + // image_type_to_extension(IMAGETYPE_JPEG) always returns 'jpeg' even if // the extension is 'jpg'. Extract the extension from the filename. if ($data[2] == IMAGETYPE_JPEG) { $extension = pathinfo($image->getSource(), PATHINFO_EXTENSION);