-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remote cache filtered CSV downloads for one hour (#4192)
- Loading branch information
Showing
20 changed files
with
157 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
modules/common/tests/src/Kernel/CacheableResponseTraitTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\common\Kernel; | ||
|
||
use Drupal\KernelTests\KernelTestBase; | ||
use Drupal\common\CacheableResponseTrait; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @coversDefaultClass \Drupal\common\CacheableResponseTrait | ||
* | ||
* @group dkan | ||
* @group common | ||
* @group kernel | ||
*/ | ||
class CacheableResponseTraitTest extends KernelTestBase { | ||
|
||
protected static $modules = [ | ||
'common', | ||
'system', | ||
]; | ||
|
||
public function testCacheableResponse() { | ||
// Check the defaults from both Response and the trait. | ||
$no_cache_controller = new ControllerUsesCacheableResponseTrait(); | ||
$response = $no_cache_controller->traitAddCacheHeaders(new Response()); | ||
$this->assertStringContainsString('no-cache', $response->headers->get('Cache-Control')); | ||
$this->assertStringContainsString('private', $response->headers->get('Cache-Control')); | ||
|
||
// Set the max age in config. | ||
$config_max_age = 999; | ||
$this->config('system.performance')->set('cache.page.max_age', $config_max_age)->save(); | ||
$config_controller = new ControllerUsesCacheableResponseTrait(); | ||
$response = $config_controller->traitAddCacheHeaders(new Response()); | ||
$this->assertEquals($config_max_age, $response->getMaxAge()); | ||
$this->assertStringContainsString('public', $response->headers->get('Cache-Control')); | ||
|
||
// Set the max age in the controller object. This should override the | ||
// config. | ||
$max_time = 23; | ||
$max_time_controller = new ControllerUsesCacheableResponseTrait(); | ||
$max_time_controller->traitSetMaxAgeProperty($max_time); | ||
$response = $max_time_controller->traitAddCacheHeaders(new Response()); | ||
$this->assertEquals($max_time, $response->getMaxAge()); | ||
$this->assertStringContainsString('public', $response->headers->get('Cache-Control')); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Make a stub class because it's less cumbersome than using mocking. | ||
*/ | ||
class ControllerUsesCacheableResponseTrait { | ||
use CacheableResponseTrait; | ||
|
||
public function traitSetMaxAgeProperty(int $max_age) { | ||
$this->cacheMaxAge = $max_age; | ||
} | ||
|
||
public function traitAddCacheHeaders(Response $response): Response { | ||
return $this->addCacheHeaders($response); | ||
} | ||
|
||
public function traitSetCacheMaxAge() { | ||
$this->setCacheMaxAge(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 8 additions & 2 deletions
10
modules/frontend/tests/src/Unit/Controller/ControllerPageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters