Issue #3469335 by catch, smustgrave: Speed up PageCacheTest
(cherry picked from commit de6e4c69e5
)
merge-requests/9339/head
parent
2d8df6ac4c
commit
87e995edfe
|
@ -53,7 +53,7 @@ class PageCacheTest extends BrowserTestBase {
|
|||
* Since tag based invalidation works, we know that our tag properly
|
||||
* persisted.
|
||||
*/
|
||||
public function testPageCacheTags(): void {
|
||||
protected function testPageCacheTags(): void {
|
||||
$this->enablePageCaching();
|
||||
|
||||
$path = 'system-test/cache_tags_page';
|
||||
|
@ -85,7 +85,7 @@ class PageCacheTest extends BrowserTestBase {
|
|||
/**
|
||||
* Tests that the page cache doesn't depend on cacheability headers.
|
||||
*/
|
||||
public function testPageCacheTagsIndependentFromCacheabilityHeaders(): void {
|
||||
protected function testPageCacheTagsIndependentFromCacheabilityHeaders(): void {
|
||||
// Disable the cacheability headers.
|
||||
$this->setContainerParameter('http.response.debug_cacheability_headers', FALSE);
|
||||
$this->rebuildContainer();
|
||||
|
@ -216,12 +216,38 @@ class PageCacheTest extends BrowserTestBase {
|
|||
$this->assertSession()->statusCodeEquals(200);
|
||||
// Verify that absence of Page was not cached.
|
||||
$this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
|
||||
$this->drupalLogout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests cache headers.
|
||||
* Tests page caching.
|
||||
*/
|
||||
public function testPageCache(): void {
|
||||
$this->testCacheableWithCustomCacheControl();
|
||||
\Drupal::service('cache.page')->deleteAll();
|
||||
$this->testPageCacheAnonymous403404();
|
||||
\Drupal::service('cache.page')->deleteAll();
|
||||
$this->testCacheabilityOfRedirectResponses();
|
||||
\Drupal::service('cache.page')->deleteAll();
|
||||
$this->testNoUrlNormalization();
|
||||
\Drupal::service('cache.page')->deleteAll();
|
||||
$this->testPageCacheHeaders();
|
||||
\Drupal::service('cache.page')->deleteAll();
|
||||
$this->testPageCacheWithoutVaryCookie();
|
||||
\Drupal::service('cache.page')->deleteAll();
|
||||
$this->testPageCacheTags();
|
||||
\Drupal::service('cache.page')->deleteAll();
|
||||
$this->testPageCacheAnonymousRolePermissions();
|
||||
\Drupal::service('cache.page')->deleteAll();
|
||||
$this->testHead();
|
||||
\Drupal::service('cache.page')->deleteAll();
|
||||
$this->testPageCacheTagsIndependentFromCacheabilityHeaders();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests page cache headers.
|
||||
*/
|
||||
protected function testPageCacheHeaders(): void {
|
||||
$this->enablePageCaching();
|
||||
|
||||
// Fill the cache.
|
||||
|
@ -279,7 +305,7 @@ class PageCacheTest extends BrowserTestBase {
|
|||
* This test verifies that, and it verifies that it does not happen for other
|
||||
* roles.
|
||||
*/
|
||||
public function testPageCacheAnonymousRolePermissions(): void {
|
||||
protected function testPageCacheAnonymousRolePermissions(): void {
|
||||
$this->enablePageCaching();
|
||||
|
||||
$content_url = Url::fromRoute('system_test.permission_dependent_content');
|
||||
|
@ -324,12 +350,13 @@ class PageCacheTest extends BrowserTestBase {
|
|||
$this->drupalGet($route_access_url);
|
||||
$this->assertCacheContext('user.permissions');
|
||||
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'config:user.role.authenticated');
|
||||
$this->drupalLogout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the 4xx-response cache tag is added and invalidated.
|
||||
*/
|
||||
public function testPageCacheAnonymous403404(): void {
|
||||
protected function testPageCacheAnonymous403404(): void {
|
||||
$admin_url = Url::fromRoute('system.admin');
|
||||
$invalid_url = 'foo/does_not_exist';
|
||||
$tests = [
|
||||
|
@ -400,12 +427,18 @@ class PageCacheTest extends BrowserTestBase {
|
|||
$this->assertSession()->statusCodeEquals($code);
|
||||
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
|
||||
}
|
||||
// Restore 403 and 404 caching.
|
||||
$settings['settings']['cache_ttl_4xx'] = (object) [
|
||||
'value' => 3600,
|
||||
'required' => TRUE,
|
||||
];
|
||||
$this->writeSettings($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the omit_vary_cookie setting.
|
||||
*/
|
||||
public function testPageCacheWithoutVaryCookie(): void {
|
||||
protected function testPageCacheWithoutVaryCookie(): void {
|
||||
$this->enablePageCaching();
|
||||
|
||||
$settings['settings']['omit_vary_cookie'] = (object) [
|
||||
|
@ -507,7 +540,7 @@ class PageCacheTest extends BrowserTestBase {
|
|||
/**
|
||||
* Tests that HEAD requests are treated the same as GET requests.
|
||||
*/
|
||||
public function testHead(): void {
|
||||
protected function testHead(): void {
|
||||
/** @var \GuzzleHttp\ClientInterface $client */
|
||||
$client = $this->getSession()->getDriver()->getClient()->getClient();
|
||||
|
||||
|
@ -537,7 +570,7 @@ class PageCacheTest extends BrowserTestBase {
|
|||
/**
|
||||
* Tests a cacheable response with custom cache control.
|
||||
*/
|
||||
public function testCacheableWithCustomCacheControl(): void {
|
||||
protected function testCacheableWithCustomCacheControl(): void {
|
||||
$this->enablePageCaching();
|
||||
|
||||
$this->drupalGet('/system-test/custom-cache-control');
|
||||
|
@ -548,7 +581,7 @@ class PageCacheTest extends BrowserTestBase {
|
|||
/**
|
||||
* Tests that the Cache-Control header is added by FinishResponseSubscriber.
|
||||
*/
|
||||
public function testCacheabilityOfRedirectResponses(): void {
|
||||
protected function testCacheabilityOfRedirectResponses(): void {
|
||||
$this->enablePageCaching();
|
||||
|
||||
$this->getSession()->getDriver()->getClient()->followRedirects(FALSE);
|
||||
|
@ -561,12 +594,13 @@ class PageCacheTest extends BrowserTestBase {
|
|||
$this->assertCacheMaxAge(300);
|
||||
}
|
||||
}
|
||||
$this->getSession()->getDriver()->getClient()->followRedirects(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that URLs are cached in a not normalized form.
|
||||
*/
|
||||
public function testNoUrlNormalization(): void {
|
||||
protected function testNoUrlNormalization(): void {
|
||||
// Use absolute URLs to avoid any processing.
|
||||
$url = Url::fromRoute('<front>')->setAbsolute()->toString();
|
||||
|
||||
|
|
Loading…
Reference in New Issue