summaryrefslogtreecommitdiff
path: root/tests/units/Core/Session/SessionStorageTest.php
blob: dd0040d5363fd363bd271ef30812634e185385a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php

require_once __DIR__.'/../../Base.php';

use Kanboard\Core\Session\SessionStorage;

class SessionStorageTest extends Base
{
    public function testNotPersistentStorage()
    {
        $storage = new SessionStorage();
        $storage->something = array('a' => 'b');
        $this->assertEquals(array('a' => 'b'), $storage->something);
        $this->assertTrue(isset($storage->something));
        $this->assertFalse(isset($storage->something->x));
        $this->assertFalse(isset($storage->notFound));
        $this->assertFalse(isset($storage->notFound->x));
        $this->assertFalse(isset($storage->notFound['x']));
    }

    public function testPersistentStorage()
    {
        $session = array('d' => 'e');

        $storage = new SessionStorage();
        $storage->setStorage($session);
        $storage->something = array('a' => 'b');

        $this->assertEquals(array('a' => 'b'), $storage->something);
        $this->assertEquals('e', $storage->d);

        $storage->something['a'] = 'c';
        $this->assertEquals('c', $storage->something['a']);

        $storage = null;
        $this->assertEquals(array('something' => array('a' => 'c'), 'd' => 'e'), $session);
    }

    public function testFlush()
    {
        $session = array('d' => 'e');

        $storage = new SessionStorage();
        $storage->setStorage($session);
        $storage->something = array('a' => 'b');

        $this->assertEquals(array('a' => 'b'), $storage->something);
        $this->assertEquals('e', $storage->d);

        $storage->flush();

        $this->assertFalse(isset($storage->d));
        $this->assertFalse(isset($storage->something));

        $storage->foo = 'bar';

        $storage = null;
        $this->assertEquals(array('foo' => 'bar'), $session);
    }
}