function NodePerformanceTest::testPromotedContentPage

Tests performance for the promoted content page view.

File

core/modules/node/tests/src/FunctionalJavascript/NodePerformanceTest.php, line 75

Class

NodePerformanceTest
Tests the performance of node functionality including cache invalidation.

Namespace

Drupal\Tests\node\FunctionalJavascript

Code

protected function testPromotedContentPage() : void {
  // Request the promoted content page, then immediately clear all object
  // caches, so that aggregates and image styles are created on disk but
  // otherwise caches are empty.
  $this->drupalGet('node');
  // 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/login');
  // Ensure everything finishes before we collect performance data.
  sleep(2);
  // Test promoted content page.
  $performance_data = $this->collectPerformanceData(function () {
    $this->drupalGet('node');
  }, 'nodePromotedContentPage');
  $this->assertSame(0, $performance_data->getScriptBytes());
  $this->assertQueriesByName('nodePromotedContentPage', $performance_data->getQueries());
  $this->assertMetricsByName('nodePromotedContentPage', $performance_data);
  $expected_default_cache_cids = [
    'views_data:node_field_data:en',
    'views_data:en',
    'views_data:views:en',
    'views_data:node:en',
    'theme_registry:stark',
  ];
  $this->assertSame($expected_default_cache_cids, $performance_data->getCacheOperations()['get']['default']);
}

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