You are here

public function ImageTest::testThemeImageWithSizes in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php \Drupal\KernelTests\Core\Theme\ImageTest::testThemeImageWithSizes()

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

File

core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php, line 48

Class

ImageTest
Tests built-in image theme functions.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function testThemeImageWithSizes() {

  // Test with multipliers.
  $sizes = '(max-width: ' . rand(10, 30) . 'em) 100vw, (max-width: ' . rand(30, 50) . 'em) 50vw, 30vw';
  $image = [
    '#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.');
}