This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php
Fabien Potencier 74bc699b27 moved management of the locale from the Session class to the Request class
The locale management does not require sessions anymore.

In the Symfony2 spirit, the locale should be part of your URLs. If this is the case
(via the special _locale request attribute), Symfony will store it in the request
(getLocale()).

This feature is now also configurable/replaceable at will as everything is now managed
by the new LocaleListener event listener.

How to upgrade:

The default locale configuration has been moved from session to the main configuration:

Before:

framework:
    session:
        default_locale: en

After:

framework:
    default_locale: en

Whenever you want to get the current locale, call getLocale() on the request (was on the
session before).
2011-10-08 18:34:49 +02:00

70 lines
1.8 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session;
use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage;
use Symfony\Bundle\FrameworkBundle\Templating\Helper\SessionHelper;
class SessionHelperTest extends \PHPUnit_Framework_TestCase
{
protected $request;
public function setUp()
{
$this->request = new Request();
$session = new Session(new ArraySessionStorage());
$session->set('foobar', 'bar');
$session->setFlash('foo', 'bar');
$this->request->setSession($session);
}
protected function tearDown()
{
$this->request = null;
}
public function testFlash()
{
$helper = new SessionHelper($this->request);
$this->assertTrue($helper->hasFlash('foo'));
$this->assertEquals('bar', $helper->getFlash('foo'));
$this->assertEquals('foo', $helper->getFlash('bar', 'foo'));
$this->assertNull($helper->getFlash('foobar'));
$this->assertEquals(array('foo' => 'bar'), $helper->getFlashes());
}
public function testGet()
{
$helper = new SessionHelper($this->request);
$this->assertEquals('bar', $helper->get('foobar'));
$this->assertEquals('foo', $helper->get('bar', 'foo'));
$this->assertNull($helper->get('foo'));
}
public function testGetName()
{
$helper = new SessionHelper($this->request);
$this->assertEquals('session', $helper->getName());
}
}