public function RefinableCalculatedGroupPermissionsTest::testMerge in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Unit/RefinableCalculatedGroupPermissionsTest.php \Drupal\Tests\group\Unit\RefinableCalculatedGroupPermissionsTest::testMerge()
Tests merging in another CalculatedGroupPermissions object.
@covers ::merge @depends testAddItem
File
- tests/
src/ Unit/ RefinableCalculatedGroupPermissionsTest.php, line 102
Class
- RefinableCalculatedGroupPermissionsTest
- Tests the RefinableCalculatedGroupPermissions class.
Namespace
Drupal\Tests\group\UnitCode
public function testMerge() {
$cache_context_manager = $this
->prophesize(CacheContextsManager::class);
$cache_context_manager
->assertValidTokens(Argument::any())
->willReturn(TRUE);
$container = $this
->prophesize(ContainerInterface::class);
$container
->get('cache_contexts_manager')
->willReturn($cache_context_manager
->reveal());
\Drupal::setContainer($container
->reveal());
$item_a = new CalculatedGroupPermissionsItem(CGPII::SCOPE_GROUP_TYPE, 'foo', [
'baz',
]);
$item_b = new CalculatedGroupPermissionsItem(CGPII::SCOPE_GROUP_TYPE, 'foo', [
'bob',
'charlie',
]);
$item_c = new CalculatedGroupPermissionsItem(CGPII::SCOPE_GROUP_TYPE, 'bar', []);
$item_d = new CalculatedGroupPermissionsItem(CGPII::SCOPE_GROUP_TYPE, 'baz', []);
$calculated_permissions = new RefinableCalculatedGroupPermissions();
$calculated_permissions
->addItem($item_a)
->addItem($item_c)
->addCacheContexts([
'foo',
])
->addCacheTags([
'foo',
]);
$other = new RefinableCalculatedGroupPermissions();
$other
->addItem($item_b)
->addItem($item_d)
->addCacheContexts([
'bar',
])
->addCacheTags([
'bar',
]);
$calculated_permissions
->merge($other);
$this
->assertNotFalse($calculated_permissions
->getItem(CGPII::SCOPE_GROUP_TYPE, 'bar'), 'Original item that did not conflict was kept.');
$this
->assertNotFalse($calculated_permissions
->getItem(CGPII::SCOPE_GROUP_TYPE, 'baz'), 'Incoming item that did not conflict was added.');
$this
->assertSame([
'baz',
'bob',
'charlie',
], $calculated_permissions
->getItem(CGPII::SCOPE_GROUP_TYPE, 'foo')
->getPermissions(), 'Permissions were merged properly.');
$this
->assertSame([
'bar',
'foo',
], $calculated_permissions
->getCacheContexts(), 'Cache contexts were merged properly');
$this
->assertSame([
'bar',
'foo',
], $calculated_permissions
->getCacheTags(), 'Cache tags were merged properly');
}