public function IndexResourceTest::testCollection in JSON:API Search API 8
Tests the results contain the index values.
@dataProvider noQueryDataProvider @dataProvider paginationDataProvider @dataProvider fulltextDataProvider @dataProvider filterDataProvider @dataProvider sortDataProvider
Parameters
array $query: The URL query params.
int $expected_count: The expected document count.
array $expected_ids: The expected entity IDs.
array $expected_links_keys: The expected pagination link keys.
File
- tests/
src/ Functional/ IndexResourceTest.php, line 84
Class
- IndexResourceTest
- Tests index resource..
Namespace
Drupal\Tests\jsonapi_search_api\FunctionalCode
public function testCollection(array $query, int $expected_count, array $expected_ids, array $expected_links_keys) : void {
$request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
$url = Url::fromRoute('jsonapi_search_api.index_database_search_index', [], [
'query' => $query,
]);
$response = $this
->request('GET', $url, $request_options);
$this
->assertSame(200, $response
->getStatusCode(), var_export(Json::decode((string) $response
->getBody()), TRUE));
$response_document = Json::decode((string) $response
->getBody());
$this
->assertCount($expected_count, $response_document['data'], var_export($response_document, TRUE));
$this
->assertSame($expected_ids, array_map(static function (array $data) {
return $data['attributes']['drupal_internal__id'];
}, $response_document['data']));
foreach ($expected_links_keys as $links_key) {
$this
->assertArrayHasKey($links_key, $response_document['links'], var_export($response_document['links'], TRUE));
}
}