|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Tests the {@see HybridSessionStore_Cookie} class |
|
5
|
|
|
*/ |
|
6
|
|
|
class HybridSessionCookieTest extends HybridSessionAbstractTest { |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @return HybridSessionStore_Cookie |
|
10
|
|
|
*/ |
|
11
|
|
View Code Duplication |
protected function getStore() { |
|
|
|
|
|
|
12
|
|
|
$store = Injector::inst()->get('HybridSessionStore_Cookie'); |
|
13
|
|
|
$store->setKey(uniqid()); |
|
14
|
|
|
$store->open(getTempFolder().'/'.__CLASS__, 'SESSIONCOOKIE'); |
|
15
|
|
|
return $store; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
View Code Duplication |
public function testStoreLargeData() { |
|
|
|
|
|
|
19
|
|
|
$session = uniqid(); |
|
20
|
|
|
$store = $this->getStore(); |
|
21
|
|
|
|
|
22
|
|
|
// Test new session is blank |
|
23
|
|
|
$result = $store->read($session); |
|
24
|
|
|
$this->assertEmpty($result); |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
// Save data against session |
|
27
|
|
|
$data1 = array( |
|
28
|
|
|
'Large' => str_repeat('A', 600), |
|
29
|
|
|
'Content' => str_repeat('B', 600) |
|
30
|
|
|
); |
|
31
|
|
|
$store->write($session, serialize($data1)); |
|
32
|
|
|
$result = $store->read($session); |
|
33
|
|
|
|
|
34
|
|
|
// Cookies should not try to store data that large |
|
35
|
|
|
$this->assertEmpty($result); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Ensure that subsequent reads without the necessary write do not report data |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testReadInvalidatesData() { |
|
42
|
|
|
$session = uniqid(); |
|
43
|
|
|
$store = $this->getStore(); |
|
44
|
|
|
|
|
45
|
|
|
// Test new session is blank |
|
46
|
|
|
$result = $store->read($session); |
|
47
|
|
|
$this->assertEmpty($result); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
// Save data against session |
|
50
|
|
|
$data1 = array( |
|
51
|
|
|
'Color' => 'red', |
|
52
|
|
|
'Animal' => 'elephant' |
|
53
|
|
|
); |
|
54
|
|
|
$store->write($session, serialize($data1)); |
|
55
|
|
|
$result = $store->read($session); |
|
56
|
|
|
$this->assertEquals($data1, unserialize($result)); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
// Since we have read the data into the result, the application could modify this content |
|
59
|
|
|
// and be unable to write it back due to headers being sent. We should thus assume |
|
60
|
|
|
// that subsequent reads without a successful write do not purport to have valid data |
|
61
|
|
|
$data1['Color'] = 'blue'; |
|
62
|
|
|
$result = $store->read($session); |
|
63
|
|
|
$this->assertEmpty($result); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
// Check that writing to cookie fails after headers are sent and these results remain |
|
66
|
|
|
// invalidated |
|
67
|
|
|
HybridSessionAbstractTest_TestCookieBackend::$override_headers_sent = true; |
|
|
|
|
|
|
68
|
|
|
$store->write($session, serialize($data1)); |
|
69
|
|
|
$result = $store->read($session); |
|
70
|
|
|
$this->assertEmpty($result); |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.