class AjaxPageStateTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Render/AjaxPageStateTest.php \Drupal\Tests\system\Functional\Render\AjaxPageStateTest
- 11.x core/tests/Drupal/Tests/Core/StackMiddleware/AjaxPageStateTest.php \Drupal\Tests\Core\StackMiddleware\AjaxPageStateTest
- 10 core/modules/system/tests/src/Functional/Render/AjaxPageStateTest.php \Drupal\Tests\system\Functional\Render\AjaxPageStateTest
- 8.9.x core/modules/system/tests/src/Functional/Render/AjaxPageStateTest.php \Drupal\Tests\system\Functional\Render\AjaxPageStateTest
Performs tests for the effects of the ajax_page_state query parameter.
@group Render
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Render\AjaxPageStateTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of AjaxPageStateTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Render/ AjaxPageStateTest.php, line 12
Namespace
Drupal\Tests\system\Functional\RenderView source
class AjaxPageStateTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'node',
'views',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* User account with all available permissions.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create an administrator with all permissions.
$this->adminUser = $this->drupalCreateUser(array_keys(\Drupal::service('user.permissions')->getPermissions()));
// Log in so there are more libraries to test for.
$this->drupalLogin($this->adminUser);
}
/**
* Default functionality without the param ajax_page_state[libraries].
*
* The libraries active-link and drupalSettings are loaded default from core
* and available in code as scripts. Do this as the base test.
*/
public function testLibrariesAvailable() {
$this->drupalGet('node', []);
// The active link library from core should be loaded.
$this->assertSession()
->responseContains('/core/misc/active-link.js');
// The drupalSettings library from core should be loaded.
$this->assertSession()
->responseContains('/core/misc/drupalSettingsLoader.js');
}
/**
* Give ajax_page_state[libraries]=core/drupalSettings to exclude the library.
*
* When called with ajax_page_state[libraries]=core/drupalSettings the library
* should be excluded as it is already loaded. This should not affect other
* libraries so test if active-link is still available.
*/
public function testDrupalSettingsIsNotLoaded() {
$this->drupalGet('node', [
"query" => [
'ajax_page_state' => [
'libraries' => 'core/drupalSettings',
],
],
]);
// The drupalSettings library from core should be excluded from loading.
$this->assertSession()
->responseNotContains('/core/misc/drupalSettingsLoader.js');
// The active-link library from core should be loaded.
$this->assertSession()
->responseContains('/core/misc/active-link.js');
}
/**
* Tests if multiple libraries can be excluded.
*
* The ajax_page_state[libraries] should be able to support multiple libraries
* comma separated.
*/
public function testMultipleLibrariesAreNotLoaded() {
$this->drupalGet('node', [
'query' => [
'ajax_page_state' => [
'libraries' => 'core/drupal,core/drupalSettings',
],
],
]);
$this->assertSession()
->statusCodeEquals(200);
// The drupal library from core should be excluded from loading.
$this->assertSession()
->responseNotContains('/core/misc/drupal.js');
// The drupalSettings library from core should be excluded from loading.
$this->assertSession()
->responseNotContains('/core/misc/drupalSettingsLoader.js');
$this->drupalGet('node');
// The drupal library from core should be included in loading.
$this->assertSession()
->responseContains('/core/misc/drupal.js');
// The drupalSettings library from core should be included in loading.
$this->assertSession()
->responseContains('/core/misc/drupalSettingsLoader.js');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.