c4e75b1b18b4085e485b6345702b71fb37be21b4
[yaffs-website] / vendor / symfony / http-foundation / Tests / Session / Flash / FlashBagTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpFoundation\Tests\Session\Flash;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
16
17 /**
18  * FlashBagTest.
19  *
20  * @author Drak <drak@zikula.org>
21  */
22 class FlashBagTest extends TestCase
23 {
24     /**
25      * @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
26      */
27     private $bag;
28
29     protected $array = array();
30
31     protected function setUp()
32     {
33         parent::setUp();
34         $this->bag = new FlashBag();
35         $this->array = array('notice' => array('A previous flash message'));
36         $this->bag->initialize($this->array);
37     }
38
39     protected function tearDown()
40     {
41         $this->bag = null;
42         parent::tearDown();
43     }
44
45     public function testInitialize()
46     {
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());
53     }
54
55     public function testGetStorageKey()
56     {
57         $this->assertEquals('_symfony_flashes', $this->bag->getStorageKey());
58         $attributeBag = new FlashBag('test');
59         $this->assertEquals('test', $attributeBag->getStorageKey());
60     }
61
62     public function testGetSetName()
63     {
64         $this->assertEquals('flashes', $this->bag->getName());
65         $this->bag->setName('foo');
66         $this->assertEquals('foo', $this->bag->getName());
67     }
68
69     public function testPeek()
70     {
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'));
75     }
76
77     public function testGet()
78     {
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'));
83     }
84
85     public function testAll()
86     {
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()
92         );
93
94         $this->assertEquals(array(), $this->bag->all());
95     }
96
97     public function testSet()
98     {
99         $this->bag->set('notice', 'Foo');
100         $this->bag->set('notice', 'Bar');
101         $this->assertEquals(array('Bar'), $this->bag->peek('notice'));
102     }
103
104     public function testHas()
105     {
106         $this->assertFalse($this->bag->has('nothing'));
107         $this->assertTrue($this->bag->has('notice'));
108     }
109
110     public function testKeys()
111     {
112         $this->assertEquals(array('notice'), $this->bag->keys());
113     }
114
115     public function testPeekAll()
116     {
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()
123         );
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()
130         );
131     }
132 }