StandardPerformanceTest.php
Same filename and directory in other branches
Namespace
Drupal\Tests\standard\FunctionalJavascriptFile
-
core/
profiles/ standard/ tests/ src/ FunctionalJavascript/ StandardPerformanceTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\standard\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\PerformanceTestBase;
use Drupal\user\UserInterface;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
// cSpell:ignore mlid
/**
* Tests the performance of basic functionality in the standard profile.
*/
class StandardPerformanceTest extends PerformanceTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected $profile = 'standard';
/**
* The user account created during testing.
*/
protected ?UserInterface $user = NULL;
/**
* Tests performance of a logged-in admin user with the navigation toolbar.
*/
public function testAdmin() : void {
$admin_user = $this->drupalCreateUser();
$admin_user->addRole('administrator');
$admin_user->save();
$this->drupalLogin($admin_user);
// Request the front 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('');
sleep(1);
$this->drupalGet('');
// 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('');
}, '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'));
}
}
Classes
| Title | Deprecated | Summary |
|---|---|---|
| StandardPerformanceTest | Tests the performance of basic functionality in the standard profile. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.