You are here

public function BlazyManagerTest::testPreRenderImage in Blazy 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/BlazyManagerTest.php \Drupal\Tests\blazy\Kernel\BlazyManagerTest::testPreRenderImage()

Tests BlazyManager image.

@covers ::preRenderImage @covers ::getResponsiveImageCacheTags @covers \Drupal\blazy\BlazyLightbox::build @covers \Drupal\blazy\BlazyLightbox::buildCaptions @dataProvider providerTestPreRenderImage

Parameters

array $settings: The settings being tested.

string $expected_responsive_image_style_id: The responsive image style ID.

File

tests/src/Kernel/BlazyManagerTest.php, line 48

Class

BlazyManagerTest
Tests the Blazy manager methods.

Namespace

Drupal\Tests\blazy\Kernel

Code

public function testPreRenderImage(array $settings = [], $expected_responsive_image_style_id = '') {
  $build = $this->data;
  $settings['count'] = $this->maxItems;
  $settings['uri'] = $this->uri;
  $settings['responsive_image_style_id'] = '';
  $settings['resimage'] = empty($settings['responsive_image_style']) ? FALSE : $this->blazyManager
    ->entityLoad($settings['responsive_image_style'], 'responsive_image_style');
  $build['settings'] = array_merge($build['settings'], $settings) + BlazyDefault::itemSettings();
  $switch_css = str_replace('_', '-', $settings['media_switch']);
  $element = $this
    ->doPreRenderImage($build);
  if ($settings['media_switch'] == 'content') {
    $this
      ->assertEquals($settings['content_url'], $element['#url']);
    $this
      ->assertArrayHasKey('#url', $element);
  }
  else {
    $this
      ->assertArrayHasKey('data-' . $switch_css . '-trigger', $element['#url_attributes']);
    $this
      ->assertArrayHasKey('#url', $element);
  }
  $this
    ->assertEquals($expected_responsive_image_style_id, $element['#settings']['responsive_image_style_id']);
}