function ImageThemeFunctionTest::testImageFormatterDeprecatedProperty

Test the deprecated item_attributes property.

Attributes

#[IgnoreDeprecations]

File

core/modules/image/tests/src/Kernel/ImageThemeFunctionTest.php, line 169

Class

ImageThemeFunctionTest
Tests image theme functions.

Namespace

Drupal\Tests\image\Kernel

Code

public function testImageFormatterDeprecatedProperty() : void {
  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = $this->container
    ->get('renderer');
  // Create an image.
  $files = $this->drupalGetTestFiles('image');
  $file = reset($files);
  $original_uri = \Drupal::service('file_system')->copy($file->uri, 'public://', FileExists::Rename);
  // Create a test entity with the image field set.
  $entity = EntityTest::create();
  $entity->image_test->target_id = $this->image
    ->id();
  $entity->image_test->alt = NULL;
  $entity->image_test->uri = $original_uri;
  $entity->save();
  // Create the base element that we'll use in the tests below.
  $path = $this->randomMachineName();
  $element = [
    '#theme' => 'image_formatter',
    '#item' => $entity->image_test,
    '#url' => Url::fromUri('base:' . $path),
    '#item_attributes' => [
      'class' => [
        'foo',
      ],
    ],
  ];
  $renderer->renderRoot($element);
  $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.