class CalculatedGroupPermissionsTest in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Unit/CalculatedGroupPermissionsTest.php \Drupal\Tests\group\Unit\CalculatedGroupPermissionsTest
Tests the CalculatedGroupPermissions value object.
@coversDefaultClass \Drupal\group\Access\CalculatedGroupPermissions @group group
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\group\Unit\CalculatedGroupPermissionsTest
Expanded class hierarchy of CalculatedGroupPermissionsTest
File
- tests/
src/ Unit/ CalculatedGroupPermissionsTest.php, line 17
Namespace
Drupal\Tests\group\UnitView source
class CalculatedGroupPermissionsTest extends UnitTestCase {
/**
* Tests that the object values were set in the constructor.
*
* @covers ::__construct
* @covers ::getItem
* @covers ::getItems
* @covers ::getItemsByScope
*/
public function testConstructor() {
$calculated_permissions = $this
->prophesize(CalculatedGroupPermissionsInterface::class);
$item_a = new CalculatedGroupPermissionsItem(CGPII::SCOPE_GROUP_TYPE, 'foo', [
'baz',
]);
$item_b = new CalculatedGroupPermissionsItem(CGPII::SCOPE_GROUP, 1, [
'bob',
'charlie',
]);
$calculated_permissions
->getItems()
->willReturn([
$item_a,
$item_b,
]);
$calculated_permissions
->getCacheContexts()
->willReturn([
'24',
]);
$calculated_permissions
->getCacheTags()
->willReturn([
'Oct',
]);
$calculated_permissions
->getCacheMaxAge()
->willReturn(1986);
$calculated_permissions = new CalculatedGroupPermissions($calculated_permissions
->reveal());
$this
->assertSame($item_a, $calculated_permissions
->getItem(CGPII::SCOPE_GROUP_TYPE, 'foo'), 'Managed to retrieve the calculated permissions item by scope and identifier.');
$this
->assertFalse($calculated_permissions
->getItem(CGPII::SCOPE_GROUP_TYPE, '404-id-not-found'), 'Requesting a non-existent identifier fails correctly.');
$this
->assertSame([
$item_a,
$item_b,
], $calculated_permissions
->getItems(), 'Successfully retrieved all items regardless of scope.');
$this
->assertSame([
$item_a,
], $calculated_permissions
->getItemsByScope(CGPII::SCOPE_GROUP_TYPE), 'Successfully retrieved all items by scope.');
$this
->assertSame([
'24',
], $calculated_permissions
->getCacheContexts(), 'Successfully inherited all cache tags.');
$this
->assertSame([
'Oct',
], $calculated_permissions
->getCacheTags(), 'Successfully inherited all cache contexts.');
$this
->assertSame(1986, $calculated_permissions
->getCacheMaxAge(), 'Successfully inherited cache max-age.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CalculatedGroupPermissionsTest:: |
public | function | Tests that the object values were set in the constructor. | |
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. | |
UnitTestCase:: |
protected | function | 340 |