You are here

protected function ResourceTestBase::getData in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getData()

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 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Tests GETting a collection of resources.

File

core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php, line 357

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());
}