-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
specing editorial coment hook listener
- Loading branch information
Showing
5 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
newscoop/src/Newscoop/ArticlesBundle/Controller/EditorialCommentsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
newscoop/src/Newscoop/ArticlesBundle/EventListener/HookListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
newscoop/src/Newscoop/ArticlesBundle/Resources/config/routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
articles: | ||
resource: "@NewscoopArticlesBundle/Controller/" | ||
type: annotation | ||
prefix: / |
49 changes: 49 additions & 0 deletions
49
spec/Newscoop/ArticlesBundle/Controller/EditorialCommentsControllerSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
85
spec/Newscoop/ArticlesBundle/EventListener/HookListenerSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |