aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-10-30 11:27:09 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-30 11:27:09 +0100
commit48656e0eaac006a80f21e9aec8900747fe76283a (patch)
tree8b685bd1b2b68b47a12b2bc17f076683c466603f /tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php
parent7f55941856549a3f5f45c42fdc171d66ff7ee297 (diff)
downloadwallabag-48656e0eaac006a80f21e9aec8900747fe76283a.tar.gz
wallabag-48656e0eaac006a80f21e9aec8900747fe76283a.tar.zst
wallabag-48656e0eaac006a80f21e9aec8900747fe76283a.zip
Fixing tests
Diffstat (limited to 'tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php
new file mode 100644
index 00000000..84a54d3a
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php
@@ -0,0 +1,86 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Event\Listener;
4
5use Symfony\Component\EventDispatcher\EventDispatcher;
6use Symfony\Component\HttpFoundation\Request;
7use Symfony\Component\HttpFoundation\Session\Session;
8use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
9use Symfony\Component\HttpKernel\Event\GetResponseEvent;
10use Symfony\Component\HttpKernel\HttpKernelInterface;
11use Symfony\Component\HttpKernel\KernelEvents;
12use Wallabag\CoreBundle\Event\Listener\LocaleListener;
13
14class LocaleListenerTest extends \PHPUnit_Framework_TestCase
15{
16 private function getEvent(Request $request)
17 {
18 $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')
19 ->disableOriginalConstructor()
20 ->getMock();
21
22 return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
23 }
24
25 public function testWithoutSession()
26 {
27 $request = Request::create('/');
28
29 $listener = new LocaleListener('fr');
30 $event = $this->getEvent($request);
31
32 $listener->onKernelRequest($event);
33 $this->assertEquals('en', $request->getLocale());
34 }
35
36 public function testWithPreviousSession()
37 {
38 $request = Request::create('/');
39 // generate a previous session
40 $request->cookies->set('MOCKSESSID', 'foo');
41 $request->setSession(new Session(new MockArraySessionStorage()));
42
43 $listener = new LocaleListener('fr');
44 $event = $this->getEvent($request);
45
46 $listener->onKernelRequest($event);
47 $this->assertEquals('fr', $request->getLocale());
48 }
49
50 public function testLocaleFromRequestAttribute()
51 {
52 $request = Request::create('/');
53 // generate a previous session
54 $request->cookies->set('MOCKSESSID', 'foo');
55 $request->setSession(new Session(new MockArraySessionStorage()));
56 $request->attributes->set('_locale', 'es');
57
58 $listener = new LocaleListener('fr');
59 $event = $this->getEvent($request);
60
61 $listener->onKernelRequest($event);
62 $this->assertEquals('en', $request->getLocale());
63 $this->assertEquals('es', $request->getSession()->get('_locale'));
64 }
65
66 public function testSubscribedEvents()
67 {
68 $request = Request::create('/');
69 // generate a previous session
70 $request->cookies->set('MOCKSESSID', 'foo');
71 $request->setSession(new Session(new MockArraySessionStorage()));
72
73 $listener = new LocaleListener('fr');
74 $event = $this->getEvent($request);
75
76 $dispatcher = new EventDispatcher();
77 $dispatcher->addSubscriber($listener);
78
79 $dispatcher->dispatch(
80 KernelEvents::REQUEST,
81 $event
82 );
83
84 $this->assertEquals('fr', $request->getLocale());
85 }
86}