function ResponsiveImageFieldDisplayTest::testResponsiveImageFieldFormatterDeprecatedProperty
Test the deprecated item_attributes property.
Attributes
#[IgnoreDeprecations]
File
-
core/
modules/ responsive_image/ tests/ src/ Functional/ ResponsiveImageFieldDisplayTest.php, line 457
Class
- ResponsiveImageFieldDisplayTest
- Tests responsive image display formatter.
Namespace
Drupal\Tests\responsive_image\FunctionalCode
public function testResponsiveImageFieldFormatterDeprecatedProperty() : void {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container
->get('renderer');
$node_storage = $this->container
->get('entity_type.manager')
->getStorage('node');
$field_name = $this->randomMachineName();
$this->createImageField($field_name, 'node', 'article', [
'uri_scheme' => 'public',
]);
// Create a new node with an image attached.
$test_image = current($this->getTestFiles('image'));
$nid = $this->uploadNodeImage($test_image, $field_name, 'article', $this->randomMachineName());
$node_storage->resetCache([
$nid,
]);
$node = $node_storage->load($nid);
$image = [
'#theme' => 'responsive_image_formatter',
'#item' => $node->{$field_name}[0],
'#responsive_image_style_id' => 'style_one',
'#item_attributes' => [
'data-test1' => 'test1',
'data-test2' => 'test2',
],
];
$html_output = str_replace("\n", '', (string) $renderer->renderRoot($image));
$this->assertStringContainsString('data-test1="test1"', $html_output);
$this->assertStringContainsString('data-test2="test2"', $html_output);
$this->expectDeprecation('Usage of #item_attributes is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Use #attributes instead. See https://www.drupal.org/node/3554585');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.