View source
<?php
class LazyloaderExcludeTestCase extends LazyloaderTestBase {
public static function getInfo() {
return array(
'name' => 'Lazyloader exclude',
'description' => 'Ensure lazyloader correctly excludes/includes images from lazyloading..',
'group' => 'Lazyloader',
);
}
function testContentTypeExclude() {
$this
->drupalGet("node/{$this->node->nid}");
$this
->assertLazyloaderEnabled();
$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.');
$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.');
}
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 ');
}
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.');
}
}
}
function testImageStyleExclude() {
$this
->drupalGet("node/{$this->node->nid}");
$this
->assertLazyloaderEnabled();
$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.');
$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.');
}
}