1<?php 2 3namespace Drupal\Tests\Core\Cache\Context; 4 5use Drupal\Core\Cache\Context\PathParentCacheContext; 6use Drupal\Tests\UnitTestCase; 7use Symfony\Component\HttpFoundation\Request; 8use Symfony\Component\HttpFoundation\RequestStack; 9 10/** 11 * @coversDefaultClass \Drupal\Core\Cache\Context\PathParentCacheContext 12 * @group Cache 13 */ 14class 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} 44