class ImageLoadingAttributeTest
Same name in this branch
- 11.x core/modules/system/tests/src/Functional/Theme/ImageLoadingAttributeTest.php \Drupal\Tests\system\Functional\Theme\ImageLoadingAttributeTest
Same name and namespace in other branches
- 10 core/modules/system/tests/src/Functional/Theme/ImageLoadingAttributeTest.php \Drupal\Tests\system\Functional\Theme\ImageLoadingAttributeTest
- 9 core/modules/system/tests/src/Functional/Theme/ImageLoadingAttributeTest.php \Drupal\Tests\system\Functional\Theme\ImageLoadingAttributeTest
- main core/modules/system/tests/src/Functional/Theme/ImageLoadingAttributeTest.php \Drupal\Tests\system\Functional\Theme\ImageLoadingAttributeTest
- main core/modules/system/tests/src/Kernel/Theme/ImageLoadingAttributeTest.php \Drupal\Tests\system\Kernel\Theme\ImageLoadingAttributeTest
Tests lazy loading for images.
Attributes
#[Group('Theme')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\BrowserHtmlDebugTrait, \Drupal\Tests\HttpKernelUiHelperTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Kernel\Theme\ImageLoadingAttributeTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of ImageLoadingAttributeTest
File
-
core/
modules/ system/ tests/ src/ Kernel/ Theme/ ImageLoadingAttributeTest.php, line 14
Namespace
Drupal\Tests\system\Kernel\ThemeView source
class ImageLoadingAttributeTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'image_lazy_load_test',
];
/**
* Tests that loading attribute is enabled for images.
*/
public function testImageLoadingAttribute() : void {
$assert = $this->assertSession();
// Get page under test.
$this->drupalGet('image-lazy-load-test');
// Loading attribute is added when image dimensions has been set.
$assert->elementAttributeExists('css', '#with-dimensions img', 'loading');
$assert->elementAttributeContains('css', '#with-dimensions img', 'loading', 'lazy');
// Loading attribute with lazy default value can be overridden.
$assert->elementAttributeContains('css', '#override-loading-attribute img', 'loading', 'eager');
// Without image dimensions loading attribute is not generated.
$element = $assert->elementExists('css', '#without-dimensions img');
$this->assertFalse($element->hasAttribute('loading'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.