]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
fd32f380378f27a9a27a3600c47ab044a1359503
[github/wallabag/wallabag.git] / tests / Wallabag / UserBundle / EventListener / CreateConfigListenerTest.php
1 <?php
2
3 namespace Tests\Wallabag\UserBundle\EventListener;
4
5 use FOS\UserBundle\Event\FilterUserResponseEvent;
6 use FOS\UserBundle\FOSUserEvents;
7 use PHPUnit\Framework\TestCase;
8 use Symfony\Component\EventDispatcher\EventDispatcher;
9 use Symfony\Component\HttpFoundation\Request;
10 use Symfony\Component\HttpFoundation\Response;
11 use Symfony\Component\HttpFoundation\Session\Session;
12 use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
13 use Wallabag\CoreBundle\Entity\Config;
14 use Wallabag\UserBundle\Entity\User;
15 use Wallabag\UserBundle\EventListener\CreateConfigListener;
16
17 class CreateConfigListenerTest extends TestCase
18 {
19 private $em;
20 private $listener;
21 private $dispatcher;
22 private $request;
23 private $response;
24
25 protected function setUp()
26 {
27 $session = new Session(new MockArraySessionStorage());
28 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
29 ->disableOriginalConstructor()
30 ->getMock();
31
32 $this->listener = new CreateConfigListener(
33 $this->em,
34 'baggy',
35 20,
36 50,
37 'fr',
38 1,
39 1,
40 1,
41 $session
42 );
43
44 $this->dispatcher = new EventDispatcher();
45 $this->dispatcher->addSubscriber($this->listener);
46
47 $this->request = Request::create('/');
48 $this->response = Response::create();
49 }
50
51 public function testWithValidUser()
52 {
53 $user = new User();
54 $user->setEnabled(true);
55
56 $event = new FilterUserResponseEvent(
57 $user,
58 $this->request,
59 $this->response
60 );
61
62 $config = new Config($user);
63 $config->setTheme('baggy');
64 $config->setItemsPerPage(20);
65 $config->setFeedLimit(50);
66 $config->setLanguage('fr');
67 $config->setReadingSpeed(1);
68
69 $this->em->expects($this->once())
70 ->method('persist')
71 ->will($this->returnValue($config));
72 $this->em->expects($this->once())
73 ->method('flush');
74
75 $this->dispatcher->dispatch(
76 FOSUserEvents::REGISTRATION_COMPLETED,
77 $event
78 );
79 }
80 }