aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-10-01 22:25:23 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-10-03 13:30:43 +0200
commit772d8c4b93adc36baefda93ec37007e4a85321de (patch)
treec654a9c7b00f2d7d3a5dd20a49120c67e8b8d0a9 /src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php
parent2c13918acc3c46120bbef5e6746f3c6dc27be5df (diff)
downloadwallabag-772d8c4b93adc36baefda93ec37007e4a85321de.tar.gz
wallabag-772d8c4b93adc36baefda93ec37007e4a85321de.tar.zst
wallabag-772d8c4b93adc36baefda93ec37007e4a85321de.zip
Add test on RegistrationConfirmedListener
And PLEASE @nicosomb, NEVER EVER inject the whole container inside a service.
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php')
-rw-r--r--src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php b/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php
new file mode 100644
index 00000000..137c097c
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php
@@ -0,0 +1,92 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests\EventListener;
4
5use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6use Symfony\Component\EventDispatcher\EventDispatcher;
7use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpFoundation\Response;
9use FOS\UserBundle\FOSUserEvents;
10use FOS\UserBundle\Event\FilterUserResponseEvent;
11use Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener;
12use Wallabag\CoreBundle\Entity\User;
13use Wallabag\CoreBundle\Entity\Config;
14
15class RegistrationConfirmedListenerTest extends KernelTestCase
16{
17 private $em;
18 private $listener;
19 private $dispatcher;
20 private $request;
21 private $response;
22
23 protected function setUp()
24 {
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $this->listener = new RegistrationConfirmedListener(
30 $this->em,
31 'baggy',
32 20,
33 50,
34 'fr'
35 );
36
37 $this->dispatcher = new EventDispatcher();
38 $this->dispatcher->addSubscriber($this->listener);
39
40 $this->request = Request::create('/');
41 $this->response = Response::create();
42 }
43
44 public function testWithInvalidUser()
45 {
46 $user = new User();
47 $user->setEnabled(false);
48
49 $event = new FilterUserResponseEvent(
50 $user,
51 $this->request,
52 $this->response
53 );
54
55 $this->em->expects($this->never())->method('persist');
56 $this->em->expects($this->never())->method('flush');
57
58 $this->dispatcher->dispatch(
59 FOSUserEvents::REGISTRATION_CONFIRMED,
60 $event
61 );
62 }
63
64 public function testWithValidUser()
65 {
66 $user = new User();
67 $user->setEnabled(true);
68
69 $event = new FilterUserResponseEvent(
70 $user,
71 $this->request,
72 $this->response
73 );
74
75 $config = new Config($user);
76 $config->setTheme('baggy');
77 $config->setItemsPerPage(20);
78 $config->setRssLimit(50);
79 $config->setLanguage('fr');
80
81 $this->em->expects($this->once())
82 ->method('persist')
83 ->will($this->returnValue($config));
84 $this->em->expects($this->once())
85 ->method('flush');
86
87 $this->dispatcher->dispatch(
88 FOSUserEvents::REGISTRATION_CONFIRMED,
89 $event
90 );
91 }
92}