You are here

public function ExcludeTestCase::testFilenameExclude in Image Lazyloader 8

Test functioning of the filename exclude setting.

File

src/tests/ExcludeTestCase.php, line 60

Class

ExcludeTestCase
Tests Lazyloader's exclusion functionality.

Namespace

Drupal\lazyloader\Tests

Code

public function testFilenameExclude() {
  $node = node_view($this->node);
  \Drupal::configFactory()
    ->getEditable('lazyloader.settings')
    ->set('lazyloader_excluded_filenames', $node['field_images'][0]['#item']['filename'])
    ->save();
  $this
    ->drupalGet("node/{$this->node->nid}");
  foreach (Element::children($node['field_images']) as $image) {
    $image = $node['field_images'][$image]['#item'];
    $pattern = '/data-echo=".*' . preg_quote($image['filename']) . '/';

    // @FIXME
    // Could not extract the default value because it is either indeterminate,
    // or not scalar. You'll need to provide a default value in
    // config/install/lazyloader.settings.yml and
    // config/schema/lazyloader.schema.yml.
    if ($image['filename'] !== \Drupal::config('lazyloader.settings')
      ->get('lazyloader_excluded_filenames')) {
      $this
        ->assertSession()
        ->responseMatches("{$pattern}");
      $this
        ->assertSession()
        ->responseMatches("{$pattern}", 'Image is lazyloaded when not excluded by filename.');
    }
    else {
      $this
        ->assertSession()
        ->responseNotMatches("{$pattern}", 'Image is NOT lazyloaded when excluded by filename.');
    }
  }
}