Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / src / Functional / Render / AjaxPageStateTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Render;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Performs tests for the effects of the ajax_page_state query parameter.
9  *
10  * @group Render
11  */
12 class AjaxPageStateTest extends BrowserTestBase {
13
14   /**
15    * Modules to install.
16    *
17    * @var array
18    */
19   public static $modules = ['node', 'views'];
20
21   /**
22    * User account with all available permissions
23    *
24    * @var \Drupal\Core\Session\AccountInterface
25    */
26   protected $adminUser;
27
28   protected function setUp() {
29     parent::setUp();
30     // Create an administrator with all permissions.
31     $this->adminUser = $this->drupalCreateUser(array_keys(\Drupal::service('user.permissions')
32       ->getPermissions()));
33
34     // Log in so there are more libraries to test with otherwise only html5shiv
35     // is the only one in the source we can easily test for.
36     $this->drupalLogin($this->adminUser);
37   }
38
39   /**
40    * Default functionality without the param ajax_page_state[libraries].
41    *
42    * The libraries html5shiv and drupalSettings are loaded default from core
43    * and available in code as scripts. Do this as the base test.
44    */
45   public function testLibrariesAvailable() {
46     $this->drupalGet('node', []);
47     $this->assertRaw(
48       '/core/assets/vendor/html5shiv/html5shiv.min.js',
49       'The html5shiv library from core should be loaded.'
50     );
51     $this->assertRaw(
52       '/core/misc/drupalSettingsLoader.js',
53       'The drupalSettings library from core should be loaded.'
54     );
55   }
56
57   /**
58    * Give ajax_page_state[libraries]=core/html5shiv to exclude the library.
59    *
60    * When called with ajax_page_state[libraries]=core/html5shiv the library
61    * should be excluded as it is already loaded. This should not affect other
62    * libraries so test if drupalSettings is still available.
63    */
64   public function testHtml5ShivIsNotLoaded() {
65     $this->drupalGet('node',
66       [
67         "query" =>
68           [
69             'ajax_page_state' => [
70               'libraries' => 'core/html5shiv',
71             ],
72           ],
73       ]
74     );
75     $this->assertNoRaw(
76       '/core/assets/vendor/html5shiv/html5shiv.min.js',
77       'The html5shiv library from core should be excluded from loading'
78     );
79
80     $this->assertRaw(
81       '/core/misc/drupalSettingsLoader.js',
82       'The drupalSettings library from core should be loaded.'
83     );
84   }
85
86   /**
87    * Test if multiple libraries can be excluded.
88    *
89    * The ajax_page_state[libraries] should be able to support multiple libraries
90    * comma separated.
91    */
92   public function testMultipleLibrariesAreNotLoaded() {
93     $this->drupalGet('node',
94       ['query' => ['ajax_page_state' => ['libraries' => 'core/html5shiv,core/drupalSettings']]]
95     );
96     $this->assertResponse(200);
97     $this->assertNoRaw(
98       '/core/assets/vendor/html5shiv/html5shiv.min.js',
99       'The html5shiv library from core should be excluded from loading.'
100     );
101
102     $this->assertNoRaw(
103       '/core/misc/drupalSettingsLoader.js',
104       'The drupalSettings library from core should be excluded from loading.'
105     );
106
107     $this->drupalGet('node');
108     $this->assertRaw(
109       '/core/assets/vendor/html5shiv/html5shiv.min.js',
110       'The html5shiv library from core should be included in loading.'
111     );
112
113     $this->assertRaw(
114       '/core/misc/drupalSettingsLoader.js',
115       'The drupalSettings library from core should be included in loading.'
116     );
117   }
118
119 }