893e120ce166e384d0ed74d6cdfcd1e8db493cb2
[yaffs-website] / vendor / symfony / http-foundation / Tests / Session / Storage / 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
12 namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
16 use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
17 use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
18
19 /**
20  * Test class for MockArraySessionStorage.
21  *
22  * @author Drak <drak@zikula.org>
23  */
24 class MockArraySessionStorageTest extends TestCase
25 {
26     /**
27      * @var MockArraySessionStorage
28      */
29     private $storage;
30
31     /**
32      * @var AttributeBag
33      */
34     private $attributes;
35
36     /**
37      * @var FlashBag
38      */
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
124     /**
125      * @expectedException \RuntimeException
126      */
127     public function testUnstartedSave()
128     {
129         $this->storage->save();
130     }
131 }