IsFrontPathCacheContextTest.php

Same filename in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Cache/Context/IsFrontPathCacheContextTest.php
  2. 10 core/tests/Drupal/Tests/Core/Cache/Context/IsFrontPathCacheContextTest.php
  3. 11.x core/tests/Drupal/Tests/Core/Cache/Context/IsFrontPathCacheContextTest.php

Namespace

Drupal\Tests\Core\Cache\Context

File

core/tests/Drupal/Tests/Core/Cache/Context/IsFrontPathCacheContextTest.php

View source
<?php

namespace Drupal\Tests\Core\Cache\Context;

use Drupal\Core\Cache\Context\IsFrontPathCacheContext;
use Drupal\Core\Path\PathMatcherInterface;
use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\Core\Cache\Context\IsFrontPathCacheContext
 * @group Cache
 */
class IsFrontPathCacheContextTest extends UnitTestCase {
    
    /**
     * @covers ::getContext
     */
    public function testGetContextFront() {
        $cache_context = new IsFrontPathCacheContext($this->createPathMatcher(TRUE)
            ->reveal());
        $this->assertSame('is_front.1', $cache_context->getContext());
    }
    
    /**
     * @covers ::getContext
     */
    public function testGetContextNotFront() {
        $cache_context = new IsFrontPathCacheContext($this->createPathMatcher(FALSE)
            ->reveal());
        $this->assertSame('is_front.0', $cache_context->getContext());
    }
    
    /**
     * Creates a PathMatcherInterface prophecy.
     *
     * @param bool $is_front
     *   Whether the page is the front page.
     *
     * @return \Prophecy\Prophecy\ObjectProphecy
     */
    protected function createPathMatcher($is_front) {
        $path_matcher = $this->prophesize(PathMatcherInterface::class);
        $path_matcher->isFrontPage()
            ->willReturn($is_front);
        return $path_matcher;
    }

}

Classes

Title Deprecated Summary
IsFrontPathCacheContextTest @coversDefaultClass \Drupal\Core\Cache\Context\IsFrontPathCacheContext @group Cache

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.