From a50510ae8a2bb7409c356f7caf7e09bf59f7c0fd Mon Sep 17 00:00:00 2001 From: Bartek Date: Tue, 27 Oct 2020 13:10:23 +0100 Subject: [PATCH] EZP-31039: Skip requirement of sort params when updating Location via REST (#3071) Co-authored-by: Bartek Wajda --- .../Server/Input/Parser/LocationUpdate.php | 13 ++---- .../Tests/Input/Parser/LocationUpdateTest.php | 46 ++++++++++++++----- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/eZ/Publish/Core/REST/Server/Input/Parser/LocationUpdate.php b/eZ/Publish/Core/REST/Server/Input/Parser/LocationUpdate.php index d06f630965..63082ef0cf 100644 --- a/eZ/Publish/Core/REST/Server/Input/Parser/LocationUpdate.php +++ b/eZ/Publish/Core/REST/Server/Input/Parser/LocationUpdate.php @@ -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; @@ -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/eZ/Publish/Core/REST/Server/Tests/Input/Parser/LocationUpdateTest.php b/eZ/Publish/Core/REST/Server/Tests/Input/Parser/LocationUpdateTest.php index 29cbb81d42..50be4bc102 100644 --- a/eZ/Publish/Core/REST/Server/Tests/Input/Parser/LocationUpdateTest.php +++ b/eZ/Publish/Core/REST/Server/Tests/Input/Parser/LocationUpdateTest.php @@ -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, @@ -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, @@ -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 + ); } /**