You are here

public function OgStandardReferenceItemTest::testStandardReference in Organic groups 8

Testing referencing of non-user entity to groups.

File

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

Class

OgStandardReferenceItemTest
Tests OgStandardReferenceItem class.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

public function testStandardReference() {
  $groups_query = function ($gid) {
    return $this->container
      ->get('entity_type.manager')
      ->getStorage('entity_test')
      ->getQuery()
      ->condition($this->fieldName, $gid)
      ->execute();
  };
  $entity = EntityTest::create([
    'type' => $this->bundles[2],
    'name' => $this
      ->randomString(),
  ]);
  $entity
    ->save();
  $this
    ->assertEmpty($groups_query($this->groups[0]
    ->id()));
  $entity = EntityTest::create([
    'type' => $this->bundles[2],
    'name' => $this
      ->randomString(),
    $this->fieldName => [
      [
        'target_id' => $this->groups[1]
          ->id(),
      ],
    ],
  ]);
  $entity
    ->save();
  $this
    ->assertEmpty($groups_query($this->groups[0]
    ->id()));
  $this
    ->assertEquals(array_keys($groups_query($this->groups[1]
    ->id())), [
    $entity
      ->id(),
  ]);
}