/** * Invoke form * * @return void */ public function __invoke() { $request = $this->getRequest(); if ($request->isPost()) { $post = $request->getPost(); $this->getForm()->setData($post); if ($this->getForm()->isValid()) { $commentTable = new Blog\Model\Comment(); $document = $this->getServiceLocator()->get('Zend\\View\\Renderer\\PhpRenderer')->plugin('CurrentDocument'); if ($commentTable->add($this->getForm()->getInputFilter()->getValues(), $document()->getId())) { $this->flashMessenger()->addSuccessMessage('Message sent'); return $this->redirect()->toUrl($request->getRequestUri()); } } } return $this->addPath(__DIR__ . '/../views')->render('plugin/comment-form.phtml', array('form' => $this->getForm(), 'errorMessage' => 'Error')); }
/** * Test * * @return void */ public function testAddWithWrongValues() { $data = array('message' => '', 'username' => '', 'email' => ''); $this->assertFalse($this->object->add($data, $this->document->getId())); }