Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Render / RenderTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Render;
4
5 use Drupal\KernelTests\KernelTestBase;
6
7 /**
8  * Performs functional tests on drupal_render().
9  *
10  * @group Common
11  */
12 class RenderTest extends KernelTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['system', 'common_test'];
20
21   /**
22    * Tests theme preprocess functions being able to attach assets.
23    */
24   public function testDrupalRenderThemePreprocessAttached() {
25     \Drupal::state()->set('theme_preprocess_attached_test', TRUE);
26
27     $test_element = [
28       '#theme' => 'common_test_render_element',
29       'foo' => [
30         '#markup' => 'Kittens!',
31       ],
32     ];
33     \Drupal::service('renderer')->renderRoot($test_element);
34
35     $expected_attached = [
36       'library' => [
37         'test/generic_preprocess',
38         'test/specific_preprocess',
39       ]
40     ];
41     $this->assertEqual($expected_attached, $test_element['#attached'], 'All expected assets from theme preprocess hooks attached.');
42
43     \Drupal::state()->set('theme_preprocess_attached_test', FALSE);
44   }
45
46   /**
47    * Tests that we get an exception when we try to attach an illegal type.
48    */
49   public function testProcessAttached() {
50     // Specify invalid attachments in a render array.
51     $build['#attached']['library'][] = 'core/drupal.states';
52     $build['#attached']['drupal_process_states'][] = [];
53     $renderer = $this->container->get('bare_html_page_renderer');
54     try {
55       $renderer->renderBarePage($build, '', 'maintenance_page');
56       $this->fail("Invalid #attachment 'drupal_process_states' allowed");
57     }
58     catch (\LogicException $e) {
59       $this->pass("Invalid #attachment 'drupal_process_states' not allowed");
60     }
61   }
62
63 }