You are here

public function KernelTestBaseTest::testRenderWithTheme in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testRenderWithTheme()
  2. 9 core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testRenderWithTheme()

@covers ::render

File

core/tests/Drupal/KernelTests/KernelTestBaseTest.php, line 219

Class

KernelTestBaseTest
@coversDefaultClass \Drupal\KernelTests\KernelTestBase

Namespace

Drupal\KernelTests

Code

public function testRenderWithTheme() {
  $this
    ->enableModules([
    'system',
  ]);
  $build = [
    '#type' => 'textfield',
    '#name' => 'test',
  ];
  $expected = '/' . preg_quote('<input type="text" name="test"', '/') . '/';
  $this
    ->assertArrayNotHasKey('theme', $GLOBALS);
  $output = \Drupal::service('renderer')
    ->renderRoot($build);
  $this
    ->assertEquals('core', \Drupal::theme()
    ->getActiveTheme()
    ->getName());
  $this
    ->assertMatchesRegularExpression($expected, (string) $build['#children']);
  $this
    ->assertMatchesRegularExpression($expected, (string) $output);
}