1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
13:
14: use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
15: use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
16: use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
17:
18: 19: 20: 21: 22:
23: class MockArraySessionStorageTest extends \PHPUnit_Framework_TestCase
24: {
25: 26: 27:
28: private $storage;
29:
30: 31: 32:
33: private $attributes;
34:
35: 36: 37:
38: private $flashes;
39:
40: private $data;
41:
42: protected function setUp()
43: {
44: $this->attributes = new AttributeBag();
45: $this->flashes = new FlashBag();
46:
47: $this->data = array(
48: $this->attributes->getStorageKey() => array('foo' => 'bar'),
49: $this->flashes->getStorageKey() => array('notice' => 'hello'),
50: );
51:
52: $this->storage = new MockArraySessionStorage();
53: $this->storage->registerBag($this->flashes);
54: $this->storage->registerBag($this->attributes);
55: $this->storage->setSessionData($this->data);
56: }
57:
58: protected function tearDown()
59: {
60: $this->data = null;
61: $this->flashes = null;
62: $this->attributes = null;
63: $this->storage = null;
64: }
65:
66: public function testStart()
67: {
68: $this->assertEquals('', $this->storage->getId());
69: $this->storage->start();
70: $id = $this->storage->getId();
71: $this->assertNotEquals('', $id);
72: $this->storage->start();
73: $this->assertEquals($id, $this->storage->getId());
74: }
75:
76: public function testRegenerate()
77: {
78: $this->storage->start();
79: $id = $this->storage->getId();
80: $this->storage->regenerate();
81: $this->assertNotEquals($id, $this->storage->getId());
82: $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
83: $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->peekAll());
84:
85: $id = $this->storage->getId();
86: $this->storage->regenerate(true);
87: $this->assertNotEquals($id, $this->storage->getId());
88: $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
89: $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->peekAll());
90: }
91:
92: public function testGetId()
93: {
94: $this->assertEquals('', $this->storage->getId());
95: $this->storage->start();
96: $this->assertNotEquals('', $this->storage->getId());
97: }
98:
99: 100: 101:
102: public function testUnstartedSave()
103: {
104: $this->storage->save();
105: }
106: }
107: