aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/UserBundle
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-10-01 15:51:37 +0200
committerGitHub <noreply@github.com>2016-10-01 15:51:37 +0200
commitdb5541e7a1e7131d62b4df23fa6eadd0c542b256 (patch)
treec5c71df873a9aa9350660e225f046a448274868f /tests/Wallabag/UserBundle
parent114c55c0a6eade2ba6c53fe25f61cc58cca91620 (diff)
parentfb7354c4a430f4f4916a1247aa1b1bf564ead0da (diff)
downloadwallabag-db5541e7a1e7131d62b4df23fa6eadd0c542b256.tar.gz
wallabag-db5541e7a1e7131d62b4df23fa6eadd0c542b256.tar.zst
wallabag-db5541e7a1e7131d62b4df23fa6eadd0c542b256.zip
Merge pull request #2320 from wallabag/user-config
Create user config in one place.
Diffstat (limited to 'tests/Wallabag/UserBundle')
-rw-r--r--tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
new file mode 100644
index 00000000..0cebd3e4
--- /dev/null
+++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
@@ -0,0 +1,93 @@
1<?php
2
3namespace Tests\Wallabag\UserBundle\EventListener;
4
5use FOS\UserBundle\Event\FilterUserResponseEvent;
6use FOS\UserBundle\FOSUserEvents;
7use Symfony\Component\EventDispatcher\EventDispatcher;
8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\HttpFoundation\Response;
10use Wallabag\CoreBundle\Entity\Config;
11use Wallabag\UserBundle\EventListener\CreateConfigListener;
12use Wallabag\UserBundle\Entity\User;
13
14class 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 );
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_COMPLETED,
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 $config->setReadingSpeed(1);
81
82 $this->em->expects($this->once())
83 ->method('persist')
84 ->will($this->returnValue($config));
85 $this->em->expects($this->once())
86 ->method('flush');
87
88 $this->dispatcher->dispatch(
89 FOSUserEvents::REGISTRATION_COMPLETED,
90 $event
91 );
92 }
93}