protected function SelectionHandlerTest::setUp in Organic groups 8
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ Entity/ SelectionHandlerTest.php, line 86
Class
- SelectionHandlerTest
- Tests entity reference selection plugins.
Namespace
Drupal\Tests\og\Kernel\EntityCode
protected function setUp() : void {
parent::setUp();
// Add membership and config schema.
$this
->installConfig([
'og',
]);
$this
->installEntitySchema('og_membership');
$this
->installEntitySchema('user');
$this
->installEntitySchema('node');
$this
->installSchema('system', 'sequences');
// Setting up variables.
$this->groupBundle = mb_strtolower($this
->randomMachineName());
$this->groupContentBundle = mb_strtolower($this
->randomMachineName());
$this->selectionPluginManager = $this->container
->get('plugin.manager.entity_reference_selection');
// Create a group.
NodeType::create([
'type' => $this->groupBundle,
'name' => $this
->randomString(),
])
->save();
// Create a group content type.
NodeType::create([
'type' => $this->groupContentBundle,
'name' => $this
->randomString(),
])
->save();
// Define the group content as group.
Og::groupTypeManager()
->addGroup('node', $this->groupBundle);
// Add og audience field to group content.
$this->fieldDefinition = Og::createField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'node', $this->groupContentBundle);
// Get the storage of the field.
$options = [
'target_type' => $this->fieldDefinition
->getFieldStorageDefinition()
->getSetting('target_type'),
'handler' => $this->fieldDefinition
->getSetting('handler'),
'field_mode' => 'admin',
];
$this->selectionPluginManager
->getInstance($options);
$this->selectionHandler = $this->selectionPluginManager
->getSelectionHandler($this->fieldDefinition);
// Create two users.
$this->user1 = User::create([
'name' => $this
->randomString(),
]);
$this->user1
->save();
$this->user2 = User::create([
'name' => $this
->randomString(),
]);
$this->user2
->save();
}