From abd7a7d74adf020e47e35883d69fb71a52952791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Muszy=C5=84ski?= Date: Fri, 26 Sep 2014 15:58:10 +0200 Subject: [PATCH] specing editorial coment hook listener --- .../EditorialCommentsController.php | 24 ++++++ .../EventListener/HookListener.php | 24 ++++++ .../Resources/config/routing.yml | 4 + .../EditorialCommentsControllerSpec.php | 49 +++++++++++ .../EventListener/HookListenerSpec.php | 85 +++++++++++++++++++ 5 files changed, 186 insertions(+) create mode 100644 newscoop/src/Newscoop/ArticlesBundle/Controller/EditorialCommentsController.php create mode 100644 newscoop/src/Newscoop/ArticlesBundle/EventListener/HookListener.php create mode 100644 newscoop/src/Newscoop/ArticlesBundle/Resources/config/routing.yml create mode 100644 spec/Newscoop/ArticlesBundle/Controller/EditorialCommentsControllerSpec.php create mode 100644 spec/Newscoop/ArticlesBundle/EventListener/HookListenerSpec.php diff --git a/newscoop/src/Newscoop/ArticlesBundle/Controller/EditorialCommentsController.php b/newscoop/src/Newscoop/ArticlesBundle/Controller/EditorialCommentsController.php new file mode 100644 index 0000000000..141caff38e --- /dev/null +++ b/newscoop/src/Newscoop/ArticlesBundle/Controller/EditorialCommentsController.php @@ -0,0 +1,24 @@ + + * @copyright 2014 Sourcefabric ź.u. + * @license http://www.gnu.org/licenses/gpl-3.0.txt + */ + +namespace Newscoop\ArticlesBundle\Controller; + +use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Component\HttpFoundation\Request; + +class EditorialCommentsController extends Controller +{ + /** + * @Route("/admin/editorial-comments", options={"expose"=true}) + */ + public function getAction(Request $request) + { + return array(); + } +} diff --git a/newscoop/src/Newscoop/ArticlesBundle/EventListener/HookListener.php b/newscoop/src/Newscoop/ArticlesBundle/EventListener/HookListener.php new file mode 100644 index 0000000000..521fa15d01 --- /dev/null +++ b/newscoop/src/Newscoop/ArticlesBundle/EventListener/HookListener.php @@ -0,0 +1,24 @@ + + * @copyright 2014 Sourcefabric ź.u. + * @license http://www.gnu.org/licenses/gpl-3.0.txt + */ + +namespace Newscoop\ArticlesBundle\EventListener; + +use Doctrine\ORM\EntityManager; + +/** + * Editorial comments hook listener + */ +class HookListener +{ + protected $em; + + public function __construct(EntityManager $em) + { + // TODO: write logic here + } +} diff --git a/newscoop/src/Newscoop/ArticlesBundle/Resources/config/routing.yml b/newscoop/src/Newscoop/ArticlesBundle/Resources/config/routing.yml new file mode 100644 index 0000000000..0f153f0b38 --- /dev/null +++ b/newscoop/src/Newscoop/ArticlesBundle/Resources/config/routing.yml @@ -0,0 +1,4 @@ +articles: + resource: "@NewscoopArticlesBundle/Controller/" + type: annotation + prefix: / \ No newline at end of file diff --git a/spec/Newscoop/ArticlesBundle/Controller/EditorialCommentsControllerSpec.php b/spec/Newscoop/ArticlesBundle/Controller/EditorialCommentsControllerSpec.php new file mode 100644 index 0000000000..68549214df --- /dev/null +++ b/spec/Newscoop/ArticlesBundle/Controller/EditorialCommentsControllerSpec.php @@ -0,0 +1,49 @@ +get('doctrine')->willReturn($doctrine); + $container->get('request')->willReturn($request); + $doctrine->getManager()->willReturn($entityManager); + $entityManager->getRepository(Argument::any())->willReturn($repository); + + $this->setContainer($container); + } + + function it_is_initializable() + { + $this->shouldHaveType('Newscoop\ArticlesBundle\Controller\EditorialCommentsController'); + } + + function it_is_of_type_container_aware() + { + $this->shouldBeAnInstanceOf('Symfony\Component\DependencyInjection\ContainerAware'); + } + + function its_getAction_should_render_a_list_of_EditorialCommentArray( + $entityManager, + \Newscoop\ArticlesBundle\Entity\Repository\EditorialCommentRepository $repository, + Request $request + ) { + $entityManager->getRepository(Argument::exact('Newscoop\ArticlesBundle\Entity\EditorialComment'))->willReturn($repository); + $repository->getAllByArticleNumber(1)->willReturn(Argument::type('array')); + + $this->getAction($request)->shouldReturn(Argument::type('array')); + } +} diff --git a/spec/Newscoop/ArticlesBundle/EventListener/HookListenerSpec.php b/spec/Newscoop/ArticlesBundle/EventListener/HookListenerSpec.php new file mode 100644 index 0000000000..a3280a8f3e --- /dev/null +++ b/spec/Newscoop/ArticlesBundle/EventListener/HookListenerSpec.php @@ -0,0 +1,85 @@ +persist(Argument::any())->willReturn(true); + $em->flush(Argument::any())->willReturn(true); + $em->remove(Argument::any())->willReturn(true); + + $this->beConstructedWith($em, $templating); + } + + public function it_is_initializable() + { + $this->shouldHaveType('Newscoop\ArticlesBundle\EventListener\HookListener'); + } + + public function it_will_display_form_and_list_of_editorial_comments( + \Newscoop\EventDispatcher\Events\PluginHooksEvent $event, + $em, + \Newscoop\ArticlesBundle\Entity\Repository\EditorialCommentRepository $repository, + $form, + $formFactory + ) + { + $em->getRepository(Argument::exact('Newscoop\ArticlesBundle\Entity\EditorialComment'))->willReturn($repository); + $repository->getAllByArticleNumber(1)->willReturn(Argument::type('array')); + + //$classBook = Argument::exact('Acme\DemoBundle\Entity\Book')->getValue(); + //$book = new $classBook; + $classBookType = Argument::exact('Newscoop\ArticlesBundle\Form\EditorialCommentType')->getValue(); + $booktype = new $classBookType; + + $formFactory->create($booktype, $book)->willReturn($form); + $form->bind($request)->willReturn($form); + $form->isValid()->willReturn(true); + + $form = $this->container->get('form.factory')->create(new CommentButtonType(), array( + 'lists' => $listsArray + ), array('em' => $em)); + + $response = $this->container->get('templating')->renderResponse( + 'NewscoopCommentListsBundle:Hooks:listsButton.html.twig', + array( + 'form' => $form->createView(), + 'lists' => $lists, + 'commentId' => $commentId + ) + ); + + $event->addHookResponse($response); + + //$this->getAction($request)->shouldReturn(Argument::type('array')); + } + + public function its_createAction_should_save_the_BookObject_when_form_is_valid($request, $form, $formFactory, $entityManager) + { + $classBook = Argument::exact('Acme\DemoBundle\Entity\Book')->getValue(); + $book = new $classBook; + $classBookType = Argument::exact('Acme\DemoBundle\Form\BookType')->getValue(); + $booktype = new $classBookType; + + $formFactory->create($booktype, $book)->willReturn($form); + $form->bind($request)->willReturn($form); + $form->isValid()->willReturn(true); + + $entityManager->persist($book)->shouldBeCalled(); + $entityManager->flush()->shouldBeCalled(); + + $response = $this->createAction($request); + $response->shouldBeAnInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse'); + } +}