public function SvgFormatterTest::testImageSizeAttributes in SVG Formatter 8
Tests image size attributes.
File
- tests/
src/ Functional/ SvgFormatterTest.php, line 363
Class
- SvgFormatterTest
- Simple test to ensure that basic functionality of the module works.
Namespace
Drupal\Tests\svg_formatter\FunctionalCode
public function testImageSizeAttributes() {
$media = $this
->createMediaEntity();
$media
->save();
$display = $this->container
->get('entity_type.manager')
->getStorage('entity_view_display')
->load('media.svg.default');
$component = $display
->getComponent('field_media_file');
$component['settings'] = [
'inline' => FALSE,
'sanitize' => TRUE,
'apply_dimensions' => TRUE,
'width' => 99,
'height' => 99,
'enable_alt' => TRUE,
'alt_string' => '',
'enable_title' => TRUE,
'title_string' => '',
];
$display
->setComponent('field_media_file', $component)
->save();
$this
->drupalGet('media/1');
$this
->assertSession()
->elementAttributeContains('css', 'main > div > div > div:nth-child(3) > div:nth-child(4) > div:nth-child(2) > img', 'width', '99');
$this
->assertSession()
->elementAttributeContains('css', 'main > div > div > div:nth-child(3) > div:nth-child(4) > div:nth-child(2) > img', 'height', '99');
// Test that image attributes don't exist if apply_dimensions is disabled.
$component['settings'] = [
'inline' => FALSE,
'sanitize' => TRUE,
'apply_dimensions' => FALSE,
'width' => 99,
'height' => 99,
'enable_alt' => TRUE,
'alt_string' => '',
'enable_title' => TRUE,
'title_string' => '',
];
$display
->setComponent('field_media_file', $component)
->save();
$this
->drupalGet('media/1');
$this
->assertSession()
->elementNotExists('css', 'main > div > div > div:nth-child(3) > div:nth-child(4) > div:nth-child(2) > img[width]');
$this
->assertSession()
->elementNotExists('css', 'main > div > div > div:nth-child(3) > div:nth-child(4) > div:nth-child(2) > img[height]');
}