Skip to content

Commit

Permalink
EZP-31039: Skip requirement of sort params when updating Location via…
Browse files Browse the repository at this point in the history
… REST (#3071)

Co-authored-by: Bartek Wajda <[email protected]>
  • Loading branch information
Bartek and barw4 authored Oct 27, 2020
1 parent 2e43804 commit a50510a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
13 changes: 4 additions & 9 deletions eZ/Publish/Core/REST/Server/Input/Parser/LocationUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use eZ\Publish\Core\REST\Common\Input\BaseParser;
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
use eZ\Publish\Core\REST\Common\Input\ParserTools;
use eZ\Publish\Core\REST\Common\Exceptions;
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\Core\REST\Server\Values\RestLocationUpdateStruct;

Expand Down Expand Up @@ -69,18 +68,14 @@ public function parse(array $data, ParsingDispatcher $parsingDispatcher)
$hidden = $this->parserTools->parseBooleanValue($data['hidden']);
}

if (!array_key_exists('sortField', $data)) {
throw new Exceptions\Parser("Missing 'sortField' element for LocationUpdate.");
if (array_key_exists('sortField', $data)) {
$locationUpdateStruct->sortField = $this->parserTools->parseDefaultSortField($data['sortField']);
}

$locationUpdateStruct->sortField = $this->parserTools->parseDefaultSortField($data['sortField']);

if (!array_key_exists('sortOrder', $data)) {
throw new Exceptions\Parser("Missing 'sortOrder' element for LocationUpdate.");
if (array_key_exists('sortOrder', $data)) {
$locationUpdateStruct->sortOrder = $this->parserTools->parseDefaultSortOrder($data['sortOrder']);
}

$locationUpdateStruct->sortOrder = $this->parserTools->parseDefaultSortOrder($data['sortOrder']);

return new RestLocationUpdateStruct($locationUpdateStruct, $hidden);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ public function testParse()
}

/**
* Test LocationUpdate parser throwing exception on missing sort field.
*
* @expectedException \eZ\Publish\Core\REST\Common\Exceptions\Parser
* @expectedExceptionMessage Missing 'sortField' element for LocationUpdate.
* Test LocationUpdate parser with missing sort field.
*/
public function testParseExceptionOnMissingSortField()
public function testParseWithMissingSortField()
{
$inputArray = [
'priority' => 0,
Expand All @@ -87,16 +84,27 @@ public function testParseExceptionOnMissingSortField()
];

$locationUpdate = $this->getParser();
$locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());
$result = $locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());

$this->assertInstanceOf(
RestLocationUpdateStruct::class,
$result
);

$this->assertInstanceOf(
LocationUpdateStruct::class,
$result->locationUpdateStruct
);

$this->assertNull(
$result->locationUpdateStruct->sortField
);
}

/**
* Test LocationUpdate parser throwing exception on missing sort order.
*
* @expectedException \eZ\Publish\Core\REST\Common\Exceptions\Parser
* @expectedExceptionMessage Missing 'sortOrder' element for LocationUpdate.
* Test LocationUpdate parser with missing sort order.
*/
public function testParseExceptionOnMissingSortOrder()
public function testParseWithMissingSortOrder()
{
$inputArray = [
'priority' => 0,
Expand All @@ -105,7 +113,21 @@ public function testParseExceptionOnMissingSortOrder()
];

$locationUpdate = $this->getParser();
$locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());
$result = $locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());

$this->assertInstanceOf(
RestLocationUpdateStruct::class,
$result
);

$this->assertInstanceOf(
LocationUpdateStruct::class,
$result->locationUpdateStruct
);

$this->assertNull(
$result->locationUpdateStruct->sortOrder
);
}

/**
Expand Down

0 comments on commit a50510a

Please sign in to comment.