SessionTest.php 1.71 KB
Newer Older
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
61
62
63
64
<?php

namespace qfq;

require_once(__DIR__ . '/../../qfq/Constants.php');
require_once(__DIR__ . '/../../qfq/store/Session.php');

/**
 * Created by PhpStorm.
 * User: crose
 * Date: 1/10/16
 * Time: 10:55 PM
 */
class SessionTest extends \PHPUnit_Framework_TestCase {

    public function testGetSession() {

        $session1 = Session::getInstance();
        $session2 = Session::getInstance();

        $this->assertEquals($session1, $session2);

        // should not be null
        $this->assertEquals(false, $session2 === null);

        // changing of 'phpUnit' should not fire an exception
        Session::getInstance(false);

        // changing of 'phpUnit' should not fire an exception
        Session::getInstance(true);
    }

    public function testGet() {

        // write/read data1
        Session::set('var1', 'data1');
        $val = Session::get('var1');
        $this->assertEquals('data1', $val);

        // write/read data2
        Session::set('var2', 'data2');
        $val = Session::get('var2');
        $this->assertEquals('data2', $val);

        // read data1  again
        $val = Session::get('var1');
        $this->assertEquals('data1', $val);

        // rewrite/read data1
        Session::set('var1', 'data1again');
        $val = Session::get('var1');
        $this->assertEquals('data1again', $val);

        // read non existing
        $val = Session::get('var3');
        $this->assertEquals(false, $val);

    }

    public function testClear() {

        // write/read data1
        Session::set('var1', 'data1');

Carsten  Rose's avatar
#2067    
Carsten Rose committed
65
        Session::clearAll();
66
67
68
69
70
71
72
73
74

        $val = Session::get('var1');
        $this->assertEquals(false, $val);
    }

    public function setup() {
        Session::getInstance(true);
    }
}