/** * @test */ public function addCommentToObjectStorageHoldingComments() { $comment = new \Pluswerk\Simpleblog\Domain\Model\Comment(); $commentsObjectStorageMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', array('attach'), array(), '', FALSE); $commentsObjectStorageMock->expects($this->once())->method('attach')->with($this->equalTo($comment)); $this->inject($this->subject, 'comments', $commentsObjectStorageMock); $this->subject->addComment($comment); }
/** * @param \Pluswerk\Simpleblog\Domain\Model\Post $post * @param \Pluswerk\Simpleblog\Domain\Model\Comment $comment */ public function ajaxAction(\Pluswerk\Simpleblog\Domain\Model\Post $post, \Pluswerk\Simpleblog\Domain\Model\Comment $comment = NULL) { // Wenn der Kommentar leer ist, wird nicht persistiert if ($comment->getComment() == "") { return FALSE; } // Datum des Kommentars setzen und den Kommentar zum Post hinzufügen $comment->setCommentdate(new \DateTime()); $post->addComment($comment); // Signal for comment $this->signalSlotDispatcher->dispatch(__CLASS__, 'beforeCommentCreation', array($comment, $post)); $this->postRepository->update($post); $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager')->persistAll(); $comments = $post->getComments(); foreach ($comments as $comment) { $json[$comment->getUid()] = array('comment' => $comment->getComment(), 'commentdate' => $comment->getCommentdate()); } return json_encode($json); }