protected function ReferenceStringIdTest::setUp in Organic groups 8
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ Entity/ ReferenceStringIdTest.php, line 48
Class
- ReferenceStringIdTest
- Checks that groups with string IDs can be referenced.
Namespace
Drupal\Tests\og\Kernel\EntityCode
protected function setUp() : void {
parent::setUp();
// Add membership and config schema.
$this
->installConfig([
'og',
]);
$this
->installEntitySchema('entity_test_string_id');
$this
->installEntitySchema('og_membership');
$this
->installEntitySchema('user');
$this
->installSchema('system', 'sequences');
// Create two bundles, one will serve as group, the other as group content.
for ($i = 0; $i < 2; $i++) {
$bundle = EntityTestStringId::create([
'type' => mb_strtolower($this
->randomMachineName()),
'name' => $this
->randomString(),
'id' => $this
->randomMachineName(),
]);
$bundle
->save();
$this->bundles[] = $bundle
->id();
}
// Create a group with a string as an ID.
$group = EntityTestStringId::create([
'type' => $this->bundles[0],
'id' => $this
->randomMachineName(),
]);
$group
->save();
$this->group = $group;
// Let OG mark the group entity type as a group.
Og::groupTypeManager()
->addGroup('entity_test_string_id', $this->bundles[0]);
// Add a group audience field to the second bundle, this will turn it into a
// group content type.
$this->fieldName = strtolower($this
->randomMachineName());
Og::CreateField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'entity_test_string_id', $this->bundles[1], [
'field_name' => $this->fieldName,
]);
}