function ImageDimensionsTest::getImageTag

Same name and namespace in other branches
  1. 8.9.x core/modules/image/tests/src/Functional/ImageDimensionsTest.php \Drupal\Tests\image\Functional\ImageDimensionsTest::getImageTag()
  2. 10 core/modules/image/tests/src/Functional/ImageDimensionsTest.php \Drupal\Tests\image\Functional\ImageDimensionsTest::getImageTag()
  3. 11.x core/modules/image/tests/src/Functional/ImageDimensionsTest.php \Drupal\Tests\image\Functional\ImageDimensionsTest::getImageTag()

Render an image style element.

Function \Drupal\Core\Render\RendererInterface::render() alters the passed $variables array by adding a new key '#printed' => TRUE. This prevents next call to re-render the element. We wrap \Drupal\Core\Render\RendererInterface::render() in a helper protected method and pass each time a fresh array so that $variables won't get altered and the element is re-rendered each time.

1 call to ImageDimensionsTest::getImageTag()
ImageDimensionsTest::testImageDimensions in core/modules/image/tests/src/Functional/ImageDimensionsTest.php
Tests styled image dimensions cumulatively.

File

core/modules/image/tests/src/Functional/ImageDimensionsTest.php, line 306

Class

ImageDimensionsTest
Tests that images have correct dimensions when styled.

Namespace

Drupal\Tests\image\Functional

Code

protected function getImageTag($variables) {
    return str_replace("\n", '', \Drupal::service('renderer')->renderRoot($variables));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.