Fix wrong detection of Page Cache timeout (TTL) (#20)

Use the earliest instead of latest timeout.
Extend tests to cover the bug.

Relates: #10506
This commit is contained in:
Daniel Siepmann 2023-05-24 09:45:15 +02:00 committed by GitHub
parent a122f515d8
commit d6d3330bd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 1 deletions

View file

@ -120,7 +120,7 @@ class PageCacheTimeout implements SingletonInterface
$newTimeout <= $now $newTimeout <= $now
|| ( || (
$this->timeout instanceof DateTimeImmutable $this->timeout instanceof DateTimeImmutable
&& $this->timeout >= $newTimeout && $this->timeout <= $newTimeout
) )
) { ) {
return; return;

View file

@ -174,6 +174,56 @@ class CacheTest extends AbstractTestCase
self::assertCacheHeaders($end, $response); self::assertCacheHeaders($end, $response);
} }
/**
* @test
*/
public function usesEarliestTimeout(): void
{
$end = (new DateTimeImmutable('now', new DateTimeZone('UTC')))->modify('+2 hours');
(new PhpDataSet())->import([
'tx_events_domain_model_event' => [
[
'uid' => '1',
'pid' => '2',
'title' => 'Test Event 1',
],
[
'uid' => '2',
'pid' => '2',
'title' => 'Test Event 2',
],
],
'tx_events_domain_model_date' => [
[
'pid' => '2',
'event' => '1',
'start' => $end->format('U'),
'end' => '0',
],
[
'pid' => '2',
'event' => '2',
'start' => $end->modify('+2 hours')->format('U'),
'end' => '0',
],
],
]);
$response = $this->executeFrontendRequest($this->getRequestWithSleep([
'plugin.' => [
'tx_events.' => [
'settings.' => [
'upcoming' => 1,
],
],
],
]));
self::assertSame(200, $response->getStatusCode());
self::assertCacheHeaders($end, $response);
}
/** /**
* @test * @test
*/ */