public function ImageLoadingAttributeTest::testImageLoadingAttribute in Drupal 10
Same name and namespace in other branches
- 9 core/modules/system/tests/src/Functional/Theme/ImageLoadingAttributeTest.php \Drupal\Tests\system\Functional\Theme\ImageLoadingAttributeTest::testImageLoadingAttribute()
Tests that loading attribute is enabled for images.
File
- core/
modules/ system/ tests/ src/ Functional/ Theme/ ImageLoadingAttributeTest.php, line 29
Class
- ImageLoadingAttributeTest
- Tests lazy loading for images.
Namespace
Drupal\Tests\system\Functional\ThemeCode
public function testImageLoadingAttribute() {
$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'));
}