Skip to content

Commit

Permalink
Merge pull request #54 from wollanup/develop
Browse files Browse the repository at this point in the history
fix sort
  • Loading branch information
wollanup authored Dec 4, 2017
2 parents 4e69821 + 70c9d2a commit 64ba636
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function setModifierFromRequest(ServerRequestInterface $request)
}

# Handle non JSON string, this is what we need !
if (null === json_decode($modifiers)) {
if (is_string($modifiers) && null === json_decode($modifiers)) {
$sorters = explode(',', $modifiers);
foreach ($sorters as $sorter) {
$direction = Criteria::ASC;
Expand Down
19 changes: 19 additions & 0 deletions tests/Service/Request/QueryModifier/Modifier/SortModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ public function testApplyMulti()
$this->assertEquals('modifier_test.column2 ASC', $mc->getOrderByColumns()[1]);
}

public function testSetModifierFromRequest()
{
$r = new Request(["sort" => ["property" => "name"], "foo" => "bar"]);
$m = new SortModifier($r);
$m->setModifierFromRequest($r);
$this->assertSame(["property" => "name"], $m->getModifier('name'));

$r = new Request(["sort" => "-name", "foo" => "bar"]);
$m = new SortModifier($r);
$m->setModifierFromRequest($r);
$this->assertSame(["property" => "name", "direction" => "DESC"], $m->getModifier('name'));

$r = new Request(["sort" => "-name,foo"]);
$m = new SortModifier($r);
$m->setModifierFromRequest($r);
$this->assertSame(["property" => "name", "direction" => "DESC"], $m->getModifier('name'));
$this->assertSame(["property" => "foo", "direction" => "ASC"], $m->getModifier('foo'));
}

public function testApplyOnInexistentField()
{
$m = new SortModifier(new Request(["sort" => json_encode(["property" => "notFound"])]));
Expand Down

0 comments on commit 64ba636

Please sign in to comment.