, , $idPost - undefined.
- :
public function delete($id = null){
$this->Comment->id = $id;
if (!$this->Comment->exists()) {
throw new NotFoundException(__('Invalid comment'));
}
if ($this->Comment->delete()) {
$this->Session->setFlash(__('Comment deleted'));
} else {
$this->Session->setFlash(__('Comment was not deleted'));
}
$this->redirect(array('controller' => 'posts', 'action' => 'view', $id));
}
}
:
public function testDeleteWithSuccess() {
$Controller = $this->generate('Comments', array(
'components' => array(
'Session'
),
'models' => array(
'Comment' => array('exists')
)
));
$Controller->Comment->expects($this->once())
->method('exists')
->will($this->returnValue(true));
$Controller->Session->expects($this->once())
->method('setFlash')
->with('Comment deleted');
$this->testAction("/comments/delete/ID");
$this->assertEquals($this->headers['Location'], 'http://'. $_SERVER['HTTP_HOST'] . '/posts/view/ID');
}