class RouteGroupCacheContextTest in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Unit/RouteGroupCacheContextTest.php \Drupal\Tests\group\Unit\RouteGroupCacheContextTest
Tests the route.group cache context.
@coversDefaultClass \Drupal\group\Cache\Context\RouteGroupCacheContext @group group
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\group\Unit\RouteGroupCacheContextTest
Expanded class hierarchy of RouteGroupCacheContextTest
File
- tests/
src/ Unit/ RouteGroupCacheContextTest.php, line 20
Namespace
Drupal\Tests\group\UnitView source
class RouteGroupCacheContextTest extends UnitTestCase {
/**
* The current route match object.
*
* @var \Drupal\Core\Routing\RouteMatchInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $currentRouteMatch;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->currentRouteMatch = $this
->prophesize(RouteMatchInterface::class);
$this->entityTypeManager = $this
->prophesize(EntityTypeManagerInterface::class);
}
/**
* Tests getting the context value when there is no group on the route.
*
* @covers ::getContext
*/
public function testGetContextNoGroup() {
$this->currentRouteMatch
->getParameter('group')
->willReturn(NULL);
$this->currentRouteMatch
->getRouteName()
->willReturn('foo');
$cache_context = new RouteGroupCacheContext($this->currentRouteMatch
->reveal(), $this->entityTypeManager
->reveal());
$this
->assertSame('group.none', $cache_context
->getContext());
}
/**
* Tests getting the context value when there is a group on the route.
*
* @covers ::getContext
*/
public function testGetContextWithGroup() {
$group = $this
->prophesize(GroupInterface::class);
$group
->id()
->willReturn(1);
$this->currentRouteMatch
->getParameter('group')
->willReturn($group
->reveal());
$cache_context = new RouteGroupCacheContext($this->currentRouteMatch
->reveal(), $this->entityTypeManager
->reveal());
$this
->assertSame(1, $cache_context
->getContext());
}
/**
* Tests getting the context value when on the group add form route.
*
* @covers ::getContext
*/
public function testGetContextOnGroupAddForm() {
$group = $this
->prophesize(GroupInterface::class);
$group
->id()
->willReturn(NULL);
$group
->bundle()
->willReturn('foo');
$group_type = $this
->prophesize(GroupTypeInterface::class);
$group_type
->id()
->willReturn('foo');
$this->currentRouteMatch
->getParameter('group')
->willReturn(NULL);
$this->currentRouteMatch
->getParameter('group_type')
->willReturn($group_type
->reveal());
$this->currentRouteMatch
->getRouteName()
->willReturn('entity.group.add_form');
$storage = $this
->prophesize(ContentEntityStorageInterface::class);
$storage
->create([
'type' => 'foo',
])
->willReturn($group
->reveal());
$this->entityTypeManager
->getStorage('group')
->willReturn($storage
->reveal());
$cache_context = new RouteGroupCacheContext($this->currentRouteMatch
->reveal(), $this->entityTypeManager
->reveal());
$this
->assertSame('foo', $cache_context
->getContext());
}
/**
* Tests getting the cacheable metadata for the cache context.
*
* @covers ::getCacheableMetadata
*/
public function testGetCacheableMetadata() {
$cache_context = new RouteGroupCacheContext($this->currentRouteMatch
->reveal(), $this->entityTypeManager
->reveal());
$this
->assertEquals(new CacheableMetadata(), $cache_context
->getCacheableMetadata());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RouteGroupCacheContextTest:: |
protected | property | The current route match object. | |
RouteGroupCacheContextTest:: |
protected | property | The entity type manager service. | |
RouteGroupCacheContextTest:: |
public | function |
Overrides UnitTestCase:: |
|
RouteGroupCacheContextTest:: |
public | function | Tests getting the cacheable metadata for the cache context. | |
RouteGroupCacheContextTest:: |
public | function | Tests getting the context value when there is no group on the route. | |
RouteGroupCacheContextTest:: |
public | function | Tests getting the context value when on the group add form route. | |
RouteGroupCacheContextTest:: |
public | function | Tests getting the context value when there is a group on the route. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |