You are here

lazyloader_exclude.test in Image Lazyloader 7.2

File

tests/lazyloader_exclude.test
View source
<?php

/**
 * Tests Lazyloader's exclusion functionality.
 */
class LazyloaderExcludeTestCase extends LazyloaderTestBase {
  public static function getInfo() {
    return array(
      'name' => 'Lazyloader exclude',
      'description' => 'Ensure lazyloader correctly excludes/includes images from lazyloading..',
      'group' => 'Lazyloader',
    );
  }

  /**
   * Tests functioning of the content type exclude settings.
   */
  function testContentTypeExclude() {

    // Test default rendering of a node.
    $this
      ->drupalGet("node/{$this->node->nid}");
    $this
      ->assertLazyloaderEnabled();

    // Test rendering with content type exclusion enabled.
    $edit['lazyloader_content_types[article]'] = 'article';
    $this
      ->drupalPost("admin/config/media/lazyloader/exclude", $edit, t('Save configuration'));
    $this
      ->drupalGet("node/{$this->node->nid}");
    $this
      ->assertLazyloaderEnabled(FALSE, 'Lazyloader is disabled for page nodes when limited to article content types.');

    // Test rendering when the page type is supposed to be rendered.
    $edit['lazyloader_content_types[article]'] = FALSE;
    $edit['lazyloader_content_types[page]'] = 'page';
    $this
      ->drupalPost("admin/config/media/lazyloader/exclude", $edit, t('Save configuration'));
    $this
      ->drupalGet("node/{$this->node->nid}");
    $this
      ->assertLazyloaderEnabled(TRUE, 'Lazyloader is enabled for page nodes when limited to page content types.');
  }

  /**
   * Test functioning of the path exclude setting.
   */
  function testPathExclude() {
    $alias = $this->node->path['alias'];
    $this
      ->drupalGet($alias);
    $this
      ->assertLazyloaderEnabled();
    $edit['lazyloader_paths'] = $alias;
    $this
      ->drupalPost("admin/config/media/lazyloader/exclude", $edit, t('Save configuration'));
    $this
      ->drupalGet($alias);
    $this
      ->assertLazyloaderEnabled(FALSE, 'Lazyloader disabled for disabled alias');
    $edit['lazyloader_paths'] = '*' . substr($alias, 2, 2) . '*';
    $this
      ->drupalPost("admin/config/media/lazyloader/exclude", $edit, t('Save configuration'));
    $this
      ->drupalGet($alias);
    $this
      ->assertLazyloaderEnabled(FALSE, 'Lazyloader disabled for disabled alias with wildcards');
    $this
      ->drupalGet("node/{$this->node->nid}");
    $this
      ->assertLazyloaderEnabled(FALSE, 'Lazyloader is also disabled on internal path if alias with wildcard matches ');
  }

  /**
   * Test functioning of the filename exclude setting.
   */
  function testFilenameExclude() {
    $node = node_view($this->node);
    variable_set('lazyloader_excluded_filenames', $node['field_images'][0]['#item']['filename']);
    $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']) . '/';
      if ($image['filename'] !== variable_get('lazyloader_excluded_filenames')) {
        $this
          ->assertPattern("{$pattern}");
        $this
          ->assertPattern("{$pattern}", 'Image is lazyloaded when not excluded by filename.');
      }
      else {
        $this
          ->assertNoPattern("{$pattern}", 'Image is NOT lazyloaded when excluded by filename.');
      }
    }
  }

  /**
   * Test functioning of the image style exclude setting.
   */
  function testImageStyleExclude() {

    // Test default rendering of a node.
    $this
      ->drupalGet("node/{$this->node->nid}");
    $this
      ->assertLazyloaderEnabled();

    // Enable exclusion option, but don't disable the current image style.
    $edit['lazyloader_image_styles[medium]'] = 'medium';
    $this
      ->drupalPost("admin/config/media/lazyloader/exclude", $edit, t('Save configuration'));
    $this
      ->drupalGet("node/{$this->node->nid}");
    $this
      ->assertLazyloaderEnabled(TRUE, 'Lazyloader is enabled for <em>medium</em> image style.');

    // Enable exclusion option, now excluding the current image style.
    $edit['lazyloader_image_styles[medium]'] = FALSE;
    $edit['lazyloader_image_styles[large]'] = 'large';
    $this
      ->drupalPost("admin/config/media/lazyloader/exclude", $edit, t('Save configuration'));
    $this
      ->drupalGet("node/{$this->node->nid}");
    $this
      ->assertLazyloaderEnabled(FALSE, 'Lazyloader is disabled for <em>medium</em> image style.');

    // @todo test that image style exclusion only affects images using an image
    // style.
  }

}

Classes

Namesort descending Description
LazyloaderExcludeTestCase Tests Lazyloader's exclusion functionality.