function RefinableCalculatedPermissionsTest::testAddItem
Same name in other branches
- 10 core/tests/Drupal/Tests/Core/Session/RefinableCalculatedPermissionsTest.php \Drupal\Tests\Core\Session\RefinableCalculatedPermissionsTest::testAddItem()
Tests the addition of a calculated permissions item.
File
-
core/
tests/ Drupal/ Tests/ Core/ Session/ RefinableCalculatedPermissionsTest.php, line 26
Class
- RefinableCalculatedPermissionsTest
- Tests the RefinableCalculatedPermissions class.
Namespace
Drupal\Tests\Core\SessionCode
public function testAddItem() : void {
$calculated_permissions = new RefinableCalculatedPermissions();
$scope = 'some_scope';
$item = new CalculatedPermissionsItem([
'bar',
], FALSE, $scope, 'foo');
$calculated_permissions->addItem($item);
$this->assertSame($item, $calculated_permissions->getItem($scope, 'foo'), 'Managed to retrieve the calculated permissions item.');
$item = new CalculatedPermissionsItem([
'baz',
], FALSE, $scope, 'foo');
$calculated_permissions->addItem($item);
$this->assertEquals([
'bar',
'baz',
], $calculated_permissions->getItem($scope, 'foo')
->getPermissions(), 'Adding a calculated permissions item that was already in the list merges them.');
$item = new CalculatedPermissionsItem([
'cat',
], TRUE, $scope, 'foo');
$calculated_permissions->addItem($item);
$this->assertEquals([], $calculated_permissions->getItem($scope, 'foo')
->getPermissions(), 'Merging in a calculated permissions item with admin rights empties the permissions.');
$this->assertTrue($calculated_permissions->getItem($scope, 'foo')
->isAdmin(), 'Merging in a calculated permissions item with admin rights flags the result as having admin rights.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.