diff --git a/core/modules/system/src/Tests/Theme/ImageTest.php b/core/modules/system/src/Tests/Theme/ImageTest.php index f37ef9b..5563c0f 100644 --- a/core/modules/system/src/Tests/Theme/ImageTest.php +++ b/core/modules/system/src/Tests/Theme/ImageTest.php @@ -33,14 +33,13 @@ class ImageTest extends DrupalUnitTestBase { protected function setUp() { parent::setUp(); $this->testImages = array( - DRUPAL_ROOT . '/core/misc/druplicon.png', - DRUPAL_ROOT . '/core/misc/loading.gif', - DRUPAL_ROOT . '/core/misc/loading-small.gif', + '/core/misc/druplicon.png', + '/core/misc/loading.gif', ); } /** - * Tests that an image with the src attribute is outputted correctly. + * Tests that an image with the src attribute is output correctly. */ function testThemeImageWithSrc() { @@ -49,21 +48,20 @@ function testThemeImageWithSrc() { '#uri' => reset($this->testImages), '#width' => rand(0, 1000) . 'px', '#height' => rand(0, 500) . 'px', - '#alt' => $this->randomString(), - '#title' => $this->randomString(), + '#alt' => $this->randomMachineName(), + '#title' => $this->randomMachineName(), ); $this->render($image); $this->removeWhiteSpace(); - $expected = '' . $image['#alt']
-      . ''; + $expected = '' . $image['#alt'] . ''; $this->assertRaw($expected, 'Correct output for image with src attribute.'); } /** - * Tests that an image with the srcset attribute is outputted correctly. + * Tests that an image with the srcset and multipliers is output correctly. */ - function testThemeImageWithSrcset() { + function testThemeImageWithSrcsetMultiplier() { // Test with multipliers. $image = array( '#theme' => 'image', @@ -76,23 +74,50 @@ function testThemeImageWithSrcset() { 'uri' => $this->testImages[1], 'multiplier' => '2x', ), + ), + '#width' => rand(0, 1000) . 'px', + '#height' => rand(0, 500) . 'px', + '#alt' => $this->randomMachineName(), + '#title' => $this->randomMachineName(), + ); + $this->render($image); + $this->removeWhiteSpace(); + $expected = '' . $image['#alt'] . ''; + $this->assertRaw($expected, 'Correct output for image with srcset attribute and multipliers.'); + } + + /** + * Tests that an image with the srcset and widths is output correctly. + */ + function testThemeImageWithSrcsetWidth() { + // Test with multipliers. + $widths = array( + rand(0, 500) . 'w', + rand(500, 1000) . 'w', + ); + $image = array( + '#theme' => 'image', + '#srcset' => array( array( - 'uri' => $this->testImages[2], - 'width' => '640w', + 'uri' => $this->testImages[0], + 'width' => $widths[0], + ), + array( + 'uri' => $this->testImages[1], + 'width' => $widths[1], ), ), '#width' => rand(0, 1000) . 'px', '#height' => rand(0, 500) . 'px', - '#alt' => $this->randomString(), - '#title' => $this->randomString(), + '#alt' => $this->randomMachineName(), + '#title' => $this->randomMachineName(), ); $this->render($image); $this->removeWhiteSpace(); - $expected = ''
-      . $image['#alt'] . ''; - $this->assertRaw($expected, 'Correct output for image with srcset attribute.'); + $expected = '' . $image['#alt'] . ''; + $this->assertRaw($expected, 'Correct output for image with srcset attribute and width descriptors.'); } }