Version 1
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Cache / Context / PathParentCacheContextTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Cache\Context;
4
5 use Drupal\Core\Cache\Context\PathParentCacheContext;
6 use Drupal\Tests\UnitTestCase;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\HttpFoundation\RequestStack;
9
10 /**
11  * @coversDefaultClass \Drupal\Core\Cache\Context\PathParentCacheContext
12  * @group Cache
13  */
14 class PathParentCacheContextTest extends UnitTestCase {
15
16   /**
17    * @covers ::getContext
18    *
19    * @dataProvider providerTestGetContext
20    */
21   public function testGetContext($original_path, $context) {
22     $request_stack = new RequestStack();
23     $request = Request::create($original_path);
24     $request_stack->push($request);
25     $cache_context = new PathParentCacheContext($request_stack);
26     $this->assertSame($cache_context->getContext(), $context);
27   }
28
29   /**
30    * Provides a list of paths and expected cache contexts.
31    */
32   public function providerTestGetContext() {
33     return [
34       ['/some/path', 'some'],
35       ['/some/other-path', 'some'],
36       ['/some/other/path', 'some/other'],
37       ['/some/other/path?q=foo&b=bar', 'some/other'],
38       ['/some', ''],
39       ['/', ''],
40     ];
41   }
42
43 }