You are here

protected function ResourceTestBase::getData in JSON:API 8.2

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::getData()
ResourceTestBase::testCollection in tests/src/Functional/ResourceTestBase.php
Tests GETting a collection of resources.

File

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

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getData() {
  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());
}