/** * Test admin_delete action * * @return void */ public function testAdminDelete() { $this->Comments->admin_delete('invalid-comment'); $this->assertEqual($this->Comments->redirectUrl, array('action' => 'index')); $this->assertEqual($this->Comments->Session->read('Message.flash.message'), 'Invalid id for Comment'); $this->Comments->Session->delete('Message.flash.message'); $Article = ClassRegistry::init('Article'); $oldCount = array_shift(Set::extract($Article->read(array('Article.comments'), 1), '/Article/comments')); $this->Comments->admin_delete(1); $this->assertEqual($this->Comments->redirectUrl, array('action' => 'index')); $this->assertEqual($this->Comments->Session->read('Message.flash.message'), 'Comment deleted'); $newCount = array_shift(Set::extract($Article->read(array('Article.comments'), 1), '/Article/comments')); $this->assertEqual($newCount, $oldCount - 1); $this->Comments->Session->delete('Message.flash.message'); }
/** * Test admin_delete action * * @return void */ public function testAdminDelete() { $this->Collection = $this->getMock('ComponentCollection'); $this->Comments->Session = $this->getMock('SessionComponent', array('setFlash'), array($this->Collection)); $this->Comments->Session->expects($this->once())->method('setFlash')->with(__d('comments', 'Invalid id for Comment')); $this->Comments->admin_delete('invalid-comment'); $this->assertEqual($this->Comments->redirectUrl, array('action' => 'index')); $Article = ClassRegistry::init('Article'); $oldCount = array_shift(Set::extract($Article->read(array('Article.comments'), 1), '/Article/comments')); $this->Collection = $this->getMock('ComponentCollection'); $this->Comments->Session = $this->getMock('SessionComponent', array('setFlash'), array($this->Collection)); $this->Comments->Session->expects($this->once())->method('setFlash')->with(__d('comments', 'Comment deleted')); $this->Comments->admin_delete(1); $this->assertEqual($this->Comments->redirectUrl, array('action' => 'index')); $newCount = array_shift(Set::extract($Article->read(array('Article.comments'), 1), '/Article/comments')); $this->assertEqual($newCount, $oldCount - 1); }