Skip to content

Commit

Permalink
specing editorial coment hook listener
Browse files Browse the repository at this point in the history
  • Loading branch information
takeit committed Sep 26, 2014
1 parent 20dd6c3 commit abd7a7d
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @package Newscoop\ArticlesBundle
* @author Rafał Muszyński <rafal.muszynski@sourcefabric.org>
* @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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @package Newscoop\ArticlesBundle
* @author Rafał Muszyński <rafal.muszynski@sourcefabric.org>
* @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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
articles:
resource: "@NewscoopArticlesBundle/Controller/"
type: annotation
prefix: /
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace spec\Newscoop\ArticlesBundle\Controller;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\Container;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\Request;

class EditorialCommentsControllerSpec extends ObjectBehavior
{
function let(Container $container,
Registry $doctrine,
EntityRepository $repository,
EntityManager $entityManager,
Request $request
) {
$container->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'));
}
}
85 changes: 85 additions & 0 deletions spec/Newscoop/ArticlesBundle/EventListener/HookListenerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace spec\Newscoop\ArticlesBundle\EventListener;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\EntityManager;

class HookListenerSpec extends ObjectBehavior
{
public function let(
$die,
\Doctrine\ORM\EntityManager $em,
\Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine $templating,
EntityRepository $repository
) {
$em->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');
}
}

0 comments on commit abd7a7d

Please sign in to comment.