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

Commit

Permalink
Merge branch 'hotfix/7255' into develop
Browse files Browse the repository at this point in the history
Re-instate #7255 on develop branch.
  • Loading branch information
weierophinney committed Mar 26, 2015
2 parents e790fb3 + e28fad6 commit ab8b520
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
6 changes: 4 additions & 2 deletions library/Zend/Mvc/Controller/AbstractRestfulController.php
Expand Up @@ -116,7 +116,7 @@ public function delete($id)
*
* @return mixed
*/
public function deleteList()
public function deleteList($data)
{
$this->response->setStatusCode(405);

Expand Down Expand Up @@ -347,14 +347,16 @@ public function onDispatch(MvcEvent $e)
// DELETE
case 'delete':
$id = $this->getIdentifier($routeMatch, $request);
$data = $this->processBodyContent($request);

if ($id !== false) {
$action = 'delete';
$return = $this->delete($id);
break;
}

$action = 'deleteList';
$return = $this->deleteList();
$return = $this->deleteList($data);
break;
// GET
case 'get':
Expand Down
14 changes: 12 additions & 2 deletions tests/ZendTest/Mvc/Controller/RestfulControllerTest.php
Expand Up @@ -137,9 +137,19 @@ public function testDispatchInvokesDeleteMethodWhenNoActionPresentAndDeleteInvok

public function testDispatchInvokesDeleteListMethodWhenNoActionPresentAndDeleteInvokedWithoutIdentifier()
{
$this->request->setMethod('DELETE');
$entities = array(
array('id' => uniqid(), 'name' => __FUNCTION__),
array('id' => uniqid(), 'name' => __FUNCTION__),
array('id' => uniqid(), 'name' => __FUNCTION__),
);

$this->controller->entity = $entities;

$string = http_build_query($entities);
$this->request->setMethod('DELETE')
->setContent($string);
$result = $this->controller->dispatch($this->request, $this->response);
$this->assertSame($this->response, $result);
$this->assertEmpty($this->controller->entity);
$this->assertEquals(204, $result->getStatusCode());
$this->assertTrue($result->getHeaders()->has('X-Deleted'));
$this->assertEquals('deleteList', $this->routeMatch->getParam('action'));
Expand Down
Expand Up @@ -49,11 +49,23 @@ public function delete($id)
*
* @return \Zend\Http\Response
*/
public function deleteList()
public function deleteList($data)
{
if (is_array($this->entity)) {
foreach ($data as $row) {
foreach ($this->entity as $index => $entity) {
if ($row['id'] == $entity['id']) {
unset($this->entity[$index]);
break;
}
}
}
}

$response = $this->getResponse();
$response->setStatusCode(204);
$response->getHeaders()->addHeaderLine('X-Deleted', 'true');

return $response;
}

Expand Down

0 comments on commit ab8b520

Please sign in to comment.