2011-11-24 05:07:08 +00: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.
|
|
|
|
*/
|
|
|
|
|
2012-02-08 23:15:47 +00:00
|
|
|
namespace Symfony\Tests\Component\HttpFoundation\Session\Flash;
|
2011-11-24 05:07:08 +00:00
|
|
|
|
2012-02-08 23:15:47 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
|
|
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
|
2011-11-24 05:07:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FlashBagTest
|
|
|
|
*
|
|
|
|
* @author Drak <drak@zikula.org>
|
|
|
|
*/
|
|
|
|
class FlashBagTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
2012-02-08 09:46:38 +00:00
|
|
|
* @var \Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface
|
2011-11-24 05:07:08 +00:00
|
|
|
*/
|
|
|
|
private $bag;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $array = array();
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->bag = new FlashBag();
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->array = array('notice' => 'A previous flash message');
|
2011-11-24 05:07:08 +00:00
|
|
|
$this->bag->initialize($this->array);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
$this->bag = null;
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInitialize()
|
|
|
|
{
|
|
|
|
$bag = new FlashBag();
|
|
|
|
$bag->initialize($this->array);
|
2012-02-10 09:45:15 +00:00
|
|
|
$this->assertEquals($this->array, $bag->peekAll());
|
2011-11-24 05:07:08 +00:00
|
|
|
$array = array('should' => array('change'));
|
|
|
|
$bag->initialize($array);
|
2012-02-10 09:45:15 +00:00
|
|
|
$this->assertEquals($array, $bag->peekAll());
|
2011-11-24 05:07:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 09:45:15 +00:00
|
|
|
public function testPeek()
|
2011-11-24 05:07:08 +00:00
|
|
|
{
|
2012-02-10 09:45:15 +00:00
|
|
|
$this->assertNull($this->bag->peek('non_existing'));
|
|
|
|
$this->assertEquals('default', $this->bag->peek('not_existing', 'default'));
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->assertEquals('A previous flash message', $this->bag->peek('notice'));
|
|
|
|
$this->assertEquals('A previous flash message', $this->bag->peek('notice'));
|
2011-11-24 05:07:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-11 10:45:20 +00:00
|
|
|
public function testGet()
|
2011-11-24 05:07:08 +00:00
|
|
|
{
|
2012-02-11 10:45:20 +00:00
|
|
|
$this->assertNull($this->bag->get('non_existing'));
|
|
|
|
$this->assertEquals('default', $this->bag->get('not_existing', 'default'));
|
|
|
|
$this->assertEquals('A previous flash message', $this->bag->get('notice'));
|
|
|
|
$this->assertNull($this->bag->get('notice'));
|
2011-11-24 05:07:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-11 10:45:20 +00:00
|
|
|
public function testAll()
|
2011-11-24 05:07:08 +00:00
|
|
|
{
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->bag->set('notice', 'Foo');
|
|
|
|
$this->bag->set('error', 'Bar');
|
2011-11-24 05:07:08 +00:00
|
|
|
$this->assertEquals(array(
|
2012-02-10 09:53:21 +00:00
|
|
|
'notice' => 'Foo',
|
2012-02-11 10:45:20 +00:00
|
|
|
'error' => 'Bar'), $this->bag->all()
|
2011-11-24 05:07:08 +00:00
|
|
|
);
|
|
|
|
|
2012-02-11 10:45:20 +00:00
|
|
|
$this->assertEquals(array(), $this->bag->all());
|
2011-11-24 05:07:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 09:45:15 +00:00
|
|
|
public function testSet()
|
2011-11-24 05:07:08 +00:00
|
|
|
{
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->bag->set('notice', 'Foo');
|
|
|
|
$this->bag->set('notice', 'Bar');
|
|
|
|
$this->assertEquals('Bar', $this->bag->peek('notice'));
|
2011-11-24 05:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testHas()
|
|
|
|
{
|
|
|
|
$this->assertFalse($this->bag->has('nothing'));
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->assertTrue($this->bag->has('notice'));
|
2011-11-24 05:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testKeys()
|
|
|
|
{
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->assertEquals(array('notice'), $this->bag->keys());
|
2011-11-24 05:07:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 09:45:15 +00:00
|
|
|
public function testPeekAll()
|
2011-11-24 05:07:08 +00:00
|
|
|
{
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->bag->set('notice', 'Foo');
|
|
|
|
$this->bag->set('error', 'Bar');
|
2011-11-24 05:07:08 +00:00
|
|
|
$this->assertEquals(array(
|
2012-02-10 09:53:21 +00:00
|
|
|
'notice' => 'Foo',
|
|
|
|
'error' => 'Bar',
|
2012-02-10 09:45:15 +00:00
|
|
|
), $this->bag->peekAll()
|
2011-11-24 05:07:08 +00:00
|
|
|
);
|
2012-02-10 09:53:21 +00:00
|
|
|
$this->assertTrue($this->bag->has('notice'));
|
|
|
|
$this->assertTrue($this->bag->has('error'));
|
2011-11-24 05:07:08 +00:00
|
|
|
$this->assertEquals(array(
|
2012-02-10 09:53:21 +00:00
|
|
|
'notice' => 'Foo',
|
|
|
|
'error' => 'Bar',
|
2012-02-10 09:45:15 +00:00
|
|
|
), $this->bag->peekAll()
|
2011-11-24 05:07:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|