function ImageDimensionsTest::getImageTag

Same name and namespace in other branches
  1. 9 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_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_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
Test styled image dimensions cumulatively.

File

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

Class

ImageDimensionsTest
Tests that images have correct dimensions when styled.

Namespace

Drupal\Tests\image\Functional

Code

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

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