Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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