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

70 lines
1.8 KiB
PHP
Raw Normal View History

<?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()
{
2011-06-11 09:27:54 +01:00
$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;
}
2011-06-11 09:27:54 +01:00
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());
2011-06-11 09:27:54 +01:00
}
2011-06-11 09:27:54 +01:00
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'));
2011-06-11 09:27:54 +01:00
}
2011-06-11 09:27:54 +01:00
public function testGetName()
{
$helper = new SessionHelper($this->request);
$this->assertEquals('session', $helper->getName());
2011-06-11 09:27:54 +01:00
}
}