Open Journal Systems  3.3.0
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 
13 
14 use PHPUnit\Framework\TestCase;
16 
22 class FlashBagTest 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('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 }
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\testGetSetName
testGetSetName()
Definition: FlashBagTest.php:71
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\testSet
testSet()
Definition: FlashBagTest.php:106
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\testGetStorageKey
testGetStorageKey()
Definition: FlashBagTest.php:64
Symfony\Component\HttpFoundation\Session\Flash\FlashBag
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:19
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\$array
$array
Definition: FlashBagTest.php:38
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\setUp
setUp()
Definition: FlashBagTest.php:40
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\testGet
testGet()
Definition: FlashBagTest.php:86
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\tearDown
tearDown()
Definition: FlashBagTest.php:48
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\testKeys
testKeys()
Definition: FlashBagTest.php:119
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\testAll
testAll()
Definition: FlashBagTest.php:94
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\testPeekAll
testPeekAll()
Definition: FlashBagTest.php:124
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\testPeek
testPeek()
Definition: FlashBagTest.php:78
Symfony\Component\HttpFoundation\Tests\Session\Flash
Definition: AutoExpireFlashBagTest.php:12
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest
Definition: FlashBagTest.php:22
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\testInitialize
testInitialize()
Definition: FlashBagTest.php:54
Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest\testHas
testHas()
Definition: FlashBagTest.php:113