function RendererTest::testRenderSortingWithSetHashSorted

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::testRenderSortingWithSetHashSorted()
  2. 8.9.x core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::testRenderSortingWithSetHashSorted()
  3. 11.x 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 525

Class

RendererTest
@coversDefaultClass \Drupal\Core\Render\Renderer[[api-linebreak]] @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function testRenderSortingWithSetHashSorted() : void {
  $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 = (string) $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));
}

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