public function SelectionHandlerTest::testSelectionHandlerResults in Organic groups 8
Testing OG selection handler results.
We need to verify that each user gets the groups they own in the normal widget and the other users' groups in the other groups widget and vice versa.
File
- tests/
src/ Kernel/ Entity/ SelectionHandlerTest.php, line 156
Class
- SelectionHandlerTest
- Tests entity reference selection plugins.
Namespace
Drupal\Tests\og\Kernel\EntityCode
public function testSelectionHandlerResults() {
$user1_groups = $this
->createGroups(2, $this->user1);
$user2_groups = $this
->createGroups(2, $this->user2);
// Check that users get the groups they manage.
$this
->setCurrentAccount($this->user1);
$groups = $this->selectionHandler
->getReferenceableEntities();
$this
->assertEquals($user1_groups, array_keys($groups[$this->groupBundle]));
$this
->setCurrentAccount($this->user2);
$groups = $this->selectionHandler
->getReferenceableEntities();
$this
->assertEquals($user2_groups, array_keys($groups[$this->groupBundle]));
// Check the other groups.
$options = [
'target_type' => $this->fieldDefinition
->getFieldStorageDefinition()
->getSetting('target_type'),
'handler' => $this->fieldDefinition
->getSetting('handler'),
'field_mode' => 'admin',
];
$this->selectionHandler = $this->selectionPluginManager
->getInstance($options);
$this
->setCurrentAccount($this->user1);
$groups = $this->selectionHandler
->getReferenceableEntities();
$this
->assertEquals($user2_groups, array_keys($groups[$this->groupBundle]));
$this
->setCurrentAccount($this->user2);
$groups = $this->selectionHandler
->getReferenceableEntities();
$this
->assertEquals($user1_groups, array_keys($groups[$this->groupBundle]));
}