Skip to content
Snippets Groups Projects
Unverified Commit cc797039 authored by Pablo López's avatar Pablo López
Browse files

Issue #3507866: Adjust tests

parent f9058994
No related branches found
No related tags found
1 merge request!11256Issue #3507866: Enable the Navigation Top Bar when Navigation is enabled
......@@ -115,13 +115,13 @@ public function testNavigationBlock(): void {
$this->drupalLogin($site_configuration_user1);
$this->verifyDynamicPageCache($test_page_url, 'MISS');
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertCacheContexts(['user', 'url.query_args:_wrapper_format', 'session']);
$this->assertCacheContexts(['user', 'url.query_args:_wrapper_format', 'session', 'route']);
$this->assertSession()->pageTextContains('Shortcuts');
$this->assertSession()->linkExists('Cron');
$this->drupalLogin($site_configuration_user2);
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertCacheContexts(['user', 'url.query_args:_wrapper_format', 'session']);
$this->assertCacheContexts(['user', 'url.query_args:_wrapper_format', 'session', 'route']);
$this->assertSession()->pageTextContains('Shortcuts');
$this->assertSession()->linkExists('Cron');
......
......@@ -25,7 +25,7 @@ class NavigationTopBarContentModerationTest extends ModerationStateTestBase {
protected static $modules = [
'content_moderation',
'node',
'navigation_top_bar',
'navigation',
];
/**
......
......@@ -26,7 +26,6 @@ class NavigationTopBarPageContextTest extends BrowserTestBase {
protected static $modules = [
'node',
'navigation',
'navigation_top_bar',
'test_page_test',
];
......
......@@ -83,20 +83,6 @@ public function testTopBarVisibility(): void {
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertSession()->elementNotExists('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/button");
$this->verifyDynamicPageCache($this->node->toUrl(), 'MISS');
$this->verifyDynamicPageCache($this->node->toUrl(), 'HIT');
// Top Bar is not visible if the feature flag module is disabled.
$this->assertSession()->elementNotExists('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/button");
$this->assertSession()->elementExists('xpath', '//div[@id="block-tabs"]');
\Drupal::service('module_installer')->install(['navigation_top_bar']);
// Test page does not include the Top Bar.
$test_page_url = Url::fromRoute('test_page_test.test_page');
$this->verifyDynamicPageCache($test_page_url, 'MISS');
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertSession()->elementNotExists('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/button");
// Top Bar is visible once the feature flag module is enabled.
$this->verifyDynamicPageCache($this->node->toUrl(), 'MISS');
$this->verifyDynamicPageCache($this->node->toUrl(), 'HIT');
......
......@@ -73,14 +73,14 @@ public function testLogin(): void {
$expected = [
'QueryCount' => 4,
'CacheGetCount' => 59,
'CacheGetCount' => 61,
'CacheGetCountByBin' => [
'config' => 11,
'data' => 6,
'discovery' => 10,
'bootstrap' => 6,
'dynamic_page_cache' => 2,
'render' => 23,
'render' => 25,
'menu' => 1,
],
'CacheSetCount' => 2,
......@@ -89,7 +89,7 @@ public function testLogin(): void {
],
'CacheDeleteCount' => 0,
'CacheTagChecksumCount' => 3,
'CacheTagIsValidCount' => 29,
'CacheTagIsValidCount' => 30,
'CacheTagInvalidationCount' => 0,
'ScriptCount' => 2,
'ScriptBytes' => 215500,
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\navigation\FunctionalJavascript;
use Drupal\Core\Cache\Cache;
use Drupal\FunctionalJavascriptTests\PerformanceTestBase;
/**
* Tests the performance impacts of navigation module.
*
* Stark is used as the default theme so that this test is not Olivero specific.
*
* @group navigation
*/
class TopBarPerformanceTest extends PerformanceTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'navigation',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected $profile = 'testing';
/**
* Tests performance for anonymous users is not affected by the Top Bar.
*/
public function testTopBarPerformance(): 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();
}
// Gather performance data before enabling navigation_top_bar.
$performance_data_before_top_bar = $this->collectPerformanceData(function () {
$this->drupalGet('');
}, 'navigationFrontPageTopBarDisabled');
// Install navigation_top_bar module.
\Drupal::service('module_installer')->install(['navigation_top_bar']);
// Clear caches to prep for another performance data collect.
foreach (Cache::getBins() as $bin) {
$bin->deleteAll();
}
// Gather performance data after enabling navigation_top_bar.
$performance_data_after_top_bar = $this->collectPerformanceData(function () {
$this->drupalGet('');
}, 'navigationFrontPageTopBarEnabled');
// Ensure that there is no change to performance metrics from the Top Bar.
// Anonymous users should never see the Top Bar.
$this->assertMetrics([
'QueryCount' => $performance_data_before_top_bar->getQueryCount(),
'CacheGetCount' => $performance_data_before_top_bar->getCacheGetCount(),
'CacheSetCount' => $performance_data_before_top_bar->getCacheSetCount(),
'CacheDeleteCount' => $performance_data_before_top_bar->getCacheDeleteCount(),
'CacheTagChecksumCount' => $performance_data_before_top_bar->getCacheTagChecksumCount(),
'CacheTagIsValidCount' => $performance_data_before_top_bar->getCacheTagIsValidCount(),
'CacheTagInvalidationCount' => $performance_data_before_top_bar->getCacheTagInvalidationCount(),
], $performance_data_after_top_bar);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment