public function UserGroupAccessResolverTest::testResolve in Organic groups 8
@covers ::resolve @dataProvider resolveProvider
Parameters
array $previously_added_groups: An array of test entity IDs that were added to the collection by plugins that ran previously.
array $expected_added_groups: An array of groups that are expected to be added by the plugin. If left empty it is expected that the plugin will not add any group to the collection.
array $expected_removed_groups: An array of groups that are expected to be removed by the plugin. If left empty it is expected that the plugin will not remove any group from the collection.
Overrides OgGroupResolverTestBase::testResolve
File
- tests/
src/ Unit/ Plugin/ OgGroupResolver/ UserGroupAccessResolverTest.php, line 46
Class
- UserGroupAccessResolverTest
- Tests the UserGroupAccessResolver plugin.
Namespace
Drupal\Tests\og\Unit\Plugin\OgGroupResolverCode
public function testResolve(array $previously_added_groups = [], array $expected_added_groups = [], array $expected_removed_groups = []) {
// Construct a collection of groups that were discovered by other plugins.
/** @var \Drupal\og\OgResolvedGroupCollectionInterface|\Prophecy\Prophecy\ObjectProphecy $collection */
$collection = $this
->prophesize(OgResolvedGroupCollectionInterface::class);
// It is expected that the plugin will retrieve the full set of information
// about the groups in the collection.
$test_entities = $this->testEntities;
$group_info = array_map(function ($group) use ($test_entities) {
return [
'entity' => $test_entities[$group],
];
}, $previously_added_groups);
$collection
->getGroupInfo()
->willReturn($group_info)
->shouldBeCalled();
// Add expectations for groups that should be added or removed.
foreach ($expected_added_groups as $expected_added_group) {
$collection
->addGroup($test_entities[$expected_added_group], [
'user',
])
->shouldBeCalled();
}
foreach ($expected_removed_groups as $expected_removed_group) {
$collection
->removeGroup($test_entities[$expected_removed_group])
->shouldBeCalled();
}
// Set expectations for when NO groups should be added or removed.
if (empty($expected_added_groups)) {
$collection
->addGroup()
->shouldNotBeCalled();
}
if (empty($expected_removed_groups)) {
$collection
->removeGroup()
->shouldNotBeCalled();
}
// Launch the test. Any unmet expectation will cause a failure.
$plugin = $this
->getPluginInstance();
$plugin
->resolve($collection
->reveal());
}