Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Add $data parameter to deleteList #59

Merged
merged 1 commit into from
Mar 3, 2015
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
17 changes: 12 additions & 5 deletions src/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class RestController extends AbstractRestfulController
* @var int
*/
protected $pageSize = 30;

/**
* Maximum number of entities to return per page of a collection. If
* $pageSize parameter is out of range an ApiProblem will be returned
Expand Down Expand Up @@ -158,7 +158,7 @@ public function setCollectionName($name)
{
$this->collectionName = (string) $name;
}

/**
* Set the minimum page size for paginated responses
*
Expand Down Expand Up @@ -327,7 +327,13 @@ public function onDispatch(MvcEvent $e)
// Check for an API-Problem in the event
$return = $e->getParam('api-problem', false);

// If no API-Problem, dispatch the parent event
// Override RESTful deleteList method
if (strtolower($e->getRequest()->getMethod()) == 'delete' &&
$this->getIdentifier($e->getRouteMatch(), $e->getRequest()) === false) {
$return = $this->deleteList($this->processBodyContent($e->getRequest()));
}

// If no return value dispatch the parent event
if (!$return) {
$return = parent::onDispatch($e);
}
Expand All @@ -350,6 +356,7 @@ public function onDispatch(MvcEvent $e)
$viewModel = new ContentNegotiationViewModel(array('payload' => $return));
$viewModel->setTerminal(true);
$e->setResult($viewModel);

return $viewModel;
}

Expand Down Expand Up @@ -431,13 +438,13 @@ public function delete($id)
return $response;
}

public function deleteList()
public function deleteList($data = null)
{
$events = $this->getEventManager();
$events->trigger('deleteList.pre', $this, array());

try {
$result = $this->getResource()->deleteList();
$result = $this->getResource()->deleteList($data);
} catch (\Exception $e) {
return new ApiProblem($this->getHttpStatusCodeFromException($e), $e);
}
Expand Down
13 changes: 12 additions & 1 deletion test/RestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function setUp()
$this->resource = $resource = new Resource();
$controller->setResource($resource);
}

public function testReturnsErrorResponseWhenPageSizeExceedsMax()
{
$items = array(
Expand Down Expand Up @@ -217,6 +217,17 @@ public function testTrueFromDeleteCollectionReturnsResponseWithNoContent()
return true;
});

$result = $this->controller->deleteList(array(1, 2, 3));
$this->assertInstanceOf('Zend\Http\Response', $result);
$this->assertEquals(204, $result->getStatusCode());
}

public function testDeleteCollectionBackwardsCompatibleWithNoData()
{
$this->resource->getEventManager()->attach('deleteList', function ($e) {
return true;
});

$result = $this->controller->deleteList();
$this->assertInstanceOf('Zend\Http\Response', $result);
$this->assertEquals(204, $result->getStatusCode());
Expand Down