f0aa6a61577f4a2fae7caca270b2f6ab7e2ef988
[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     /**
30      * @var array
31      */
32     protected $array = array();
33
34     protected function setUp()
35     {
36         parent::setUp();
37         $this->bag = new FlashBag();
38         $this->array = array('notice' => array('A previous flash message'));
39         $this->bag->initialize($this->array);
40     }
41
42     protected function tearDown()
43     {
44         $this->bag = null;
45         parent::tearDown();
46     }
47
48     public function testInitialize()
49     {
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());
56     }
57
58     public function testGetStorageKey()
59     {
60         $this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
61         $attributeBag = new FlashBag('test');
62         $this->assertEquals('test', $attributeBag->getStorageKey());
63     }
64
65     public function testGetSetName()
66     {
67         $this->assertEquals('flashes', $this->bag->getName());
68         $this->bag->setName('foo');
69         $this->assertEquals('foo', $this->bag->getName());
70     }
71
72     public function testPeek()
73     {
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'));
78     }
79
80     public function testGet()
81     {
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'));
86     }
87
88     public function testAll()
89     {
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()
95         );
96
97         $this->assertEquals(array(), $this->bag->all());
98     }
99
100     public function testSet()
101     {
102         $this->bag->set('notice', 'Foo');
103         $this->bag->set('notice', 'Bar');
104         $this->assertEquals(array('Bar'), $this->bag->peek('notice'));
105     }
106
107     public function testHas()
108     {
109         $this->assertFalse($this->bag->has('nothing'));
110         $this->assertTrue($this->bag->has('notice'));
111     }
112
113     public function testKeys()
114     {
115         $this->assertEquals(array('notice'), $this->bag->keys());
116     }
117
118     public function testPeekAll()
119     {
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()
126         );
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()
133         );
134     }
135 }