4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpFoundation\Tests\Session\Flash;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag as FlashBag;
18 * AutoExpireFlashBagTest.
20 * @author Drak <drak@zikula.org>
22 class AutoExpireFlashBagTest extends TestCase
25 * @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag
29 protected $array = array();
31 protected function setUp()
34 $this->bag = new FlashBag();
35 $this->array = array('new' => array('notice' => array('A previous flash message')));
36 $this->bag->initialize($this->array);
39 protected function tearDown()
45 public function testInitialize()
47 $bag = new FlashBag();
48 $array = array('new' => array('notice' => array('A previous flash message')));
49 $bag->initialize($array);
50 $this->assertEquals(array('A previous flash message'), $bag->peek('notice'));
51 $array = array('new' => array(
52 'notice' => array('Something else'),
53 'error' => array('a'),
55 $bag->initialize($array);
56 $this->assertEquals(array('Something else'), $bag->peek('notice'));
57 $this->assertEquals(array('a'), $bag->peek('error'));
60 public function testGetStorageKey()
62 $this->assertEquals('_symfony_flashes', $this->bag->getStorageKey());
63 $attributeBag = new FlashBag('test');
64 $this->assertEquals('test', $attributeBag->getStorageKey());
67 public function testGetSetName()
69 $this->assertEquals('flashes', $this->bag->getName());
70 $this->bag->setName('foo');
71 $this->assertEquals('foo', $this->bag->getName());
74 public function testPeek()
76 $this->assertEquals(array(), $this->bag->peek('non_existing'));
77 $this->assertEquals(array('default'), $this->bag->peek('non_existing', array('default')));
78 $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
79 $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
82 public function testSet()
84 $this->bag->set('notice', 'Foo');
85 $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
88 public function testHas()
90 $this->assertFalse($this->bag->has('nothing'));
91 $this->assertTrue($this->bag->has('notice'));
94 public function testKeys()
96 $this->assertEquals(array('notice'), $this->bag->keys());
99 public function testPeekAll()
108 $this->bag->initialize($array);
109 $this->assertEquals(array(
112 ), $this->bag->peekAll()
115 $this->assertEquals(array(
118 ), $this->bag->peekAll()
122 public function testGet()
124 $this->assertEquals(array(), $this->bag->get('non_existing'));
125 $this->assertEquals(array('default'), $this->bag->get('non_existing', array('default')));
126 $this->assertEquals(array('A previous flash message'), $this->bag->get('notice'));
127 $this->assertEquals(array(), $this->bag->get('notice'));
130 public function testSetAll()
132 $this->bag->setAll(array('a' => 'first', 'b' => 'second'));
133 $this->assertFalse($this->bag->has('a'));
134 $this->assertFalse($this->bag->has('b'));
137 public function testAll()
139 $this->bag->set('notice', 'Foo');
140 $this->bag->set('error', 'Bar');
141 $this->assertEquals(array(
142 'notice' => array('A previous flash message'),
146 $this->assertEquals(array(), $this->bag->all());
149 public function testClear()
151 $this->assertEquals(array('notice' => array('A previous flash message')), $this->bag->clear());
154 public function testDoNotRemoveTheNewFlashesWhenDisplayingTheExistingOnes()
156 $this->bag->add('success', 'Something');
159 $this->assertEquals(array('new' => array('success' => array('Something')), 'display' => array()), $this->array);