class LocaleListenerTest in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/http-kernel/Tests/EventListener/LocaleListenerTest.php \Symfony\Component\HttpKernel\Tests\EventListener\LocaleListenerTest
Hierarchy
- class \Symfony\Component\HttpKernel\Tests\EventListener\LocaleListenerTest extends \Symfony\Component\HttpKernel\Tests\EventListener\PHPUnit_Framework_TestCase
Expanded class hierarchy of LocaleListenerTest
File
- vendor/
symfony/ http-kernel/ Tests/ EventListener/ LocaleListenerTest.php, line 20
Namespace
Symfony\Component\HttpKernel\Tests\EventListenerView source
class LocaleListenerTest extends \PHPUnit_Framework_TestCase {
private $requestStack;
protected function setUp() {
$this->requestStack = $this
->getMock('Symfony\\Component\\HttpFoundation\\RequestStack', array(), array(), '', false);
}
public function testDefaultLocaleWithoutSession() {
$listener = new LocaleListener('fr', null, $this->requestStack);
$event = $this
->getEvent($request = Request::create('/'));
$listener
->onKernelRequest($event);
$this
->assertEquals('fr', $request
->getLocale());
}
public function testLocaleFromRequestAttribute() {
$request = Request::create('/');
session_name('foo');
$request->cookies
->set('foo', 'value');
$request->attributes
->set('_locale', 'es');
$listener = new LocaleListener('fr', null, $this->requestStack);
$event = $this
->getEvent($request);
$listener
->onKernelRequest($event);
$this
->assertEquals('es', $request
->getLocale());
}
public function testLocaleSetForRoutingContext() {
// the request context is updated
$context = $this
->getMock('Symfony\\Component\\Routing\\RequestContext');
$context
->expects($this
->once())
->method('setParameter')
->with('_locale', 'es');
$router = $this
->getMock('Symfony\\Component\\Routing\\Router', array(
'getContext',
), array(), '', false);
$router
->expects($this
->once())
->method('getContext')
->will($this
->returnValue($context));
$request = Request::create('/');
$request->attributes
->set('_locale', 'es');
$listener = new LocaleListener('fr', $router, $this->requestStack);
$listener
->onKernelRequest($this
->getEvent($request));
}
public function testRouterResetWithParentRequestOnKernelFinishRequest() {
// the request context is updated
$context = $this
->getMock('Symfony\\Component\\Routing\\RequestContext');
$context
->expects($this
->once())
->method('setParameter')
->with('_locale', 'es');
$router = $this
->getMock('Symfony\\Component\\Routing\\Router', array(
'getContext',
), array(), '', false);
$router
->expects($this
->once())
->method('getContext')
->will($this
->returnValue($context));
$parentRequest = Request::create('/');
$parentRequest
->setLocale('es');
$this->requestStack
->expects($this
->once())
->method('getParentRequest')
->will($this
->returnValue($parentRequest));
$event = $this
->getMock('Symfony\\Component\\HttpKernel\\Event\\FinishRequestEvent', array(), array(), '', false);
$listener = new LocaleListener('fr', $router, $this->requestStack);
$listener
->onKernelFinishRequest($event);
}
public function testRequestLocaleIsNotOverridden() {
$request = Request::create('/');
$request
->setLocale('de');
$listener = new LocaleListener('fr', null, $this->requestStack);
$event = $this
->getEvent($request);
$listener
->onKernelRequest($event);
$this
->assertEquals('de', $request
->getLocale());
}
private function getEvent(Request $request) {
return new GetResponseEvent($this
->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LocaleListenerTest:: |
private | property | ||
LocaleListenerTest:: |
private | function | ||
LocaleListenerTest:: |
protected | function | ||
LocaleListenerTest:: |
public | function | ||
LocaleListenerTest:: |
public | function | ||
LocaleListenerTest:: |
public | function | ||
LocaleListenerTest:: |
public | function | ||
LocaleListenerTest:: |
public | function |