You are here

function ImageTest::testThemeImageWithSizes 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::testThemeImageWithSizes()

Tests that an image with the sizes attribute is output correctly.

File

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

Class

ImageTest
Tests built-in image theme functions.

Namespace

Drupal\system\Tests\Theme

Code

function testThemeImageWithSizes() {

  // Test with multipliers.
  $sizes = '(max-width: ' . rand(10, 30) . 'em) 100vw, (max-width: ' . rand(30, 50) . 'em) 50vw, 30vw';
  $image = array(
    '#theme' => 'image',
    '#sizes' => $sizes,
    '#uri' => reset($this->testImages),
    '#width' => rand(0, 1000) . 'px',
    '#height' => rand(0, 500) . 'px',
    '#alt' => $this
      ->randomMachineName(),
    '#title' => $this
      ->randomMachineName(),
  );
  $this
    ->render($image);

  // Make sure sizes is set.
  $this
    ->assertRaw($sizes, 'Sizes is set correctly.');
}