function StandardPerformanceTest::testAdmin
Same name and namespace in other branches
- 11.x core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php \Drupal\Tests\standard\FunctionalJavascript\StandardPerformanceTest::testAdmin()
Tests performance of a logged-in admin user with the navigation toolbar.
1 call to StandardPerformanceTest::testAdmin()
- StandardPerformanceTest::testStandardPerformance in core/
profiles/ standard/ tests/ src/ FunctionalJavascript/ StandardPerformanceTest.php - Tests performance of the standard profile.
File
-
core/
profiles/ standard/ tests/ src/ FunctionalJavascript/ StandardPerformanceTest.php, line 163
Class
- StandardPerformanceTest
- Tests the performance of basic functionality in the standard profile.
Namespace
Drupal\Tests\standard\FunctionalJavascriptCode
protected function testAdmin() : void {
$admin_user = $this->drupalCreateUser();
$admin_user->addRole('administrator');
$admin_user->save();
// Ensure no user is logged in and clear the render cache bin before
// starting the warm-up, since prior sub-tests may leave an active session
// and stale render cache entries.
$this->drupalLogout();
\Drupal::cache('render')->deleteAll();
$this->drupalLogin($admin_user);
// Request the node/1 page twice to ensure all cache collectors are fully
// warmed. The exact contents of cache collectors depends on the order in
// which requests complete so this ensures that the second request completes
// after asset aggregates are served.
$this->drupalGet('node/1');
sleep(1);
$this->drupalGet('node/1');
// Flush the dynamic page cache to simulate visiting a page that is not
// already fully cached.
\Drupal::cache('dynamic_page_cache')->deleteAll();
$performance_data = $this->collectPerformanceData(function () {
$this->drupalGet('node/1');
}, 'testAdmin');
$this->assertQueriesByName('testAdmin', $performance_data->getQueries());
$this->assertMetricsByName('testAdmin', $performance_data);
// The navigation toolbar must be cached under low-cardinality contexts,
// not per-user, to ensure it scales for authenticated admins.
$this->assertIsObject(\Drupal::cache('render')->get('navigation:navigation:[languages:language_interface]=en:[theme]=stark:[user.permissions]=is-admin'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.