public function BlazyUnitTest::testBuildAttributes in Blazy 8
Tests building Blazy attributes.
@covers \Drupal\blazy\Blazy::buildAttributes @covers \Drupal\blazy\Blazy::buildBreakpointAttributes @covers \Drupal\blazy\Blazy::buildUrl @covers \Drupal\blazy\Dejavu\BlazyDefault::entitySettings @dataProvider providerBuildAttributes
Parameters
array $settings: The settings being tested.
bool $expected_image: Whether to expect an image, or not.
bool $expected_iframe: Whether to expect an iframe, or not.
File
- tests/
src/ Unit/ BlazyUnitTest.php, line 131
Class
- BlazyUnitTest
- @coversDefaultClass \Drupal\blazy\Blazy
Namespace
Drupal\Tests\blazy\UnitCode
public function testBuildAttributes(array $settings, $expected_image, $expected_iframe) {
$variables = [
'attributes' => [],
];
$build = $this->data;
$settings = array_merge($build['settings'], $settings) + BlazyDefault::itemSettings();
$settings['breakpoints'] = [];
$settings['blazy'] = TRUE;
$settings['lazy'] = 'blazy';
$settings['image_style'] = '';
$settings['thumbnail_style'] = '';
if (!empty($settings['embed_url'])) {
$settings = array_merge(BlazyDefault::entitySettings(), $settings);
}
$variables['element']['#item'] = $this->testItem;
$variables['element']['#settings'] = $settings;
Blazy::buildAttributes($variables);
$image = $expected_image == TRUE ? !empty($variables['image']) : empty($variables['image']);
$iframe = $expected_iframe == TRUE ? !empty($variables['iframe_attributes']) : empty($variables['iframe_attributes']);
$this
->assertTrue($image);
$this
->assertTrue($iframe);
$this
->assertEquals($settings['blazy'], $variables['settings']['blazy']);
}