function RenderTest::testDrupalRenderThemePreprocessAttached

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Render/RenderTest.php \Drupal\KernelTests\Core\Render\RenderTest::testDrupalRenderThemePreprocessAttached()
  2. 10 core/tests/Drupal/KernelTests/Core/Render/RenderTest.php \Drupal\KernelTests\Core\Render\RenderTest::testDrupalRenderThemePreprocessAttached()
  3. 11.x 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 <a href="/api/drupal/core%21includes%21common.inc/function/drupal_render/8.9.x" title="Renders HTML given a structured array tree." class="local">drupal_render</a>().

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->assertEqual($expected_attached, $test_element['#attached'], 'All expected assets from theme preprocess hooks attached.');
    \Drupal::state()->set('theme_preprocess_attached_test', FALSE);
}

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