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
32 protected $array = array();
34 protected function setUp()
37 $this->bag = new FlashBag();
38 $this->array = array('notice' => array('A previous flash message'));
39 $this->bag->initialize($this->array);
42 protected function tearDown()
48 public function testInitialize()
50 $bag = new FlashBag();
51 $bag->initialize($this->array);
52 $this->assertEquals($this->array, $bag->peekAll());
53 $array = array('should' => array('change'));
54 $bag->initialize($array);
55 $this->assertEquals($array, $bag->peekAll());
58 public function testGetStorageKey()
60 $this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
61 $attributeBag = new FlashBag('test');
62 $this->assertEquals('test', $attributeBag->getStorageKey());
65 public function testGetSetName()
67 $this->assertEquals('flashes', $this->bag->getName());
68 $this->bag->setName('foo');
69 $this->assertEquals('foo', $this->bag->getName());
72 public function testPeek()
74 $this->assertEquals(array(), $this->bag->peek('non_existing'));
75 $this->assertEquals(array('default'), $this->bag->peek('not_existing', array('default')));
76 $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
77 $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
80 public function testGet()
82 $this->assertEquals(array(), $this->bag->get('non_existing'));
83 $this->assertEquals(array('default'), $this->bag->get('not_existing', array('default')));
84 $this->assertEquals(array('A previous flash message'), $this->bag->get('notice'));
85 $this->assertEquals(array(), $this->bag->get('notice'));
88 public function testAll()
90 $this->bag->set('notice', 'Foo');
91 $this->bag->set('error', 'Bar');
92 $this->assertEquals(array(
93 'notice' => array('Foo'),
94 'error' => array('Bar'), ), $this->bag->all()
97 $this->assertEquals(array(), $this->bag->all());
100 public function testSet()
102 $this->bag->set('notice', 'Foo');
103 $this->bag->set('notice', 'Bar');
104 $this->assertEquals(array('Bar'), $this->bag->peek('notice'));
107 public function testHas()
109 $this->assertFalse($this->bag->has('nothing'));
110 $this->assertTrue($this->bag->has('notice'));
113 public function testKeys()
115 $this->assertEquals(array('notice'), $this->bag->keys());
118 public function testPeekAll()
120 $this->bag->set('notice', 'Foo');
121 $this->bag->set('error', 'Bar');
122 $this->assertEquals(array(
123 'notice' => array('Foo'),
124 'error' => array('Bar'),
125 ), $this->bag->peekAll()
127 $this->assertTrue($this->bag->has('notice'));
128 $this->assertTrue($this->bag->has('error'));
129 $this->assertEquals(array(
130 'notice' => array('Foo'),
131 'error' => array('Bar'),
132 ), $this->bag->peekAll()