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