]>
Commit | Line | Data |
---|---|---|
772d8c4b JB |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Tests\EventListener; | |
4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | |
6 | use Symfony\Component\EventDispatcher\EventDispatcher; | |
7 | use Symfony\Component\HttpFoundation\Request; | |
8 | use Symfony\Component\HttpFoundation\Response; | |
9 | use FOS\UserBundle\FOSUserEvents; | |
10 | use FOS\UserBundle\Event\FilterUserResponseEvent; | |
11 | use Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener; | |
12 | use Wallabag\CoreBundle\Entity\User; | |
13 | use Wallabag\CoreBundle\Entity\Config; | |
14 | ||
15 | class 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 | } |