Skip to content

Commit a50510a

Browse files
Bartekbarw4
andauthored
EZP-31039: Skip requirement of sort params when updating Location via REST (#3071)
Co-authored-by: Bartek Wajda <[email protected]>
1 parent 2e43804 commit a50510a

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

eZ/Publish/Core/REST/Server/Input/Parser/LocationUpdate.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use eZ\Publish\Core\REST\Common\Input\BaseParser;
1010
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
1111
use eZ\Publish\Core\REST\Common\Input\ParserTools;
12-
use eZ\Publish\Core\REST\Common\Exceptions;
1312
use eZ\Publish\API\Repository\LocationService;
1413
use eZ\Publish\Core\REST\Server\Values\RestLocationUpdateStruct;
1514

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

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

76-
$locationUpdateStruct->sortField = $this->parserTools->parseDefaultSortField($data['sortField']);
77-
78-
if (!array_key_exists('sortOrder', $data)) {
79-
throw new Exceptions\Parser("Missing 'sortOrder' element for LocationUpdate.");
75+
if (array_key_exists('sortOrder', $data)) {
76+
$locationUpdateStruct->sortOrder = $this->parserTools->parseDefaultSortOrder($data['sortOrder']);
8077
}
8178

82-
$locationUpdateStruct->sortOrder = $this->parserTools->parseDefaultSortOrder($data['sortOrder']);
83-
8479
return new RestLocationUpdateStruct($locationUpdateStruct, $hidden);
8580
}
8681
}

eZ/Publish/Core/REST/Server/Tests/Input/Parser/LocationUpdateTest.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,9 @@ public function testParse()
7373
}
7474

7575
/**
76-
* Test LocationUpdate parser throwing exception on missing sort field.
77-
*
78-
* @expectedException \eZ\Publish\Core\REST\Common\Exceptions\Parser
79-
* @expectedExceptionMessage Missing 'sortField' element for LocationUpdate.
76+
* Test LocationUpdate parser with missing sort field.
8077
*/
81-
public function testParseExceptionOnMissingSortField()
78+
public function testParseWithMissingSortField()
8279
{
8380
$inputArray = [
8481
'priority' => 0,
@@ -87,16 +84,27 @@ public function testParseExceptionOnMissingSortField()
8784
];
8885

8986
$locationUpdate = $this->getParser();
90-
$locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());
87+
$result = $locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());
88+
89+
$this->assertInstanceOf(
90+
RestLocationUpdateStruct::class,
91+
$result
92+
);
93+
94+
$this->assertInstanceOf(
95+
LocationUpdateStruct::class,
96+
$result->locationUpdateStruct
97+
);
98+
99+
$this->assertNull(
100+
$result->locationUpdateStruct->sortField
101+
);
91102
}
92103

93104
/**
94-
* Test LocationUpdate parser throwing exception on missing sort order.
95-
*
96-
* @expectedException \eZ\Publish\Core\REST\Common\Exceptions\Parser
97-
* @expectedExceptionMessage Missing 'sortOrder' element for LocationUpdate.
105+
* Test LocationUpdate parser with missing sort order.
98106
*/
99-
public function testParseExceptionOnMissingSortOrder()
107+
public function testParseWithMissingSortOrder()
100108
{
101109
$inputArray = [
102110
'priority' => 0,
@@ -105,7 +113,21 @@ public function testParseExceptionOnMissingSortOrder()
105113
];
106114

107115
$locationUpdate = $this->getParser();
108-
$locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());
116+
$result = $locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());
117+
118+
$this->assertInstanceOf(
119+
RestLocationUpdateStruct::class,
120+
$result
121+
);
122+
123+
$this->assertInstanceOf(
124+
LocationUpdateStruct::class,
125+
$result->locationUpdateStruct
126+
);
127+
128+
$this->assertNull(
129+
$result->locationUpdateStruct->sortOrder
130+
);
109131
}
110132

111133
/**

0 commit comments

Comments
 (0)