Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

EZP-31039: Skip requirement of sort params when updating Location via REST #57

Merged
merged 1 commit into from
Oct 27, 2020
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 src/lib/Server/Input/Parser/LocationUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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);
}
}
44 changes: 34 additions & 10 deletions tests/lib/Server/Input/Parser/LocationUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,61 @@ 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',
'sortOrder' => 'ASC',
];

$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',
'sortField' => 'PATH',
];

$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