You are here

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

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

File

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

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.
  $this
    ->assertRaw(file_url_transform_relative(file_create_url($image['#uri'])), 'Correct output for an image with the src attribute.');
}