You are here

public function BlazyUnitTest::testPreRenderImageLightbox in Blazy 8

Tests BlazyManager image with lightbox support.

This is here as we need file_create_url() for both Blazy and its lightbox.

@covers \Drupal\blazy\BlazyManager::preRenderImage @covers \Drupal\blazy\BlazyLightbox::build @covers \Drupal\blazy\BlazyLightbox::buildCaptions @dataProvider providerTestPreRenderImageLightbox

Parameters

array $settings: The settings being tested.

File

tests/src/Unit/BlazyUnitTest.php, line 234

Class

BlazyUnitTest
@coversDefaultClass \Drupal\blazy\Blazy

Namespace

Drupal\Tests\blazy\Unit

Code

public function testPreRenderImageLightbox(array $settings = []) {
  $build = $this->data;
  $settings += BlazyDefault::itemSettings();
  $settings['count'] = $this->maxItems;
  $settings['uri'] = $this->uri;
  $settings['box_style'] = '';
  $settings['box_media_style'] = '';
  $build['settings'] = array_merge($build['settings'], $settings);
  $switch_css = str_replace('_', '-', $settings['media_switch']);
  foreach ([
    'caption',
    'media',
    'wrapper',
  ] as $key) {
    $build['settings'][$key . '_attributes']['class'][] = $key . '-test';
  }
  $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);
  }
}