/
Session.test.php
96 lines (79 loc) · 2.38 KB
/
Session.test.php
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* PHP.Gt (http://php.gt)
* @copyright Copyright Ⓒ 2015 Bright Flair Ltd. (http://brightflair.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
*/
namespace Gt\Session;
class Session_Test extends \PHPUnit_Framework_TestCase {
private $cfg;
private $session;
public function setUp() {
$this->cfg = new \Gt\Core\ConfigObj([
"case_sensitive" => false,
"separator" => ".",
"base_namespace" => "TestApp",
]);
$this->session = new Session($this->cfg);
}
public function testSessionStarts() {
$this->assertEquals(Session::STATUS_ACTIVE, $this->session->getStatus());
}
public function testSessionCreatesObject() {
$this->assertArrayHasKey("TestApp", $_SESSION,
'Namespace should exist in session');
$this->assertInstanceOf("\Gt\Session\Store", $_SESSION["TestApp"]);
}
public function testAddsSingleStore() {
$key = "TestKey";
$value = "TestValue";
$this->assertFalse($this->session->exists($key));
$this->session->set($key, $value);
$this->assertTrue($this->session->exists($key));
$this->assertEquals($this->session->get($key), $value);
}
public function testDeletesStore() {
$key = "TestKey";
$value = "TestValue";
$this->assertFalse($this->session->exists($key));
$this->session->set($key, $value);
$this->session->delete($key);
$this->assertFalse($this->session->exists($key));
}
public function testCaseSensitivity() {
$key = "TestKey";
$keyCi = strtolower($key);
$value = "TestValue";
$cfgCS = new \Gt\Core\ConfigObj([
"case_sensitive" => true,
"separator" => ".",
"base_namespace" => "TestApp",
]);
$this->session->set($key, $value);
$this->assertEquals($this->session->get($keyCi), $value);
$this->session->setConfig($cfgCS);
$this->assertFalse($this->session->exists($keyCi));
}
public function testNamespace() {
$namespace = "Shop.Basket.items";
$itemArray = ["beer", "wine", "cheese"];
$this->session->set($namespace, $itemArray);
$this->assertEquals(
$this->session->get($namespace),
$itemArray
);
$this->assertInstanceOf("\Gt\Session\Store",
$this->session->get("Shop.Basket"));
}
public function testStoringNullValue() {
$namespace = "A.Test.Namespace.thing";
$this->session->set($namespace, null);
$this->assertNull($this->session->get($namespace));
}
/**
* @expectedException \Gt\Session\SessionStoreNotFoundException
*/
public function testInvalidGet() {
$this->session->get("This.Namespace.Does.Not.Exist");
}
}#