Open Journal Systems  3.3.0
MockArraySessionStorageTest.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;
18 
24 class MockArraySessionStorageTest extends TestCase
25 {
29  private $storage;
30 
34  private $attributes;
35 
39  private $flashes;
40 
41  private $data;
42 
43  protected function setUp()
44  {
45  $this->attributes = new AttributeBag();
46  $this->flashes = new FlashBag();
47 
48  $this->data = array(
49  $this->attributes->getStorageKey() => array('foo' => 'bar'),
50  $this->flashes->getStorageKey() => array('notice' => 'hello'),
51  );
52 
53  $this->storage = new MockArraySessionStorage();
54  $this->storage->registerBag($this->flashes);
55  $this->storage->registerBag($this->attributes);
56  $this->storage->setSessionData($this->data);
57  }
58 
59  protected function tearDown()
60  {
61  $this->data = null;
62  $this->flashes = null;
63  $this->attributes = null;
64  $this->storage = null;
65  }
66 
67  public function testStart()
68  {
69  $this->assertEquals('', $this->storage->getId());
70  $this->storage->start();
71  $id = $this->storage->getId();
72  $this->assertNotEquals('', $id);
73  $this->storage->start();
74  $this->assertEquals($id, $this->storage->getId());
75  }
76 
77  public function testRegenerate()
78  {
79  $this->storage->start();
80  $id = $this->storage->getId();
81  $this->storage->regenerate();
82  $this->assertNotEquals($id, $this->storage->getId());
83  $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
84  $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->peekAll());
85 
86  $id = $this->storage->getId();
87  $this->storage->regenerate(true);
88  $this->assertNotEquals($id, $this->storage->getId());
89  $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
90  $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->peekAll());
91  }
92 
93  public function testGetId()
94  {
95  $this->assertEquals('', $this->storage->getId());
96  $this->storage->start();
97  $this->assertNotEquals('', $this->storage->getId());
98  }
99 
100  public function testClearClearsBags()
101  {
102  $this->storage->clear();
103 
104  $this->assertSame(array(), $this->storage->getBag('attributes')->all());
105  $this->assertSame(array(), $this->storage->getBag('flashes')->peekAll());
106  }
107 
108  public function testClearStartsSession()
109  {
110  $this->storage->clear();
111 
112  $this->assertTrue($this->storage->isStarted());
113  }
114 
115  public function testClearWithNoBagsStartsSession()
116  {
117  $storage = new MockArraySessionStorage();
118 
119  $storage->clear();
120 
121  $this->assertTrue($storage->isStarted());
122  }
123 
127  public function testUnstartedSave()
128  {
129  $this->storage->save();
130  }
131 }
Symfony\Component\HttpFoundation\Tests\Session\Storage\MockArraySessionStorageTest\testUnstartedSave
testUnstartedSave()
Definition: MockArraySessionStorageTest.php:136
Symfony\Component\HttpFoundation\Session\Flash\FlashBag
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:19
Symfony\Component\HttpFoundation\Tests\Session\Storage\MockArraySessionStorageTest\setUp
setUp()
Definition: MockArraySessionStorageTest.php:52
Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage
Definition: lib/vendor/symfony/http-foundation/Session/Storage/MockArraySessionStorage.php:28
Symfony\Component\HttpFoundation\Tests\Session\Storage\MockArraySessionStorageTest\testStart
testStart()
Definition: MockArraySessionStorageTest.php:76
Symfony\Component\HttpFoundation\Tests\Session\Storage\MockArraySessionStorageTest\testRegenerate
testRegenerate()
Definition: MockArraySessionStorageTest.php:86
Symfony\Component\HttpFoundation\Tests\Session\Storage\MockArraySessionStorageTest\testClearWithNoBagsStartsSession
testClearWithNoBagsStartsSession()
Definition: MockArraySessionStorageTest.php:124
Symfony\Component\HttpFoundation\Tests\Session\Storage\MockArraySessionStorageTest
Definition: MockArraySessionStorageTest.php:24
Symfony\Component\HttpFoundation\Tests\Session\Storage\MockArraySessionStorageTest\testClearStartsSession
testClearStartsSession()
Definition: MockArraySessionStorageTest.php:117
Symfony\Component\HttpFoundation\Tests\Session\Storage
Symfony\Component\HttpFoundation\Tests\Session\Storage\MockArraySessionStorageTest\testGetId
testGetId()
Definition: MockArraySessionStorageTest.php:102
Symfony\Component\HttpFoundation\Tests\Session\Storage\MockArraySessionStorageTest\testClearClearsBags
testClearClearsBags()
Definition: MockArraySessionStorageTest.php:109
Symfony\Component\HttpFoundation\Tests\Session\Storage\MockArraySessionStorageTest\tearDown
tearDown()
Definition: MockArraySessionStorageTest.php:68
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag
Definition: lib/vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:17