/** * Processes formular data * * @return \Zend\View\Model\ViewModel */ public function formAction() { $services = $this->getServiceLocator(); $repository = $services->get('repositories')->get('Applications/Application'); $mode = $this->params()->fromQuery('mode', 'new'); $appId = $this->params()->fromQuery('id'); $application = $repository->find($appId); $viewModel = new ViewModel(); if ('edit' == $mode) { $comment = $repository->findComment($appId); } else { $comment = new Comment(); $comment->setUser($this->auth()->getUser()); } $this->acl($application, 'read'); $form = $services->get('forms')->get('Applications/CommentForm'); $form->bind($comment); if ($this->getRequest()->isPost()) { $form->setData($_POST); if ($form->isValid()) { if ('new' == $mode) { $application = $repository->find($appId); $application->comments->add($comment); } $viewModel->setVariable('isSaved', true); } } $viewModel->setVariables(array('mode' => $mode, 'identifier' => $appId, 'commentForm' => $form)); return $viewModel; }
/** * @covers Applications\Entity\Application::getComments * @covers Applications\Entity\Application::setComments */ public function testSetGetComments() { $comment = new Comment(); $comment->setMessage('test foo bar')->setDateCreated(new \DateTime())->setUser(new User()); $comments = new ArrayCollection(); $comments->add($comment); $this->target->setComments($comments); $this->assertEquals($comments, $this->target->getComments()); }
public function testPrePersist() { $this->target->prePersist(); $this->assertEquals($this->target->getDateCreated(), new \DateTime()); }
public function testPrePersist() { $this->target->prePersist(); $this->assertInstanceOf("\\DateTime", $this->target->getDateCreated()); }