3 namespace Drupal\Tests\system\Functional\Render;
5 use Drupal\Tests\BrowserTestBase;
8 * Performs tests for the effects of the ajax_page_state query parameter.
12 class AjaxPageStateTest extends BrowserTestBase {
19 public static $modules = ['node', 'views'];
22 * User account with all available permissions
24 * @var \Drupal\Core\Session\AccountInterface
28 protected function setUp() {
30 // Create an administrator with all permissions.
31 $this->adminUser = $this->drupalCreateUser(array_keys(\Drupal::service('user.permissions')
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);
40 * Default functionality without the param ajax_page_state[libraries].
42 * The libraries html5shiv and drupalSettings are loaded default from core
43 * and available in code as scripts. Do this as the base test.
45 public function testLibrariesAvailable() {
46 $this->drupalGet('node', []);
48 '/core/assets/vendor/html5shiv/html5shiv.min.js',
49 'The html5shiv library from core should be loaded.'
52 '/core/misc/drupalSettingsLoader.js',
53 'The drupalSettings library from core should be loaded.'
58 * Give ajax_page_state[libraries]=core/html5shiv to exclude the library.
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.
64 public function testHtml5ShivIsNotLoaded() {
65 $this->drupalGet('node',
69 'ajax_page_state' => [
70 'libraries' => 'core/html5shiv'
76 '/core/assets/vendor/html5shiv/html5shiv.min.js',
77 'The html5shiv library from core should be excluded from loading'
81 '/core/misc/drupalSettingsLoader.js',
82 'The drupalSettings library from core should be loaded.'
87 * Test if multiple libraries can be excluded.
89 * The ajax_page_state[libraries] should be able to support multiple libraries
92 public function testMultipleLibrariesAreNotLoaded() {
93 $this->drupalGet('node',
94 ['query' => ['ajax_page_state' => ['libraries' => 'core/html5shiv,core/drupalSettings']]]
96 $this->assertResponse(200);
98 '/core/assets/vendor/html5shiv/html5shiv.min.js',
99 'The html5shiv library from core should be excluded from loading.'
103 '/core/misc/drupalSettingsLoader.js',
104 'The drupalSettings library from core should be excluded from loading.'
107 $this->drupalGet('node');
109 '/core/assets/vendor/html5shiv/html5shiv.min.js',
110 'The html5shiv library from core should be included in loading.'
114 '/core/misc/drupalSettingsLoader.js',
115 'The drupalSettings library from core should be included in loading.'