You are here

public function BlazyManagerTest::testPreRenderImage in Blazy 8.2

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

Tests BlazyManager image.

@covers ::preRenderBlazy @covers \Drupal\blazy\BlazyLightbox::build @covers \Drupal\blazy\BlazyLightbox::buildCaptions @dataProvider providerTestPreRenderImage

Parameters

array $settings: The settings being tested.

bool $expected_has_responsive_image: Has the responsive image style ID.

File

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

Class

BlazyManagerTest
Tests the Blazy manager methods.

Namespace

Drupal\Tests\blazy\Kernel

Code

public function testPreRenderImage(array $settings = [], $expected_has_responsive_image = FALSE) {
  $build = $this->data;
  $settings['count'] = $this->maxItems;
  $settings['uri'] = $this->uri;
  $settings['resimage'] = $expected_has_responsive_image ? $this->blazyManager
    ->entityLoad('blazy_responsive_test', 'responsive_image_style') : NULL;
  $build['settings'] = array_merge($build['settings'], $settings);
  $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_has_responsive_image, !empty($element['#settings']['responsive_image_style_id']));
}