You are here

public function RendererTest::testRenderSortingWithSetHashSorted in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::testRenderSortingWithSetHashSorted()
  2. 10 core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::testRenderSortingWithSetHashSorted()

@covers ::render @covers ::doRender

File

core/tests/Drupal/Tests/Core/Render/RendererTest.php, line 521
Contains \Drupal\Tests\Core\Render\RendererTest.

Class

RendererTest
@coversDefaultClass \Drupal\Core\Render\Renderer @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function testRenderSortingWithSetHashSorted() {
  $first = $this
    ->randomMachineName();
  $second = $this
    ->randomMachineName();

  // The same array structure again, but with #sorted set to TRUE.
  $elements = [
    'second' => [
      '#weight' => 10,
      '#markup' => $second,
    ],
    'first' => [
      '#weight' => 0,
      '#markup' => $first,
    ],
    '#sorted' => TRUE,
  ];
  $output = $this->renderer
    ->renderRoot($elements);

  // The elements should appear in output in the same order as the array.
  $this
    ->assertLessThan(strpos($output, $first), strpos($output, $second));
}