function StandardPerformanceTest::testAnonymous

Same name and namespace in other branches
  1. 10 core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php \Drupal\Tests\standard\FunctionalJavascript\StandardPerformanceTest::testAnonymous()
  2. 11.x core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php \Drupal\Tests\standard\FunctionalJavascript\StandardPerformanceTest::testAnonymous()

Tests performance for anonymous users.

1 call to StandardPerformanceTest::testAnonymous()
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 67

Class

StandardPerformanceTest
Tests the performance of basic functionality in the standard profile.

Namespace

Drupal\Tests\standard\FunctionalJavascript

Code

protected function testAnonymous() : void {
  // Request the front page, then immediately clear all object caches, so that
  // aggregates and image styles are created on disk but otherwise caches are
  // empty.
  $this->drupalGet('');
  // Give time for big pipe placeholders, asset aggregate requests, and post
  // response tasks to finish processing and write to any caches before
  // clearing caches again.
  sleep(2);
  foreach (Cache::getBins() as $bin) {
    $bin->deleteAll();
  }
  // Now visit a different page to warm some caches.
  $this->drupalGet('user/password');
  // Ensure everything finishes before we collect performance data.
  sleep(2);
  // Test frontpage.
  $performance_data = $this->collectPerformanceData(function () {
    $this->drupalGet('');
  }, 'standardFrontPage');
  $this->assertNoJavaScript($performance_data);
  $this->assertQueriesByName('standardFrontPage', $performance_data->getQueries());
  $this->assertMetricsByName('standardFrontPage', $performance_data);
  // Test node page.
  $performance_data = $this->collectPerformanceData(function () {
    $this->drupalGet('node/1');
  }, 'standardNodePage');
  $this->assertQueriesByName('standardNodePage', $performance_data->getQueries());
  $this->assertMetricsByName('standardNodePage', $performance_data);
  // Test user profile page.
  $this->user = $this->drupalCreateUser();
  $performance_data = $this->collectPerformanceData(function () {
    $this->drupalGet('user/' . $this->user
      ->id());
  }, 'standardUserPage');
  $this->assertNoJavaScript($performance_data);
  $this->assertQueriesByName('standardUserPage', $performance_data->getQueries());
  $this->assertMetricsByName('standardUserPage', $performance_data);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.