You are here

public function RenderTest::testDrupalRenderThemePreprocessAttached in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Render/RenderTest.php \Drupal\KernelTests\Core\Render\RenderTest::testDrupalRenderThemePreprocessAttached()
  2. 9 core/tests/Drupal/KernelTests/Core/Render/RenderTest.php \Drupal\KernelTests\Core\Render\RenderTest::testDrupalRenderThemePreprocessAttached()

Tests theme preprocess functions being able to attach assets.

File

core/tests/Drupal/KernelTests/Core/Render/RenderTest.php, line 24

Class

RenderTest
Performs functional tests on \Drupal::service('renderer')->render().

Namespace

Drupal\KernelTests\Core\Render

Code

public function testDrupalRenderThemePreprocessAttached() {
  \Drupal::state()
    ->set('theme_preprocess_attached_test', TRUE);
  $test_element = [
    '#theme' => 'common_test_render_element',
    'foo' => [
      '#markup' => 'Kittens!',
    ],
  ];
  \Drupal::service('renderer')
    ->renderRoot($test_element);
  $expected_attached = [
    'library' => [
      'test/generic_preprocess',
      'test/specific_preprocess',
    ],
  ];
  $this
    ->assertEquals($expected_attached, $test_element['#attached'], 'All expected assets from theme preprocess hooks attached.');
  \Drupal::state()
    ->set('theme_preprocess_attached_test', FALSE);
}