You are here

public function ThemeTest::testThemeLazyloaderImage in Image Lazyloader 8

Tests theme_lazyloader_image() and lazyloader's override of theme_image().

File

tests/src/Kernel/ThemeTest.php, line 291

Class

ThemeTest
Tests Lazyloaders theme integration.

Namespace

Drupal\Tests\lazyloader\Kernel

Code

public function testThemeLazyloaderImage() {
  $request = Request::create('/');
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_NAME, '<front>');
  \Drupal::requestStack()
    ->push($request);

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  $image = $this->node->field_images;
  $path = file_url_transform_relative(file_create_url($image->entity->uri->value));
  \Drupal::configFactory()
    ->getEditable('lazyloader.configuration')
    ->set('enabled', TRUE)
    ->save();
  $render_array = [
    '#uri' => $image->entity->uri->value,
    '#theme' => 'image',
  ];
  $result = $renderer
    ->renderPlain($render_array);
  $this
    ->setRawContent($result);
  $images = $this
    ->cssSelect('img');
  $main_image = $images[0];
  $this
    ->assertEquals('data:image/gif;base64,R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==', (string) $main_image['src']);
  $fallback_image = $images[1];
  $this
    ->assertEquals($path, (string) $fallback_image['src']);
}