Skip to content
Snippets Groups Projects
Commit 4bb19bef authored by Björn Brala's avatar Björn Brala
Browse files

Issue #3322635 by bbrala, ptmkenny, marysmech, avioli, bojan_dev, daveiano:...

Issue #3322635 by bbrala, ptmkenny, marysmech, avioli, bojan_dev, daveiano: Unexpected value for parameter \"sort\": expecting \"array\", got \"string\"."
parent c76b1db1
No related branches found
No related tags found
No related merge requests found
......@@ -74,12 +74,12 @@ class EntityResource extends JsonApiEntityResourse {
$filters = array_merge(
$default_filter,
$request->query->all('filter')
$request->query->get('filter', [])
);
$sort = [];
if ($request->query->has('sort')) {
$sort = Sort::createFromQueryParameter($request->query->all('sort'))->fields();
$sort = Sort::createFromQueryParameter($request->query->get('sort'))->fields();
}
$sorting = array_merge($default_sorting, $sort);
......
......@@ -28,6 +28,40 @@ class JsonApiDefaultsFunctionalTest extends JsonApiExtrasFunctionalTestBase {
'jsonapi_defaults',
];
/**
* Test regression on sorting from issue 3322635.
*/
public function testSortRegression3322635() {
$this->setResouceConfigValue([
'default_filter' => [],
'default_sorting' => [],
]);
$this->createDefaultContent(2, 5, TRUE, TRUE, static::IS_NOT_MULTILINGUAL);
$this->nodes[0]->title->setValue('b');
$this->nodes[0]->save();
$this->nodes[1]->title->setValue('a');
$this->nodes[1]->save();
$stringResponse = $this->drupalGet('/api/articles', ['query' => ['sort' => 'title']]);
$output = Json::decode($stringResponse);
// Check if order changed as expected.
$this->assertEquals('a', $output['data'][0]['attributes']['title']);
$this->assertEquals('b', $output['data'][1]['attributes']['title']);
$stringResponse = $this->drupalGet('/api/articles', ['query' => ['sort' => '-title']]);
$output = Json::decode($stringResponse);
// Check if order changed as expected.
$this->assertEquals('b', $output['data'][0]['attributes']['title']);
$this->assertEquals('a', $output['data'][1]['attributes']['title']);
}
/**
* Test the GET method.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment