Issue #2254209 by smustgrave, marvil07, quietone, sun, catch, Wim Leers: Fix test performance of Drupal\system\Tests\Cache\PageCacheTagsIntegrationTest

(cherry picked from commit 57ca853a11)
merge-requests/6119/head
catch 2024-01-09 16:18:00 +00:00
parent 4729960556
commit 56c825fc56
1 changed files with 53 additions and 2 deletions

View File

@ -2,11 +2,18 @@
namespace Drupal\Tests\page_cache\Functional;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
use Drupal\Core\Language\LanguageInterface;
use Drupal\filter\Entity\FilterFormat;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\node\NodeInterface;
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
use Symfony\Component\Yaml\Yaml;
/**
* Enables the page cache and tests its cache tags in various scenarios.
@ -17,11 +24,29 @@ use Drupal\Tests\BrowserTestBase;
class PageCacheTagsIntegrationTest extends BrowserTestBase {
use AssertPageCacheContextsAndTagsTrait;
use CommentTestTrait;
/**
* {@inheritdoc}
*/
protected $profile = 'standard';
protected $defaultTheme = 'olivero';
/**
* Modules to enable.
* @var array
*/
protected static $modules = [
'big_pipe',
'block',
'comment',
'editor',
'filter',
'language',
'help',
'node',
'search',
'views',
];
/**
* {@inheritdoc}
@ -36,6 +61,32 @@ class PageCacheTagsIntegrationTest extends BrowserTestBase {
* Tests that cache tags are properly bubbled up to the page level.
*/
public function testPageCacheTags() {
$config = $this->config('language.types');
$config->set('configurable', [LanguageInterface::TYPE_INTERFACE, LanguageInterface::TYPE_CONTENT]);
$config->set('negotiation.language_content.enabled', [
LanguageNegotiationUrl::METHOD_ID => 0,
LanguageNegotiationContentEntity::METHOD_ID => 1,
]);
$config->save();
// Create two filters.
FilterFormat::create(
Yaml::parseFile('core/profiles/standard/config/install/filter.format.basic_html.yml')
)->save();
FilterFormat::create(
Yaml::parseFile('core/profiles/standard/config/install/filter.format.full_html.yml')
)->save();
$this->drupalCreateContentType(['type' => 'page', 'title' => 'Basic page']);
$this->addDefaultCommentField('node', 'page');
// To generate search and comment tags.
$anonymous = Role::load(RoleInterface::ANONYMOUS_ID);
$anonymous
->grantPermission('search content')
->grantPermission('access comments');
$anonymous->save();
// Create two nodes.
$author_1 = $this->drupalCreateUser();
$node_1 = $this->drupalCreateNode([
@ -80,7 +131,7 @@ class PageCacheTagsIntegrationTest extends BrowserTestBase {
'cookies:big_pipe_nojs',
'session.exists',
'user.permissions',
'user.roles:authenticated',
'user.roles',
];
// Full node page 1.