public function JsonApiDefaultsFunctionalTest::testPagination in JSON:API Extras 8.3
Checks standard pagination and page limit overrides.
Throws
\Drupal\Core\Entity\EntityStorageException
File
- modules/jsonapi_defaults/ tests/ src/ Functional/ JsonApiDefaultsFunctionalTest.php, line 124 
Class
- JsonApiDefaultsFunctionalTest
- The test class for the JSON API Defaults functionality.
Namespace
Drupal\Tests\jsonapi_defaults\FunctionalCode
public function testPagination() {
  /** @var \Drupal\Component\Serialization\JsonapiResourceConfig $resource_config */
  // Unset filters of resource config in this test as those limit the results.
  $this
    ->setResouceConfigValue([
    'default_filter' => [],
  ]);
  $this
    ->createDefaultContent(300, 1, FALSE, TRUE, static::IS_NOT_MULTILINGUAL);
  // 1. Check pagination using default page limit of jsonapi.
  $response = $this
    ->drupalGet('/api/articles');
  $this
    ->assertPagination(Json::decode($response), OffsetPage::SIZE_MAX);
  // 2. Check with an increased page limit.
  $this
    ->setResouceConfigValue([
    'page_limit' => static::PAGE_LIMIT_OVERRIDE_VALUE,
  ]);
  $response = $this
    ->drupalGet('/api/articles', [
    'query' => [
      'page[limit]' => static::PAGE_LIMIT_OVERRIDE_VALUE,
    ],
  ]);
  $this
    ->assertPagination(Json::decode($response), static::PAGE_LIMIT_OVERRIDE_VALUE);
  // 3. Make sure query values higher than the configured limit won't yield
  // more results.
  $query_override = static::PAGE_LIMIT_OVERRIDE_VALUE + OffsetPage::SIZE_MAX;
  $response = $this
    ->drupalGet('/api/articles', [
    'query' => [
      'page[limit]' => $query_override,
    ],
  ]);
  $response = Json::decode($response);
  $this
    ->assertArrayHasKey('data', $response);
  $this
    ->assertNotEqual(count($response['data']), $query_override);
  $this
    ->assertEqual(count($response['data']), static::PAGE_LIMIT_OVERRIDE_VALUE);
}