You are here

function ImageTest::testThemeImageWithSrcsetWidth in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Theme/ImageTest.php \Drupal\system\Tests\Theme\ImageTest::testThemeImageWithSrcsetWidth()

Tests that an image with the srcset and widths is output correctly.

File

core/modules/system/src/Tests/Theme/ImageTest.php, line 112
Contains \Drupal\system\Tests\Theme\ImageTest.

Class

ImageTest
Tests built-in image theme functions.

Namespace

Drupal\system\Tests\Theme

Code

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[0],
        'width' => $widths[0],
      ),
      array(
        'uri' => $this->testImages[1],
        'width' => $widths[1],
      ),
    ),
    '#width' => rand(0, 1000) . 'px',
    '#height' => rand(0, 500) . 'px',
    '#alt' => $this
      ->randomMachineName(),
    '#title' => $this
      ->randomMachineName(),
  );
  $this
    ->render($image);

  // Make sure the srcset attribute has the correct value.
  $this
    ->assertRaw(file_create_url($this->testImages[0]) . ' ' . $widths[0] . ', ' . file_create_url($this->testImages[1]) . ' ' . $widths[1], 'Correct output for image with srcset attribute and width descriptors.');
}