2011-06-11 08:56:09 +01:00
|
|
|
<?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;
|
2012-02-08 23:15:47 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
2012-02-11 11:04:05 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
2011-06-11 08:56:09 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\Helper\SessionHelper;
|
|
|
|
|
|
|
|
class SessionHelperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2011-06-11 09:27:54 +01:00
|
|
|
$this->request = new Request();
|
|
|
|
|
2012-02-11 11:04:05 +00:00
|
|
|
$session = new Session(new MockArraySessionStorage());
|
2011-06-11 09:27:54 +01:00
|
|
|
$session->set('foobar', 'bar');
|
2012-02-11 12:09:41 +00:00
|
|
|
$session->getFlashBag()->set('notice', 'bar');
|
2011-06-11 08:56:09 +01:00
|
|
|
|
|
|
|
$this->request->setSession($session);
|
|
|
|
}
|
|
|
|
|
2011-06-14 09:40:42 +01:00
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
$this->request = null;
|
|
|
|
}
|
|
|
|
|
2011-06-11 09:27:54 +01:00
|
|
|
public function testFlash()
|
|
|
|
{
|
2011-06-11 08:56:09 +01:00
|
|
|
$helper = new SessionHelper($this->request);
|
|
|
|
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->assertTrue($helper->hasFlash('notice'));
|
2011-06-11 08:56:09 +01:00
|
|
|
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->assertEquals('bar', $helper->getFlash('notice'));
|
2012-02-10 09:45:15 +00:00
|
|
|
}
|
2011-06-11 08:56:09 +01:00
|
|
|
|
2012-02-10 09:45:15 +00:00
|
|
|
public function testGetFlashes()
|
|
|
|
{
|
|
|
|
$helper = new SessionHelper($this->request);
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->assertEquals(array('notice' => 'bar'), $helper->getFlashes());
|
2011-06-11 09:27:54 +01:00
|
|
|
}
|
2011-06-11 08:56:09 +01:00
|
|
|
|
2011-06-11 09:27:54 +01:00
|
|
|
public function testGet()
|
|
|
|
{
|
2011-06-11 08:56:09 +01:00
|
|
|
$helper = new SessionHelper($this->request);
|
|
|
|
|
|
|
|
$this->assertEquals('bar', $helper->get('foobar'));
|
|
|
|
$this->assertEquals('foo', $helper->get('bar', 'foo'));
|
|
|
|
|
|
|
|
$this->assertNull($helper->get('foo'));
|
2011-06-11 09:27:54 +01:00
|
|
|
}
|
2011-06-11 08:56:09 +01:00
|
|
|
|
2011-06-11 09:27:54 +01:00
|
|
|
public function testGetName()
|
|
|
|
{
|
2011-06-11 08:56:09 +01:00
|
|
|
$helper = new SessionHelper($this->request);
|
|
|
|
|
|
|
|
$this->assertEquals('session', $helper->getName());
|
2011-06-11 09:27:54 +01:00
|
|
|
}
|
2011-06-11 08:56:09 +01:00
|
|
|
}
|