reverted: --- b/core/modules/image/src/Entity/ImageStyle.php +++ a/core/modules/image/src/Entity/ImageStyle.php @@ -307,15 +307,6 @@ /** * {@inheritdoc} */ - public function transformMimeType(&$mime_type) { - foreach ($this->getEffects() as $effect) { - $effect->transformMimeType($mime_type); - } - } - - /** - * {@inheritdoc} - */ public function getPathToken($uri) { // Return the first 8 characters. return substr(Crypt::hmacBase64($this->id() . ':' . $uri, \Drupal::service('private_key')->get() . Settings::getHashSalt()), 0, 8); @@ -342,7 +333,7 @@ */ public function getEffects() { if (!$this->effectsBag) { + $this->effectsBag = new ImageEffectBag(\Drupal::service('plugin.manager.image.effect'), $this->effects); - $this->effectsBag = new ImageEffectBag($this->getImageEffectPluginManager(), $this->effects); $this->effectsBag->sort(); } return $this->effectsBag; @@ -386,11 +377,4 @@ return $this; } - /** - * {@inheritdoc} - */ - public function getImageEffectPluginManager() { - return \Drupal::service('plugin.manager.image.effect'); - } - } reverted: --- b/core/modules/image/src/ImageEffectBase.php +++ a/core/modules/image/src/ImageEffectBase.php @@ -77,12 +77,6 @@ /** * {@inheritdoc} */ - public function transformMimeType(&$mime_type) { - } - - /** - * {@inheritdoc} - */ public function getSummary() { return array( '#markup' => '', reverted: --- b/core/modules/image/src/ImageEffectInterface.php +++ a/core/modules/image/src/ImageEffectInterface.php @@ -44,14 +44,6 @@ public function transformDimensions(array &$dimensions); /** - * Determines the MIME type of the image effect. - * - * @param string $mime_type - * The MIME type to be modified. - */ - public function transformMimeType(&$mime_type); - - /** * Returns a render array summarizing the configuration of the image effect. * * @return array reverted: --- b/core/modules/image/src/ImageStyleInterface.php +++ a/core/modules/image/src/ImageStyleInterface.php @@ -131,14 +131,6 @@ public function transformDimensions(array &$dimensions); /** - * Determines the MIME type of the image style. - * - * @param string $mime_type - * The MIME type to be modified. - */ - public function transformMimeType(&$mime_type); - - /** * Returns a specific image effect. * * @param string $effect @@ -178,12 +170,4 @@ */ public function deleteImageEffect(ImageEffectInterface $effect); - /** - * Returns the image effect plugin manager. - * - * @return \Drupal\Component\Plugin\PluginManagerInterface - * The image effect plugin manager. - */ - public function getImageEffectPluginManager(); - } reverted: --- b/core/modules/image/src/Tests/ImageStyleTest.php +++ /dev/null @@ -1,111 +0,0 @@ -entityTypeId = $this->randomMachineName(); - $this->provider = $this->randomMachineName(); - $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); - $this->entityType->expects($this->any()) - ->method('getProvider') - ->will($this->returnValue($this->provider)); - $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); - $this->entityManager->expects($this->any()) - ->method('getDefinition') - ->with($this->entityTypeId) - ->will($this->returnValue($this->entityType)); - $this->effectManager = $this->getMockBuilder('\Drupal\image\ImageEffectManager') - ->disableOriginalConstructor() - ->getMock(); - } - - /** - * @covers ::transformMimeType - */ - public function testTransformMimeType() { - $image_effect_id = $this->randomMachineName(); - $logger = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock(); - $image_effect = $this->getMockBuilder('\Drupal\image\ImageEffectBase') - ->setConstructorArgs(array(array(), $image_effect_id, array(), $logger)) - ->getMock(); - $image_effect->expects($this->any()) - ->method('transformMimeType') - ->will($this->returnCallback(function (&$mime_type) { $mime_type = 'image/webp';})); - - $this->effectManager->expects($this->any()) - ->method('createInstance') - ->with($image_effect_id) - ->will($this->returnValue($image_effect)); - - $image_style = $this->getMockBuilder('\Drupal\image\Entity\ImageStyle') - ->setConstructorArgs(array( - array('effects' => array($image_effect_id => array('id' => $image_effect_id))), - $this->entityTypeId, - )) - ->setMethods(array('getImageEffectPluginManager')) - ->getMock(); - $image_style->expects($this->any()) - ->method('getImageEffectPluginManager') - ->will($this->returnValue($this->effectManager)); - - $mime_types = array('image/jpeg', 'image/gif', 'image/png'); - foreach ($mime_types as $mime_type) { - $image_style->transformMimeType($mime_type); - $this->assertEquals($mime_type, 'image/webp'); - } - } - -} only in patch2: unchanged: --- /dev/null +++ b/core/modules/system/src/Tests/Theme/ImageTest.php @@ -0,0 +1,98 @@ +testImages = array( + DRUPAL_ROOT . '/core/misc/druplicon.png', + DRUPAL_ROOT . '/core/misc/loading.gif', + DRUPAL_ROOT . '/core/misc/loading-small.gif', + ); + } + + /** + * Tests that an image with the src attribute is outputted correctly. + */ + function testThemeImageWithSrc() { + + $image = array( + '#theme' => 'image', + '#uri' => reset($this->testImages), + '#width' => rand(0, 1000) . 'px', + '#height' => rand(0, 500) . 'px', + '#alt' => $this->randomString(), + '#title' => $this->randomString(), + ); + $this->render($image); + $this->removeWhiteSpace(); + $expected = '' . $image['#alt']
+      . ''; + $this->assertRaw($expected, 'Correct output for image with src attribute.'); + } + + /** + * Tests that an image with the srcset attribute is outputted correctly. + */ + function testThemeImageWithSrcset() { + // Test with multipliers. + $image = array( + '#theme' => 'image', + '#srcset' => array( + array( + 'uri' => $this->testImages[0], + 'multiplier' => '1x', + ), + array( + 'uri' => $this->testImages[1], + 'multiplier' => '2x', + ), + array( + 'uri' => $this->testImages[2], + 'width' => '640w', + ), + ), + '#width' => rand(0, 1000) . 'px', + '#height' => rand(0, 500) . 'px', + '#alt' => $this->randomString(), + '#title' => $this->randomString(), + ); + $this->render($image); + $this->removeWhiteSpace(); + $expected = ''
+      . $image['#alt'] . ''; + $this->assertRaw($expected, 'Correct output for image with srcset attribute.'); + } + +}