3 namespace Drupal\Tests\Core\Cache\Context;
5 use Drupal\Core\Cache\Context\IsFrontPathCacheContext;
6 use Drupal\Core\Path\PathMatcherInterface;
7 use Drupal\Tests\UnitTestCase;
10 * @coversDefaultClass \Drupal\Core\Cache\Context\IsFrontPathCacheContext
13 class IsFrontPathCacheContextTest extends UnitTestCase {
16 * @covers ::getContext
18 public function testGetContextFront() {
19 $cache_context = new IsFrontPathCacheContext($this->createPathMatcher(TRUE)->reveal());
20 $this->assertSame('is_front.1', $cache_context->getContext());
24 * @covers ::getContext
26 public function testGetContextNotFront() {
27 $cache_context = new IsFrontPathCacheContext($this->createPathMatcher(FALSE)->reveal());
28 $this->assertSame('is_front.0', $cache_context->getContext());
32 * Creates a PathMatcherInterface prophecy.
34 * @param bool $is_front
36 * @return \Prophecy\Prophecy\ObjectProphecy
38 protected function createPathMatcher($is_front) {
39 $path_matcher = $this->prophesize(PathMatcherInterface::class);
40 $path_matcher->isFrontPage()
41 ->willReturn($is_front);