You are here

protected function ResourceTestBase::getEntityCollection in JSON:API 8

Sets up a collection of entities of the same type for testing.

Return value

\Drupal\Core\Entity\EntityInterface[] The collection of entities to test.

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to ResourceTestBase::getEntityCollection()
ResourceTestBase::testCollection in tests/src/Functional/ResourceTestBase.php
Tests GETting a collection of resources.

File

tests/src/Functional/ResourceTestBase.php, line 304

Class

ResourceTestBase
Subclass this for every JSON API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getEntityCollection() {
  if ($this->entityStorage
    ->getQuery()
    ->count()
    ->execute() < 2) {
    $this
      ->createAnotherEntity('two');
  }
  $query = $this->entityStorage
    ->getQuery()
    ->sort($this->entity
    ->getEntityType()
    ->getKey('id'));
  return $this->entityStorage
    ->loadMultiple($query
    ->execute());
}