You are here

public function ReferenceStringIdTest::testReferencingStringIds in Organic groups 8

Test if a group that uses a string as ID can be referenced.

File

tests/src/Kernel/Entity/ReferenceStringIdTest.php, line 91

Class

ReferenceStringIdTest
Checks that groups with string IDs can be referenced.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

public function testReferencingStringIds() {

  // Create a group content entity that references the group.
  $entity = EntityTestStringId::create([
    'type' => $this->bundles[1],
    'name' => $this
      ->randomString(),
    'id' => $this
      ->randomMachineName(),
    $this->fieldName => [
      [
        'target_id' => $this->group
          ->id(),
      ],
    ],
  ]);
  $entity
    ->save();

  // Check that the group content entity is referenced.
  $references = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_test_string_id')
    ->getQuery()
    ->condition($this->fieldName, $this->group
    ->id())
    ->execute();
  $this
    ->assertEquals([
    $entity
      ->id(),
  ], array_keys($references), 'The correct group is referenced.');
}