|
8 | 8 | use GuzzleHttp\Psr7\Response; |
9 | 9 | use Illuminate\Support\Facades\Queue; |
10 | 10 | use PHPUnit\Framework\Attributes\Test; |
| 11 | +use Statamic\Console\Commands\Concerns\NormalizesPaginationHeader; |
11 | 12 | use Statamic\Console\Commands\StaticWarmJob; |
12 | 13 | use Tests\TestCase; |
13 | 14 |
|
@@ -90,4 +91,55 @@ public function subsequent_paginated_pages_dont_dispatch_static_warm_jobs() |
90 | 91 | // The first page is responsible for dispatchin jobs. Not subsequent pages. |
91 | 92 | Queue::assertNothingPushed(); |
92 | 93 | } |
| 94 | + |
| 95 | + #[Test] |
| 96 | + public function it_dispatches_paginated_jobs_when_the_pagination_header_is_folded_into_one_line() |
| 97 | + { |
| 98 | + Queue::fake(); |
| 99 | + |
| 100 | + // A proxy or CDN may coalesce the repeated header into a single comma-joined line. |
| 101 | + $mock = new MockHandler([ |
| 102 | + (new Response(200))->withHeader('X-Statamic-Pagination', '1, 3, page'), |
| 103 | + ]); |
| 104 | + |
| 105 | + $handlerStack = HandlerStack::create($mock); |
| 106 | + |
| 107 | + $job = new StaticWarmJob(new Request('GET', '/blog'), ['handler' => $handlerStack]); |
| 108 | + |
| 109 | + $job->handle(); |
| 110 | + |
| 111 | + Queue::assertPushed(StaticWarmJob::class, function (StaticWarmJob $job) { |
| 112 | + return $job->request->getUri()->getQuery() === 'page=1'; |
| 113 | + }); |
| 114 | + |
| 115 | + Queue::assertPushed(StaticWarmJob::class, function (StaticWarmJob $job) { |
| 116 | + return $job->request->getUri()->getQuery() === 'page=2'; |
| 117 | + }); |
| 118 | + |
| 119 | + Queue::assertPushed(StaticWarmJob::class, function (StaticWarmJob $job) { |
| 120 | + return $job->request->getUri()->getQuery() === 'page=3'; |
| 121 | + }); |
| 122 | + } |
| 123 | + |
| 124 | + #[Test] |
| 125 | + public function it_keeps_a_page_name_that_contains_a_comma() |
| 126 | + { |
| 127 | + $parser = new class |
| 128 | + { |
| 129 | + use NormalizesPaginationHeader; |
| 130 | + |
| 131 | + public function parse($response) |
| 132 | + { |
| 133 | + return $this->paginationHeader($response); |
| 134 | + } |
| 135 | + }; |
| 136 | + |
| 137 | + // Three separate header values, as set by the static caching middleware. |
| 138 | + $separate = (new Response(200))->withHeader('X-Statamic-Pagination', ['current' => 1, 'total' => 3, 'name' => 'pa,ge']); |
| 139 | + $this->assertSame([1, 3, 'pa,ge'], $parser->parse($separate)); |
| 140 | + |
| 141 | + // The same header folded into one comma-joined line by a proxy. |
| 142 | + $folded = (new Response(200))->withHeader('X-Statamic-Pagination', '1, 3, pa,ge'); |
| 143 | + $this->assertSame([1, 3, 'pa,ge'], $parser->parse($folded)); |
| 144 | + } |
93 | 145 | } |
0 commit comments