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;
|
|
|
|
use Symfony\Component\HttpFoundation\Session;
|
|
|
|
use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\Helper\SessionHelper;
|
[FrameworkBundle] Refactored code for changes to HttpFoundation component.
Native PHP sessions stored to file are done with session.storage.native_file
Functional testing is done with session.storage.mock_file
Default flash message implementation done with FlashBag (session.flash_bag)
Default attribute storage implementation with AttributeBag (session.attribute_bag)
Services added: session.storage.native_file, session.storage.native_memcache, session.storage.native_memcache,
session.storage.native_sqlite, session.storage.memcache, session.storage.memcached, session.storage.null,
session.storage.mock_file, session.flash_bag, session.attribute_bag
Services removed: session.storage.native, session.storage.filesystem
2011-12-15 08:46:43 +00:00
|
|
|
use Symfony\Component\HttpFoundation\FlashBag;
|
|
|
|
use Symfony\Component\HttpFoundation\AttributeBag;
|
2011-06-11 08:56:09 +01:00
|
|
|
|
|
|
|
class SessionHelperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2011-06-11 09:27:54 +01:00
|
|
|
$this->request = new Request();
|
|
|
|
|
[FrameworkBundle] Refactored code for changes to HttpFoundation component.
Native PHP sessions stored to file are done with session.storage.native_file
Functional testing is done with session.storage.mock_file
Default flash message implementation done with FlashBag (session.flash_bag)
Default attribute storage implementation with AttributeBag (session.attribute_bag)
Services added: session.storage.native_file, session.storage.native_memcache, session.storage.native_memcache,
session.storage.native_sqlite, session.storage.memcache, session.storage.memcached, session.storage.null,
session.storage.mock_file, session.flash_bag, session.attribute_bag
Services removed: session.storage.native, session.storage.filesystem
2011-12-15 08:46:43 +00:00
|
|
|
$session = new Session(new ArraySessionStorage(new AttributeBag(), new FlashBag()));
|
2011-06-11 09:27:54 +01:00
|
|
|
$session->set('foobar', 'bar');
|
[FrameworkBundle] Refactored code for changes to HttpFoundation component.
Native PHP sessions stored to file are done with session.storage.native_file
Functional testing is done with session.storage.mock_file
Default flash message implementation done with FlashBag (session.flash_bag)
Default attribute storage implementation with AttributeBag (session.attribute_bag)
Services added: session.storage.native_file, session.storage.native_memcache, session.storage.native_memcache,
session.storage.native_sqlite, session.storage.memcache, session.storage.memcached, session.storage.null,
session.storage.mock_file, session.flash_bag, session.attribute_bag
Services removed: session.storage.native, session.storage.filesystem
2011-12-15 08:46:43 +00:00
|
|
|
$session->addFlash('bar', FlashBag::NOTICE);
|
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);
|
|
|
|
|
[FrameworkBundle] Refactored code for changes to HttpFoundation component.
Native PHP sessions stored to file are done with session.storage.native_file
Functional testing is done with session.storage.mock_file
Default flash message implementation done with FlashBag (session.flash_bag)
Default attribute storage implementation with AttributeBag (session.attribute_bag)
Services added: session.storage.native_file, session.storage.native_memcache, session.storage.native_memcache,
session.storage.native_sqlite, session.storage.memcache, session.storage.memcached, session.storage.null,
session.storage.mock_file, session.flash_bag, session.attribute_bag
Services removed: session.storage.native, session.storage.filesystem
2011-12-15 08:46:43 +00:00
|
|
|
$this->assertTrue($helper->hasFlashes(FlashBag::NOTICE));
|
2011-06-11 08:56:09 +01:00
|
|
|
|
[FrameworkBundle] Refactored code for changes to HttpFoundation component.
Native PHP sessions stored to file are done with session.storage.native_file
Functional testing is done with session.storage.mock_file
Default flash message implementation done with FlashBag (session.flash_bag)
Default attribute storage implementation with AttributeBag (session.attribute_bag)
Services added: session.storage.native_file, session.storage.native_memcache, session.storage.native_memcache,
session.storage.native_sqlite, session.storage.memcache, session.storage.memcached, session.storage.null,
session.storage.mock_file, session.flash_bag, session.attribute_bag
Services removed: session.storage.native, session.storage.filesystem
2011-12-15 08:46:43 +00:00
|
|
|
$this->assertEquals(array('bar'), $helper->getFlashes(FlashBag::NOTICE));
|
2011-06-11 08:56:09 +01:00
|
|
|
|
[FrameworkBundle] Refactored code for changes to HttpFoundation component.
Native PHP sessions stored to file are done with session.storage.native_file
Functional testing is done with session.storage.mock_file
Default flash message implementation done with FlashBag (session.flash_bag)
Default attribute storage implementation with AttributeBag (session.attribute_bag)
Services added: session.storage.native_file, session.storage.native_memcache, session.storage.native_memcache,
session.storage.native_sqlite, session.storage.memcache, session.storage.memcached, session.storage.null,
session.storage.mock_file, session.flash_bag, session.attribute_bag
Services removed: session.storage.native, session.storage.filesystem
2011-12-15 08:46:43 +00:00
|
|
|
$this->assertEquals(array(FlashBag::NOTICE => array('bar')), $helper->getAllFlashes());
|
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
|
|
|
}
|