/** * Add action un-enabled entity * * @throws \Exception */ public function testAddActionNoEnabledEntity() { $form = $this->commentService->createForm(); $postData = array('comment' => "test comment", 'alias' => $this->entityType->getAlias(), 'id' => $this->user->getId()); $this->entityType->setIsEnabled(0); $this->assertNull($this->commentService->add($form, $postData)); }
/** * @param Entity\EntityType $entityType * @param $entityId * @return array */ public function getComments(Entity\EntityType $entityType, $entityId) { $objectManager = $this->serviceManager->get('Doctrine\\ORM\\EntityManager'); $arrayComments = []; $identity = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService')->getIdentity(); if ($entityType->getIsVisible() || $identity->getUser()->getRole() === User::ROLE_ADMIN) { $comments = $objectManager->getRepository('Comment\\Entity\\Comment')->findBy(['entityType' => $entityType, 'entityId' => $entityId]); $enabledCommentByComment = null; $commentEntityType = $objectManager->getRepository('Comment\\Entity\\EntityType')->findOneByAlias('comment'); if ($commentEntityType && $commentEntityType->getIsEnabled()) { $enabledCommentByComment = true; } foreach ($comments as $comment) { $arrayComments[$comment->getId()]['comment'] = $comment; if ($commentEntityType) { $arrayComments[$comment->getId()]['children'] = $this->getComments($commentEntityType, $comment->getId()); } else { $arrayComments[$comment->getId()]['children'] = []; } $arrayComments[$comment->getId()]['enabledCommentByComment'] = $enabledCommentByComment; } } return $arrayComments; }