Chris@0: container->get('renderer'); Chris@0: $extension = twig_extension(); Chris@0: \Drupal::service('theme_handler')->install(['test_theme']); Chris@0: $this->config('system.theme')->set('default', 'test_theme')->save(); Chris@0: $this->drupalCreateContentType(['type' => 'page']); Chris@0: // Enable debug, rebuild the service container, and clear all caches. Chris@0: $parameters = $this->container->getParameter('twig.config'); Chris@0: $parameters['debug'] = TRUE; Chris@0: $this->setContainerParameter('twig.config', $parameters); Chris@0: $this->rebuildContainer(); Chris@0: $this->resetAll(); Chris@0: Chris@0: $cache = $this->container->get('theme.registry')->get(); Chris@0: // Create array of Twig templates. Chris@0: $templates = drupal_find_theme_templates($cache, $extension, drupal_get_path('theme', 'test_theme')); Chris@0: $templates += drupal_find_theme_templates($cache, $extension, drupal_get_path('module', 'node')); Chris@0: Chris@0: // Create a node and test different features of the debug markup. Chris@0: $node = $this->drupalCreateNode(); Chris@0: $build = node_view($node); Chris@0: $output = $renderer->renderRoot($build); Chris@0: $this->assertTrue(strpos($output, '') !== FALSE, 'Twig debug markup found in theme output when debug is enabled.'); Chris@0: $this->setRawContent($output); Chris@0: $this->assertTrue(strpos($output, "THEME HOOK: 'node'") !== FALSE, 'Theme call information found.'); Chris@0: $this->assertTrue(strpos($output, '* node--1--full' . $extension . PHP_EOL . ' x node--1' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' * node' . $extension) !== FALSE, 'Suggested template files found in order and node ID specific template shown as current template.'); Chris@0: $this->assertEscaped('node--'); Chris@0: $template_filename = $templates['node__1']['path'] . '/' . $templates['node__1']['template'] . $extension; Chris@0: $this->assertTrue(strpos($output, "BEGIN OUTPUT from '$template_filename'") !== FALSE, 'Full path to current template file found.'); Chris@0: Chris@0: // Create another node and make sure the template suggestions shown in the Chris@0: // debug markup are correct. Chris@0: $node2 = $this->drupalCreateNode(); Chris@0: $build = node_view($node2); Chris@0: $output = $renderer->renderRoot($build); Chris@0: $this->assertTrue(strpos($output, '* node--2--full' . $extension . PHP_EOL . ' * node--2' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.'); Chris@0: Chris@0: // Create another node and make sure the template suggestions shown in the Chris@0: // debug markup are correct. Chris@0: $node3 = $this->drupalCreateNode(); Chris@0: $build = ['#theme' => 'node__foo__bar']; Chris@0: $build += node_view($node3); Chris@0: $output = $renderer->renderRoot($build); Chris@0: $this->assertTrue(strpos($output, "THEME HOOK: 'node__foo__bar'") !== FALSE, 'Theme call information found.'); Chris@0: $this->assertTrue(strpos($output, '* node--foo--bar' . $extension . PHP_EOL . ' * node--foo' . $extension . PHP_EOL . ' * node--<script type="text/javascript">alert('yo');</script>' . $extension . PHP_EOL . ' * node--3--full' . $extension . PHP_EOL . ' * node--3' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.'); Chris@0: Chris@0: // Disable debug, rebuild the service container, and clear all caches. Chris@0: $parameters = $this->container->getParameter('twig.config'); Chris@0: $parameters['debug'] = FALSE; Chris@0: $this->setContainerParameter('twig.config', $parameters); Chris@0: $this->rebuildContainer(); Chris@0: $this->resetAll(); Chris@0: Chris@0: $build = node_view($node); Chris@0: $output = $renderer->renderRoot($build); Chris@0: $this->assertFalse(strpos($output, '') !== FALSE, 'Twig debug markup not found in theme output when debug is disabled.'); Chris@0: } Chris@0: Chris@0: }