diff --git a/src/lib/Server/Input/Parser/LocationUpdate.php b/src/lib/Server/Input/Parser/LocationUpdate.php index f6471f8f..c7905e35 100644 --- a/src/lib/Server/Input/Parser/LocationUpdate.php +++ b/src/lib/Server/Input/Parser/LocationUpdate.php @@ -9,7 +9,6 @@ use EzSystems\EzPlatformRest\Input\BaseParser; use EzSystems\EzPlatformRest\Input\ParsingDispatcher; use EzSystems\EzPlatformRest\Input\ParserTools; -use EzSystems\EzPlatformRest\Exceptions; use eZ\Publish\API\Repository\LocationService; use EzSystems\EzPlatformRest\Server\Values\RestLocationUpdateStruct; @@ -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); } } diff --git a/tests/lib/Server/Input/Parser/LocationUpdateTest.php b/tests/lib/Server/Input/Parser/LocationUpdateTest.php index 8fe61c8e..eb2ff4c9 100644 --- a/tests/lib/Server/Input/Parser/LocationUpdateTest.php +++ b/tests/lib/Server/Input/Parser/LocationUpdateTest.php @@ -74,12 +74,10 @@ public function testParse() } /** - * Test LocationUpdate parser throwing exception on missing sort field. + * Test LocationUpdate parser with missing sort field. */ - public function testParseExceptionOnMissingSortField() + public function testParseWithMissingSortField() { - $this->expectException('EzSystems\EzPlatformRest\Exceptions\Parser'); - $this->expectExceptionMessage('Missing \'sortField\' element for LocationUpdate.'); $inputArray = [ 'priority' => 0, 'remoteId' => 'remote-id', @@ -87,16 +85,28 @@ 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. + * Test LocationUpdate parser with missing sort order. */ - public function testParseExceptionOnMissingSortOrder() + public function testParseWithMissingSortOrder() { - $this->expectException(Parser::class); - $this->expectExceptionMessage('Missing \'sortOrder\' element for LocationUpdate.'); $inputArray = [ 'priority' => 0, 'remoteId' => 'remote-id', @@ -104,7 +114,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 + ); } /**