예제 #1
0
 public function addAction()
 {
     $config = $this->getServiceLocator()->get('Config');
     $rbCommentConfig = (object) $config['rb_comment'];
     $form = new CommentForm($rbCommentConfig->strings);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $comment = new Comment();
         $form->setInputFilter($comment->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $comment->exchangeArray($form->getData());
             // Set default visibility from config
             $comment->visible = $rbCommentConfig->default_visibility;
             // If akismet is enabled check for spam
             if ($rbCommentConfig->akismet['enabled'] === true && $this->isSpam($comment, $rbCommentConfig)) {
                 $comment->spam = 1;
                 $comment->visible = 0;
             }
             // We need the id for the mailer
             $comment->id = $this->getCommentTable()->saveComment($comment);
             // Send email if active and not spam
             if ($rbCommentConfig->email['notify'] === true && $comment->spam === 0) {
                 $this->rbMailer($comment);
             }
             return $this->redirect()->toUrl($form->get('uri')->getValue());
         } else {
             $this->flashMessenger()->setNamespace('RbComment');
             $this->flashMessenger()->addMessage(json_encode($form->getMessages()));
             return $this->redirect()->toUrl($form->get('uri')->getValue() . '#rbcomment');
         }
     }
 }
예제 #2
0
 public function testSaveCommentWillUpdateExistingCommentIfItAlreadyHasAnId()
 {
     $comment = new Comment();
     $commentData = array('id' => 12345, 'thread' => 'f133a4599372cf531bcdbfeb1116b9afe8d09b4f', 'uri' => '/test', 'author' => 'Robert Boloc', 'contact' => '*****@*****.**', 'content' => 'Bla bla bla', 'visible' => 1, 'spam' => 0);
     $comment->exchangeArray($commentData);
     $resultSet = new ResultSet();
     $resultSet->setArrayObjectPrototype(new Comment());
     $resultSet->initialize(array($comment));
     $tableGatewayMock = $this->getMock('Zend\\Db\\TableGateway\\TableGateway', array('select', 'update'), array(), '', false);
     $tableGatewayMock->expects($this->once())->method('select')->with(array('id' => 12345))->will($this->returnValue($resultSet));
     $tableGatewayMock->expects($this->once())->method('update')->with(array('thread' => 'f133a4599372cf531bcdbfeb1116b9afe8d09b4f', 'uri' => '/test', 'author' => 'Robert Boloc', 'contact' => '*****@*****.**', 'content' => 'Bla bla bla', 'visible' => 1, 'spam' => 0), array('id' => 12345));
     $commentTable = new CommentTable($tableGatewayMock);
     $commentTable->saveComment($comment);
 }