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