Open Journal Systems  3.3.0
AutoExpireFlashBagTest.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 
13 
14 use PHPUnit\Framework\TestCase;
16 
22 class AutoExpireFlashBagTest extends TestCase
23 {
27  private $bag;
28 
32  protected $array = array();
33 
34  protected function setUp()
35  {
36  parent::setUp();
37  $this->bag = new FlashBag();
38  $this->array = array('new' => 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  $array = array('new' => array('notice' => array('A previous flash message')));
52  $bag->initialize($array);
53  $this->assertEquals(array('A previous flash message'), $bag->peek('notice'));
54  $array = array('new' => array(
55  'notice' => array('Something else'),
56  'error' => array('a'),
57  ));
58  $bag->initialize($array);
59  $this->assertEquals(array('Something else'), $bag->peek('notice'));
60  $this->assertEquals(array('a'), $bag->peek('error'));
61  }
62 
63  public function testGetStorageKey()
64  {
65  $this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
66  $attributeBag = new FlashBag('test');
67  $this->assertEquals('test', $attributeBag->getStorageKey());
68  }
69 
70  public function testGetSetName()
71  {
72  $this->assertEquals('flashes', $this->bag->getName());
73  $this->bag->setName('foo');
74  $this->assertEquals('foo', $this->bag->getName());
75  }
76 
77  public function testPeek()
78  {
79  $this->assertEquals(array(), $this->bag->peek('non_existing'));
80  $this->assertEquals(array('default'), $this->bag->peek('non_existing', array('default')));
81  $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
82  $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
83  }
84 
85  public function testSet()
86  {
87  $this->bag->set('notice', 'Foo');
88  $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
89  }
90 
91  public function testHas()
92  {
93  $this->assertFalse($this->bag->has('nothing'));
94  $this->assertTrue($this->bag->has('notice'));
95  }
96 
97  public function testKeys()
98  {
99  $this->assertEquals(array('notice'), $this->bag->keys());
100  }
101 
102  public function testPeekAll()
103  {
104  $array = array(
105  'new' => array(
106  'notice' => 'Foo',
107  'error' => 'Bar',
108  ),
109  );
110 
111  $this->bag->initialize($array);
112  $this->assertEquals(array(
113  'notice' => 'Foo',
114  'error' => 'Bar',
115  ), $this->bag->peekAll()
116  );
117 
118  $this->assertEquals(array(
119  'notice' => 'Foo',
120  'error' => 'Bar',
121  ), $this->bag->peekAll()
122  );
123  }
124 
125  public function testGet()
126  {
127  $this->assertEquals(array(), $this->bag->get('non_existing'));
128  $this->assertEquals(array('default'), $this->bag->get('non_existing', array('default')));
129  $this->assertEquals(array('A previous flash message'), $this->bag->get('notice'));
130  $this->assertEquals(array(), $this->bag->get('notice'));
131  }
132 
133  public function testSetAll()
134  {
135  $this->bag->setAll(array('a' => 'first', 'b' => 'second'));
136  $this->assertFalse($this->bag->has('a'));
137  $this->assertFalse($this->bag->has('b'));
138  }
139 
140  public function testAll()
141  {
142  $this->bag->set('notice', 'Foo');
143  $this->bag->set('error', 'Bar');
144  $this->assertEquals(array(
145  'notice' => array('A previous flash message'),
146  ), $this->bag->all()
147  );
148 
149  $this->assertEquals(array(), $this->bag->all());
150  }
151 
152  public function testClear()
153  {
154  $this->assertEquals(array('notice' => array('A previous flash message')), $this->bag->clear());
155  }
156 }
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testPeekAll
testPeekAll()
Definition: AutoExpireFlashBagTest.php:108
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testAll
testAll()
Definition: AutoExpireFlashBagTest.php:146
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testGetSetName
testGetSetName()
Definition: AutoExpireFlashBagTest.php:76
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testHas
testHas()
Definition: AutoExpireFlashBagTest.php:97
Symfony\Component\HttpFoundation\Session\Flash\FlashBag
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:19
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testInitialize
testInitialize()
Definition: AutoExpireFlashBagTest.php:54
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testGet
testGet()
Definition: AutoExpireFlashBagTest.php:131
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testGetStorageKey
testGetStorageKey()
Definition: AutoExpireFlashBagTest.php:69
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testPeek
testPeek()
Definition: AutoExpireFlashBagTest.php:83
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\setUp
setUp()
Definition: AutoExpireFlashBagTest.php:40
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\tearDown
tearDown()
Definition: AutoExpireFlashBagTest.php:48
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testClear
testClear()
Definition: AutoExpireFlashBagTest.php:158
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testSetAll
testSetAll()
Definition: AutoExpireFlashBagTest.php:139
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\$array
$array
Definition: AutoExpireFlashBagTest.php:38
Symfony\Component\HttpFoundation\Tests\Session\Flash
Definition: AutoExpireFlashBagTest.php:12
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testKeys
testKeys()
Definition: AutoExpireFlashBagTest.php:103
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest
Definition: AutoExpireFlashBagTest.php:22
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:19
Symfony\Component\HttpFoundation\Tests\Session\Flash\AutoExpireFlashBagTest\testSet
testSet()
Definition: AutoExpireFlashBagTest.php:91