You are here

protected function OgStandardReferenceItemTest::setUp in Organic groups 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/Entity/OgStandardReferenceItemTest.php, line 49

Class

OgStandardReferenceItemTest
Tests OgStandardReferenceItem class.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

protected function setUp() : void {
  parent::setUp();

  // Add membership and config schema.
  $this
    ->installConfig([
    'og',
  ]);
  $this
    ->installEntitySchema('entity_test');
  $this
    ->installEntitySchema('og_membership');
  $this
    ->installEntitySchema('user');
  $this
    ->installSchema('system', 'sequences');

  // Create several bundles.
  for ($i = 0; $i <= 2; $i++) {
    $bundle = EntityTest::create([
      'type' => mb_strtolower($this
        ->randomMachineName()),
      'name' => $this
        ->randomString(),
    ]);
    $bundle
      ->save();
    $this->bundles[] = $bundle
      ->id();
  }
  for ($i = 0; $i < 2; $i++) {
    $bundle = $this->bundles[$i];
    Og::groupTypeManager()
      ->addGroup('entity_test', $bundle);
    $group = EntityTest::create([
      'type' => $bundle,
    ]);
    $group
      ->save();
    $this->groups[] = $group;
  }
  $this->fieldName = strtolower($this
    ->randomMachineName());
  Og::CreateField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'entity_test', $this->bundles[2], [
    'field_name' => $this->fieldName,
  ]);
}