|
3 | 3 | namespace Tests\StaticCaching; |
4 | 4 |
|
5 | 5 | use Illuminate\Contracts\Cache\Repository; |
| 6 | +use Illuminate\Http\Request; |
6 | 7 | use Illuminate\Support\Facades\Event; |
7 | 8 | use PHPUnit\Framework\Attributes\DataProvider; |
8 | 9 | use PHPUnit\Framework\Attributes\Test; |
@@ -325,6 +326,60 @@ public static function invalidateEventProvider() |
325 | 326 | ]; |
326 | 327 | } |
327 | 328 |
|
| 329 | + #[Test] |
| 330 | + #[DataProvider('currentUrlProvider')] |
| 331 | + public function it_gets_the_current_url( |
| 332 | + array $query, |
| 333 | + array $config, |
| 334 | + string $expectedUrl |
| 335 | + ) { |
| 336 | + $request = Request::create('http://example.com/test', 'GET', $query); |
| 337 | + |
| 338 | + $cacher = $this->fileCacher($config); |
| 339 | + |
| 340 | + $this->assertEquals($expectedUrl, $cacher->getUrl($request)); |
| 341 | + } |
| 342 | + |
| 343 | + public static function currentUrlProvider() |
| 344 | + { |
| 345 | + return [ |
| 346 | + 'no query' => [ |
| 347 | + [], |
| 348 | + [], |
| 349 | + 'http://example.com/test', |
| 350 | + ], |
| 351 | + 'with query' => [ |
| 352 | + ['bravo' => 'b', 'charlie' => 'c', 'alfa' => 'a'], |
| 353 | + [], |
| 354 | + 'http://example.com/test?bravo=b&charlie=c&alfa=a', |
| 355 | + ], |
| 356 | + 'with query, ignoring query' => [ |
| 357 | + ['bravo' => 'b', 'charlie' => 'c', 'alfa' => 'a'], |
| 358 | + ['ignore_query_strings' => true], |
| 359 | + 'http://example.com/test', |
| 360 | + ], |
| 361 | + 'with query, allowed query' => [ |
| 362 | + ['bravo' => 'b', 'charlie' => 'c', 'alfa' => 'a'], |
| 363 | + ['allowed_query_strings' => ['alfa', 'bravo']], |
| 364 | + 'http://example.com/test?bravo=b&charlie=c&alfa=a', // allowed_query_strings has no effect |
| 365 | + ], |
| 366 | + 'with query, disallowed query' => [ |
| 367 | + ['bravo' => 'b', 'charlie' => 'c', 'alfa' => 'a'], |
| 368 | + ['disallowed_query_strings' => ['charlie']], |
| 369 | + 'http://example.com/test?bravo=b&charlie=c&alfa=a', // disallowed_query_strings has no effect |
| 370 | + |
| 371 | + ], |
| 372 | + 'with query, allowed and disallowed' => [ |
| 373 | + ['bravo' => 'b', 'charlie' => 'c', 'alfa' => 'a'], |
| 374 | + [ |
| 375 | + 'allowed_query_strings' => ['alfa', 'bravo'], |
| 376 | + 'disallowed_query_strings' => ['bravo'], |
| 377 | + ], |
| 378 | + 'http://example.com/test?bravo=b&charlie=c&alfa=a', // allowed_query_strings and disallowed_query_strings have no effect |
| 379 | + ], |
| 380 | + ]; |
| 381 | + } |
| 382 | + |
328 | 383 | private function cacheKey($domain) |
329 | 384 | { |
330 | 385 | return 'static-cache:'.md5($domain).'.urls'; |
|
0 commit comments