public function OgResolvedGroupCollectionTest::testHasGroup in Organic groups 8
Tests if it is possible to check if a group exists in the collection.
@covers ::hasGroup
File
- tests/
src/ Unit/ OgResolvedGroupCollectionTest.php, line 203
Class
- OgResolvedGroupCollectionTest
- Tests the collecting of resolved groups to pass as a route context.
Namespace
Drupal\Tests\og\UnitCode
public function testHasGroup() {
$collection = new OgResolvedGroupCollection();
// Randomly select half of the test groups and add them.
$random_selection = array_rand($this->groups, count($this->groups) / 2);
foreach ($random_selection as $key) {
$collection
->addGroup($this->groups[$key]);
}
// Loop over all groups and check that ::hasGroup() returns the correct
// result.
foreach ($this->groups as $key => $group) {
$this
->assertEquals(in_array($key, $random_selection), $collection
->hasGroup($group));
}
}