Skip to content

Commit

Permalink
EZP-31039: Skip requirement of sort params when updating Location via…
Browse files Browse the repository at this point in the history
… REST (#57)

Co-authored-by: Bartek Wajda <bartlomiej.wajda@ibexa.co>
  • Loading branch information
Bartek and barw4 authored Oct 27, 2020
1 parent 64a7a59 commit 479ab9e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
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

0 comments on commit 479ab9e

Please # to comment.