class OgMembershipStateCacheContextTest in Organic groups 8
Tests OG membership state cache context.
@group og @coversDefaultClass \Drupal\og\Cache\Context\OgMembershipStateCacheContext
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\og\Unit\Cache\Context\OgCacheContextTestBase
- class \Drupal\Tests\og\Unit\Cache\Context\OgContextCacheContextTestBase
- class \Drupal\Tests\og\Unit\Cache\Context\OgMembershipStateCacheContextTest
- class \Drupal\Tests\og\Unit\Cache\Context\OgContextCacheContextTestBase
- class \Drupal\Tests\og\Unit\Cache\Context\OgCacheContextTestBase
Expanded class hierarchy of OgMembershipStateCacheContextTest
File
- tests/
src/ Unit/ Cache/ Context/ OgMembershipStateCacheContextTest.php, line 18
Namespace
Drupal\Tests\og\Unit\Cache\ContextView source
class OgMembershipStateCacheContextTest extends OgContextCacheContextTestBase {
/**
* The OG membership entity.
*
* @var \Drupal\og\OgMembershipInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $membership;
/**
* The membership manager service.
*
* @var \Drupal\og\MembershipManagerInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $membershipManager;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $user;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->user = $this
->prophesize(AccountInterface::class);
$this->membership = $this
->prophesize(OgMembershipInterface::class);
$this->membershipManager = $this
->prophesize(MembershipManagerInterface::class);
}
/**
* {@inheritdoc}
*/
public function testWithoutContext() {
$this
->expectGroupContext();
$result = $this
->getContextResult();
$this
->assertEquals(OgMembershipStateCacheContext::NO_CONTEXT, $result);
}
/**
* {@inheritdoc}
*/
protected function setupExpectedContext($context) {
$this
->expectGroupContext($this->group
->reveal());
$this
->expectMembership($context);
}
/**
* {@inheritdoc}
*/
protected function getCacheContext() {
return new OgMembershipStateCacheContext($this->user
->reveal(), $this->ogContext
->reveal(), $this->membershipManager
->reveal());
}
/**
* Sets an expectation that the current user has the given membership state.
*
* @param string|false $state
* The membership state, or FALSE if the user is not a member.
*/
protected function expectMembership($state) {
// If the user is a member, it is expected that the membership state will be
// retrieved.
if ($state) {
$this->membership
->getState()
->willReturn($state);
$state = $this->membership;
}
// It is expected that the user membership will be retrieved, of any
// possible membership state.
$states = [
OgMembershipInterface::STATE_ACTIVE,
OgMembershipInterface::STATE_PENDING,
OgMembershipInterface::STATE_BLOCKED,
];
$this->membershipManager
->getMembership($this->group
->reveal(), $this->user
->reveal()
->id(), $states)
->willReturn($state);
}
/**
* {@inheritdoc}
*/
public function contextProvider() {
return [
[
FALSE,
OgMembershipStateCacheContext::NO_CONTEXT,
],
[
OgMembershipInterface::STATE_ACTIVE,
OgMembershipInterface::STATE_ACTIVE,
],
[
OgMembershipInterface::STATE_PENDING,
OgMembershipInterface::STATE_PENDING,
],
[
OgMembershipInterface::STATE_BLOCKED,
OgMembershipInterface::STATE_BLOCKED,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OgCacheContextTestBase:: |
protected | function | Return the context result. | |
OgContextCacheContextTestBase:: |
protected | property | A mocked group entity. | |
OgContextCacheContextTestBase:: |
protected | property | The mocked OG context service. | |
OgContextCacheContextTestBase:: |
protected | function | Sets an expectation that OgContext will return the given group. | |
OgContextCacheContextTestBase:: |
public | function | Tests the result of the cache context service with active context objects. | |
OgMembershipStateCacheContextTest:: |
protected | property | The OG membership entity. | |
OgMembershipStateCacheContextTest:: |
protected | property | The membership manager service. | |
OgMembershipStateCacheContextTest:: |
protected | property | The current user. | |
OgMembershipStateCacheContextTest:: |
public | function |
Provides test data for the test with active context objects. Overrides OgContextCacheContextTestBase:: |
|
OgMembershipStateCacheContextTest:: |
protected | function | Sets an expectation that the current user has the given membership state. | |
OgMembershipStateCacheContextTest:: |
protected | function |
Returns the instantiated cache context service which is being tested. Overrides OgCacheContextTestBase:: |
|
OgMembershipStateCacheContextTest:: |
protected | function |
Overrides OgContextCacheContextTestBase:: |
|
OgMembershipStateCacheContextTest:: |
protected | function |
Set up expectations for tests that have an active context object. Overrides OgContextCacheContextTestBase:: |
|
OgMembershipStateCacheContextTest:: |
public | function |
Tests the result of the cache context service without active context. Overrides OgContextCacheContextTestBase:: |
|
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. |