]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
Use namespaced PHPUnit classes
[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 Wallabag\CoreBundle\Entity\Config;
12 use Wallabag\UserBundle\Entity\User;
13 use Wallabag\UserBundle\EventListener\CreateConfigListener;
14
15 class CreateConfigListenerTest extends TestCase
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 CreateConfigListener(
30 $this->em,
31 'baggy',
32 20,
33 50,
34 'fr',
35 1,
36 1,
37 1
38 );
39
40 $this->dispatcher = new EventDispatcher();
41 $this->dispatcher->addSubscriber($this->listener);
42
43 $this->request = Request::create('/');
44 $this->response = Response::create();
45 }
46
47 public function testWithValidUser()
48 {
49 $user = new User();
50 $user->setEnabled(true);
51
52 $event = new FilterUserResponseEvent(
53 $user,
54 $this->request,
55 $this->response
56 );
57
58 $config = new Config($user);
59 $config->setTheme('baggy');
60 $config->setItemsPerPage(20);
61 $config->setRssLimit(50);
62 $config->setLanguage('fr');
63 $config->setReadingSpeed(1);
64
65 $this->em->expects($this->once())
66 ->method('persist')
67 ->will($this->returnValue($config));
68 $this->em->expects($this->once())
69 ->method('flush');
70
71 $this->dispatcher->dispatch(
72 FOSUserEvents::REGISTRATION_COMPLETED,
73 $event
74 );
75 }
76 }