Issue #3167034: Adding simple test coverage

merge-requests/25/head
Edys Meza 2020-09-01 15:52:47 -06:00
parent 30baa59dec
commit fd22a525cd
4 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,5 @@
name: 'Image lazy load'
type: module
description: 'Support module for image loading attribute tests.'
package: Testing
version: VERSION

View File

@ -0,0 +1,6 @@
image_lazy_load_test:
path: /image-lazy-load-test
defaults:
_controller: Drupal\image_lazy_load_test\Controller\ImageLazyLoadController::renderImage
requirements:
_access: 'TRUE'

View File

@ -0,0 +1,28 @@
<?php
namespace Drupal\image_lazy_load_test\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* The ImageLazyLoadController class.
*/
class ImageLazyLoadController extends ControllerBase {
/**
* Render an image using image theme.
*
* @return array
* The render array.
*/
public function renderImage() {
return [
'#theme' => 'image',
'#uri' => '/core/themes/bartik/logo.svg',
'#alt' => 'Image lazy load testing image',
'#width' => '50%',
'#height' => '50%',
];
}
}

View File

@ -0,0 +1,34 @@
<?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() {
$this->drupalGet('image-lazy-load-test');
$this->assertSession()->responseContains('loading="lazy"');
}
}