function ImageTest::testThemeImageWithSrcsetMultiplier

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php \Drupal\KernelTests\Core\Theme\ImageTest::testThemeImageWithSrcsetMultiplier()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php \Drupal\KernelTests\Core\Theme\ImageTest::testThemeImageWithSrcsetMultiplier()
  3. 10 core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php \Drupal\KernelTests\Core\Theme\ImageTest::testThemeImageWithSrcsetMultiplier()

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

File

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

Class

ImageTest
Tests built-in image theme functions.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function testThemeImageWithSrcsetMultiplier() : void {
    // Test with multipliers.
    $image = [
        '#theme' => 'image',
        '#srcset' => [
            [
                'uri' => $this->testImages[0],
                'multiplier' => '1x',
            ],
            [
                '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);
    // Make sure the srcset attribute has the correct value.
    $this->assertRaw($this->fileUrlGenerator
        ->transformRelative($this->fileUrlGenerator
        ->generateString($this->testImages[0])) . ' 1x, ' . $this->fileUrlGenerator
        ->transformRelative($this->fileUrlGenerator
        ->generateString($this->testImages[1])) . ' 2x', 'Correct output for image with srcset attribute and multipliers.');
}

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