aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php24
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml10
-rw-r--r--src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php92
3 files changed, 115 insertions, 11 deletions
diff --git a/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php b/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php
index bcc84923..68c25f1f 100644
--- a/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php
+++ b/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php
@@ -2,22 +2,28 @@
2 2
3namespace Wallabag\CoreBundle\EventListener; 3namespace Wallabag\CoreBundle\EventListener;
4 4
5use FOS\UserBundle\FOSUserEvents;
6use Symfony\Component\DependencyInjection\Container;
7use Symfony\Component\EventDispatcher\EventDispatcherInterface; 5use Symfony\Component\EventDispatcher\EventDispatcherInterface;
8use Symfony\Component\EventDispatcher\EventSubscriberInterface; 6use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7use Doctrine\ORM\EntityManager;
9use FOS\UserBundle\Event\FilterUserResponseEvent; 8use FOS\UserBundle\Event\FilterUserResponseEvent;
9use FOS\UserBundle\FOSUserEvents;
10use Wallabag\CoreBundle\Entity\Config; 10use Wallabag\CoreBundle\Entity\Config;
11 11
12class RegistrationConfirmedListener implements EventSubscriberInterface 12class RegistrationConfirmedListener implements EventSubscriberInterface
13{ 13{
14 private $em; 14 private $em;
15 private $container; 15 private $theme;
16 private $itemsOnPage;
17 private $rssLimit;
18 private $language;
16 19
17 public function __construct(Container $container, $em) 20 public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language)
18 { 21 {
19 $this->container = $container;
20 $this->em = $em; 22 $this->em = $em;
23 $this->theme = $theme;
24 $this->itemsOnPage = $itemsOnPage;
25 $this->rssLimit = $rssLimit;
26 $this->language = $language;
21 } 27 }
22 28
23 public static function getSubscribedEvents() 29 public static function getSubscribedEvents()
@@ -34,10 +40,10 @@ class RegistrationConfirmedListener implements EventSubscriberInterface
34 } 40 }
35 41
36 $config = new Config($event->getUser()); 42 $config = new Config($event->getUser());
37 $config->setTheme($this->container->getParameter('theme')); 43 $config->setTheme($this->theme);
38 $config->setItemsPerPage($this->container->getParameter('items_on_page')); 44 $config->setItemsPerPage($this->itemsOnPage);
39 $config->setRssLimit($this->container->getParameter('rss_limit')); 45 $config->setRssLimit($this->rssLimit);
40 $config->setLanguage($this->container->getParameter('language')); 46 $config->setLanguage($this->language);
41 $this->em->persist($config); 47 $this->em->persist($config);
42 $this->em->flush(); 48 $this->em->flush();
43 } 49 }
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index f2247260..c38787de 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -34,7 +34,8 @@ services:
34 34
35 wallabag_core.doctrine.prefixed_naming_strategy: 35 wallabag_core.doctrine.prefixed_naming_strategy:
36 class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy 36 class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy
37 arguments: [%database_table_prefix%] 37 arguments:
38 - %database_table_prefix%
38 39
39 wallabag_core.graby: 40 wallabag_core.graby:
40 class: Graby\Graby 41 class: Graby\Graby
@@ -48,6 +49,11 @@ services:
48 49
49 wallabag_core.registration_confirmed: 50 wallabag_core.registration_confirmed:
50 class: Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener 51 class: Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener
51 arguments: [@service_container, @doctrine.orm.entity_manager] 52 arguments:
53 - @doctrine.orm.entity_manager
54 - %theme%
55 - %items_on_page%
56 - %rss_limit%
57 - %language%
52 tags: 58 tags:
53 - { name: kernel.event_subscriber } 59 - { name: kernel.event_subscriber }
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}