function ResourceTestBase::getData

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getData()
  2. 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getData()
  3. 11.x 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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.