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\FlashBag;
20 * @author Drak <drak@zikula.org>
22 class FlashBagTest extends TestCase
25 * @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
29 protected $array = array();
31 protected function setUp()
34 $this->bag = new FlashBag();
35 $this->array = 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 $bag->initialize($this->array);
49 $this->assertEquals($this->array, $bag->peekAll());
50 $array = array('should' => array('change'));
51 $bag->initialize($array);
52 $this->assertEquals($array, $bag->peekAll());
55 public function testGetStorageKey()
57 $this->assertEquals('_symfony_flashes', $this->bag->getStorageKey());
58 $attributeBag = new FlashBag('test');
59 $this->assertEquals('test', $attributeBag->getStorageKey());
62 public function testGetSetName()
64 $this->assertEquals('flashes', $this->bag->getName());
65 $this->bag->setName('foo');
66 $this->assertEquals('foo', $this->bag->getName());
69 public function testPeek()
71 $this->assertEquals(array(), $this->bag->peek('non_existing'));
72 $this->assertEquals(array('default'), $this->bag->peek('not_existing', array('default')));
73 $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
74 $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
77 public function testGet()
79 $this->assertEquals(array(), $this->bag->get('non_existing'));
80 $this->assertEquals(array('default'), $this->bag->get('not_existing', array('default')));
81 $this->assertEquals(array('A previous flash message'), $this->bag->get('notice'));
82 $this->assertEquals(array(), $this->bag->get('notice'));
85 public function testAll()
87 $this->bag->set('notice', 'Foo');
88 $this->bag->set('error', 'Bar');
89 $this->assertEquals(array(
90 'notice' => array('Foo'),
91 'error' => array('Bar'), ), $this->bag->all()
94 $this->assertEquals(array(), $this->bag->all());
97 public function testSet()
99 $this->bag->set('notice', 'Foo');
100 $this->bag->set('notice', 'Bar');
101 $this->assertEquals(array('Bar'), $this->bag->peek('notice'));
104 public function testHas()
106 $this->assertFalse($this->bag->has('nothing'));
107 $this->assertTrue($this->bag->has('notice'));
110 public function testKeys()
112 $this->assertEquals(array('notice'), $this->bag->keys());
115 public function testPeekAll()
117 $this->bag->set('notice', 'Foo');
118 $this->bag->set('error', 'Bar');
119 $this->assertEquals(array(
120 'notice' => array('Foo'),
121 'error' => array('Bar'),
122 ), $this->bag->peekAll()
124 $this->assertTrue($this->bag->has('notice'));
125 $this->assertTrue($this->bag->has('error'));
126 $this->assertEquals(array(
127 'notice' => array('Foo'),
128 'error' => array('Bar'),
129 ), $this->bag->peekAll()