class OgGroupContextCacheContextTest in Organic groups 8
Tests the OG group context cache context.
@group og @coversDefaultClass \Drupal\og\Cache\Context\OgGroupContextCacheContext
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\OgGroupContextCacheContextTest
- class \Drupal\Tests\og\Unit\Cache\Context\OgContextCacheContextTestBase
- class \Drupal\Tests\og\Unit\Cache\Context\OgCacheContextTestBase
Expanded class hierarchy of OgGroupContextCacheContextTest
File
- tests/
src/ Unit/ Cache/ Context/ OgGroupContextCacheContextTest.php, line 15
Namespace
Drupal\Tests\og\Unit\Cache\ContextView source
class OgGroupContextCacheContextTest extends OgContextCacheContextTestBase {
/**
* Tests getting cache context when there is no matching group on the route.
*
* @covers ::getContext
*/
public function testWithoutContext() {
$this
->expectGroupContext();
$result = $this
->getContextResult();
$this
->assertEquals(OgGroupContextCacheContext::NO_CONTEXT, $result);
}
/**
* {@inheritdoc}
*/
protected function setupExpectedContext($context) {
if ($context) {
$this->group
->getEntityTypeId()
->willReturn($context['entity_type'])
->shouldBeCalled();
$this->group
->id()
->willReturn($context['id'])
->shouldBeCalled();
$this
->expectGroupContext($this->group
->reveal());
}
else {
$this
->expectGroupContext();
}
}
/**
* {@inheritdoc}
*/
protected function getCacheContext() {
return new OgGroupContextCacheContext($this->ogContext
->reveal());
}
/**
* {@inheritdoc}
*/
public function contextProvider() {
return [
// Test the expected result if no valid group exists in the active
// context.
[
FALSE,
OgGroupContextCacheContext::NO_CONTEXT,
],
// Test having an entity with a numeric ID present in the active context.
[
[
'entity_type' => 'node',
'id' => 3,
],
'node:3',
],
// Test having an entity with a string ID present in the active context.
[
[
'entity_type' => 'entity_test',
'id' => 'Shibo Yangcong-San',
],
'entity_test:Shibo Yangcong-San',
],
];
}
}
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:: |
protected | function |
Overrides UnitTestCase:: |
1 |
OgContextCacheContextTestBase:: |
public | function | Tests the result of the cache context service with active context objects. | |
OgGroupContextCacheContextTest:: |
public | function |
Provides test data for the test with active context objects. Overrides OgContextCacheContextTestBase:: |
|
OgGroupContextCacheContextTest:: |
protected | function |
Returns the instantiated cache context service which is being tested. Overrides OgCacheContextTestBase:: |
|
OgGroupContextCacheContextTest:: |
protected | function |
Set up expectations for tests that have an active context object. Overrides OgContextCacheContextTestBase:: |
|
OgGroupContextCacheContextTest:: |
public | function |
Tests getting cache context when there is no matching group on the route. 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. |