]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
Add a real configuration for CS-Fixer
[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 Symfony\Component\EventDispatcher\EventDispatcher;
8 use Symfony\Component\HttpFoundation\Request;
9 use Symfony\Component\HttpFoundation\Response;
10 use Wallabag\CoreBundle\Entity\Config;
11 use Wallabag\UserBundle\Entity\User;
12 use Wallabag\UserBundle\EventListener\CreateConfigListener;
13
14 class CreateConfigListenerTest extends \PHPUnit_Framework_TestCase
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
28 $this->listener = new CreateConfigListener(
29 $this->em,
30 'baggy',
31 20,
32 50,
33 'fr',
34 1,
35 1,
36 1
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
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');
62 $config->setReadingSpeed(1);
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(
71 FOSUserEvents::REGISTRATION_COMPLETED,
72 $event
73 );
74 }
75 }