AutoExpireFlashBagTest.php
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpFoundation\Tests\Session\Flash;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag as FlashBag;
/**
* AutoExpireFlashBagTest.
*
* @author Drak <drak@zikula.org>
*/
class AutoExpireFlashBagTest extends TestCase
{
/**
* @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag
*/
private $bag;
protected $array = [];
protected function setUp()
{
parent::setUp();
$this->bag = new FlashBag();
$this->array = ['new' => ['notice' => ['A previous flash message']]];
$this->bag->initialize($this->array);
}
protected function tearDown()
{
$this->bag = null;
parent::tearDown();
}
public function testInitialize()
{
$bag = new FlashBag();
$array = ['new' => ['notice' => ['A previous flash message']]];
$bag->initialize($array);
$this->assertEquals(['A previous flash message'], $bag->peek('notice'));
$array = ['new' => [
'notice' => ['Something else'],
'error' => ['a'],
]];
$bag->initialize($array);
$this->assertEquals(['Something else'], $bag->peek('notice'));
$this->assertEquals(['a'], $bag->peek('error'));
}
public function testGetStorageKey()
{
$this->assertEquals('_symfony_flashes', $this->bag->getStorageKey());
$attributeBag = new FlashBag('test');
$this->assertEquals('test', $attributeBag->getStorageKey());
}
public function testGetSetName()
{
$this->assertEquals('flashes', $this->bag->getName());
$this->bag->setName('foo');
$this->assertEquals('foo', $this->bag->getName());
}
public function testPeek()
{
$this->assertEquals([], $this->bag->peek('non_existing'));
$this->assertEquals(['default'], $this->bag->peek('non_existing', ['default']));
$this->assertEquals(['A previous flash message'], $this->bag->peek('notice'));
$this->assertEquals(['A previous flash message'], $this->bag->peek('notice'));
}
public function testSet()
{
$this->bag->set('notice', 'Foo');
$this->assertEquals(['A previous flash message'], $this->bag->peek('notice'));
}
public function testHas()
{
$this->assertFalse($this->bag->has('nothing'));
$this->assertTrue($this->bag->has('notice'));
}
public function testKeys()
{
$this->assertEquals(['notice'], $this->bag->keys());
}
public function testPeekAll()
{
$array = [
'new' => [
'notice' => 'Foo',
'error' => 'Bar',
],
];
$this->bag->initialize($array);
$this->assertEquals([
'notice' => 'Foo',
'error' => 'Bar',
], $this->bag->peekAll()
);
$this->assertEquals([
'notice' => 'Foo',
'error' => 'Bar',
], $this->bag->peekAll()
);
}
public function testGet()
{
$this->assertEquals([], $this->bag->get('non_existing'));
$this->assertEquals(['default'], $this->bag->get('non_existing', ['default']));
$this->assertEquals(['A previous flash message'], $this->bag->get('notice'));
$this->assertEquals([], $this->bag->get('notice'));
}
public function testSetAll()
{
$this->bag->setAll(['a' => 'first', 'b' => 'second']);
$this->assertFalse($this->bag->has('a'));
$this->assertFalse($this->bag->has('b'));
}
public function testAll()
{
$this->bag->set('notice', 'Foo');
$this->bag->set('error', 'Bar');
$this->assertEquals([
'notice' => ['A previous flash message'],
], $this->bag->all()
);
$this->assertEquals([], $this->bag->all());
}
public function testClear()
{
$this->assertEquals(['notice' => ['A previous flash message']], $this->bag->clear());
}
public function testDoNotRemoveTheNewFlashesWhenDisplayingTheExistingOnes()
{
$this->bag->add('success', 'Something');
$this->bag->all();
$this->assertEquals(['new' => ['success' => ['Something']], 'display' => []], $this->array);
}
}