diff -u b/core/modules/system/tests/modules/theme_test/theme_test.module b/core/modules/system/tests/modules/theme_test/theme_test.module --- b/core/modules/system/tests/modules/theme_test/theme_test.module +++ b/core/modules/system/tests/modules/theme_test/theme_test.module @@ -52,6 +52,11 @@ 'theme callback' => '_theme_custom_theme', 'type' => MENU_CALLBACK, ); + $items['theme-test/request-listener'] = array( + 'page callback' => 'theme_test_request_listener_page_callback', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); $items['theme-test/template-test'] = array( 'page callback' => 'theme_test_template_test_page_callback', 'access callback' => TRUE, @@ -74,6 +79,13 @@ } /** + * Menu callback for testing themed output generated in a request listener. + */ +function theme_test_request_listener_page_callback() { + return $GLOBALS['theme_test_output']; +} + +/** * Menu callback for testing template overridding based on filename. */ function theme_test_template_test_page_callback() { only in patch2: unchanged: --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeEarlyInitializationTest.php @@ -0,0 +1,43 @@ + 'Early theme initialization', + 'description' => 'Tests that the theme system can be correctly initialized early in the page request.', + 'group' => 'Theme', + ); + } + + /** + * Test that the theme system can generate output in a request listener. + */ + function testRequestListener() { + $this->drupalGet('theme-test/request-listener'); + // Verify that themed output generated in the request listener appears. + $this->assertRaw('Themed output generated in a KernelEvents::REQUEST listener'); + // Verify that the default theme's CSS still appears even though the theme + // system was initialized early. + $this->assertRaw('stark/css/layout.css'); + } +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/EventSubscriber/ThemeTestSubscriber.php @@ -0,0 +1,49 @@ +getRequest(); + $current_path = $request->attributes->get('system_path'); + if ($current_path == 'theme-test/request-listener') { + // First, force the theme registry to be rebuilt on this page request. + // This allows us to test a full initialization of the theme system in + // the code below. + drupal_theme_rebuild(); + // Next, initialize the theme system by storing themed text in a global + // variable. We will use this later in + // theme_test_request_listener_page_callback() to test that even when the + // theme system is initialized this early, it is still capable of + // returning output and theming the page as a whole. + $GLOBALS['theme_test_output'] = theme('more_link', array('url' => 'user', 'title' => 'Themed output generated in a KernelEvents::REQUEST listener')); + } + } + + /** + * {@inheritdoc} + */ + static function getSubscribedEvents() { + $events[KernelEvents::REQUEST][] = array('onRequest'); + return $events; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/system/tests/modules/theme_test/theme_test.services.yml @@ -0,0 +1,5 @@ +services: + theme_test.subscriber: + class: Drupal\theme_test\EventSubscriber\ThemeTestSubscriber + tags: + - { name: event_subscriber }