You are here

public function ImageTest::testThemeImageWithSrc in Drupal 9

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

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

File

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

Class

ImageTest
Tests built-in image theme functions.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function testThemeImageWithSrc() {
  $image = [
    '#theme' => 'image',
    '#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 the src attribute has the correct value.

  /** @var \Drupal\Core\File\FileUrlGeneratorInterface $this->fileUrlGenerator */
  $this->fileUrlGenerator = $this->fileUrlGenerator;
  $this
    ->assertRaw($this->fileUrlGenerator
    ->generateString($image['#uri']), 'Correct output for an image with the src attribute.');
}