
| Current Path : /var/www/html1/bbp/web/core/modules/system/tests/src/Functional/Theme/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html1/bbp/web/core/modules/system/tests/src/Functional/Theme/ImageLoadingAttributeTest.php |
<?php
namespace Drupal\Tests\system\Functional\Theme;
use Drupal\Tests\BrowserTestBase;
/**
* Tests lazy loading for images.
*
* @group Theme
*/
class ImageLoadingAttributeTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = ['image_lazy_load_test'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that loading attribute is enabled for images.
*/
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'));
}
}