function ImageTest::testThemeImageWithSizes

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php \Drupal\KernelTests\Core\Theme\ImageTest::testThemeImageWithSizes()
  2. 10 core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php \Drupal\KernelTests\Core\Theme\ImageTest::testThemeImageWithSizes()
  3. 11.x 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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.