class GroupPermissionsCacheContextTest in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Unit/GroupPermissionsCacheContextTest.php \Drupal\Tests\group\Unit\GroupPermissionsCacheContextTest
Tests the user.group_permissions cache context.
@coversDefaultClass \Drupal\group\Cache\Context\GroupPermissionsCacheContext @group group
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\group\Unit\GroupPermissionsCacheContextTest
Expanded class hierarchy of GroupPermissionsCacheContextTest
File
- tests/
src/ Unit/ GroupPermissionsCacheContextTest.php, line 17
Namespace
Drupal\Tests\group\UnitView source
class GroupPermissionsCacheContextTest extends UnitTestCase {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $currentUser;
/**
* The permissions hash generator.
*
* @var \Drupal\group\Access\GroupPermissionsHashGeneratorInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $permissionsHashGenerator;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->currentUser = $this
->prophesize(AccountProxyInterface::class);
$this->permissionsHashGenerator = $this
->prophesize(GroupPermissionsHashGeneratorInterface::class);
}
/**
* Tests getting the context value for the current user.
*
* @covers ::getContext
*/
public function testGetContext() {
$this->permissionsHashGenerator
->generateHash($this->currentUser
->reveal())
->willReturn('foo');
$cache_context = new GroupPermissionsCacheContext($this->currentUser
->reveal(), $this->permissionsHashGenerator
->reveal());
$this
->assertSame('foo', $cache_context
->getContext(), 'The cache context gets its value directly from the hash generator.');
}
/**
* Tests getting the cacheable metadata from the hash generator.
*
* @covers ::getCacheableMetadata
*/
public function testGetCacheableMetadata() {
$cacheable_metadata = new CacheableMetadata();
$cacheable_metadata
->addCacheTags([
"config:group.role.foo-bar",
]);
$this->permissionsHashGenerator
->getCacheableMetadata($this->currentUser
->reveal())
->willReturn($cacheable_metadata);
$cache_context = new GroupPermissionsCacheContext($this->currentUser
->reveal(), $this->permissionsHashGenerator
->reveal());
$this
->assertEquals($cacheable_metadata, $cache_context
->getCacheableMetadata(), 'The cache context gets its cacheable metadata directly from the hash generator.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GroupPermissionsCacheContextTest:: |
protected | property | The current user. | |
GroupPermissionsCacheContextTest:: |
protected | property | The permissions hash generator. | |
GroupPermissionsCacheContextTest:: |
public | function |
Overrides UnitTestCase:: |
|
GroupPermissionsCacheContextTest:: |
public | function | Tests getting the cacheable metadata from the hash generator. | |
GroupPermissionsCacheContextTest:: |
public | function | Tests getting the context value for the current user. | |
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. | |
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. |