diff --git a/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php b/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php index 583e3695d9..61652ba0f6 100644 --- a/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\views\Functional\Plugin; use Drupal\Core\Url; +use Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\Tests\views\Functional\ViewTestBase; @@ -222,4 +223,52 @@ public function testArgumentDefaultQueryParameter() { $this->assertEqual($view->argument['type']->getDefaultArgument(), 'page'); } + /** + * Tests the cacheability of the date argument default. + */ + public function testArgumentDefaultCacheability() { + // Create page for testing. + $view = Views::getView('test_argument_default_date'); + $view->setDisplay(); + $view->newDisplay('page', 'Page', 'page_1'); + $view->displayHandlers->get('page_1')->overrideOption('path', 'path-page-1'); + $view->displayHandlers->get('page_1')->overrideOption('cache', [ + 'type' => 'time', + 'options' => [ + // To eliminate UNCACHEABLE from the page as is. + 'results_lifespan' => '10000', + ], + ]); + $view->save(); + + $this->container->get('module_installer')->uninstall(['page_cache']); + + // Check that the page is not cached with date argument default. + $this->drupalGet('path-page-1'); + $this->assertSession()->statusCodeEquals(200); + $this->assertEquals('UNCACHEABLE', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER)); + // Double check. + $this->drupalGet('path-page-1'); + $this->assertEquals('UNCACHEABLE', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER)); + + // Change the argument to some cached option. + $view = Views::getView('test_argument_default_date'); + $view->setDisplay(); + $view->displayHandlers->get('page_1')->overrideOption('arguments', [ + 'null' => [ + 'id' => 'null', + 'table' => 'views', + 'field' => 'null', + ], + ]); + $view->save(); + + // Check that the page is cached without date argument default. + $this->drupalGet('path-page-1'); + $this->assertSession()->statusCodeEquals(200); + $this->assertEquals('MISS', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER)); + $this->drupalGet('path-page-1'); + $this->assertEquals('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER)); + } + }