commit | author | age
|
0868e0
|
1 |
<?php |
JK |
2 |
class BotSessionTest extends PHPUnit_Framework_TestCase { |
|
3 |
function testSessionFolder() { |
|
4 |
$dbFolder = dirname(__FILE__).'/../../database'; |
|
5 |
|
|
6 |
$this->assertTrue(is_writable($dbFolder)); |
|
7 |
$this->assertTrue(count(glob($dbFolder.'/*.sqlite')) == 0); |
|
8 |
} |
|
9 |
|
|
10 |
/** |
|
11 |
* @depends testSessionFolder |
|
12 |
*/ |
|
13 |
function testPullEmpty() { |
|
14 |
$dbFolder = dirname(__FILE__).'/../../database'; |
|
15 |
|
|
16 |
$session = new BotSession('test://user1@test'); |
|
17 |
$session->setClass('test'); |
|
18 |
|
|
19 |
$this->assertEquals(array(), $session->pull()); |
|
20 |
$this->assertTrue(count(glob($dbFolder.'/*.sqlite')) == 1); |
|
21 |
} |
|
22 |
|
|
23 |
/** |
|
24 |
* @depends testPullEmpty |
|
25 |
* @expectedException Exception |
|
26 |
*/ |
|
27 |
function testSetClass() { |
|
28 |
$session = new BotSession('test://user1'); |
|
29 |
$session->pull(); |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* @depends testPullEmpty |
|
34 |
*/ |
|
35 |
function testLegacyImport() { |
|
36 |
$dbFolder = dirname(__FILE__).'/../../database'; |
|
37 |
$oldDbFolder = $dbFolder = dirname(__FILE__).'/../../db'; |
|
38 |
|
|
39 |
$data = array('test' => true, 'other' => 'yes, sir!'); |
|
40 |
$data_serialized = serialize($data); |
|
41 |
|
|
42 |
$this->assertTrue(mkdir($oldDbFolder)); |
|
43 |
$this->assertTrue(is_writable($oldDbFolder)); |
|
44 |
$this->assertTrue(mkdir($oldDbFolder.'/test')); |
|
45 |
|
|
46 |
$filename = $oldDbFolder.'/test/testUser.ggdb'; |
|
47 |
$this->assertEquals(strlen($data_serialized), file_put_contents($filename, $data_serialized)); |
|
48 |
$this->assertEquals($data_serialized, file_get_contents($filename)); |
|
49 |
|
|
50 |
$session = new BotSession('test://testUser@test'); |
|
51 |
$session->setClass('test'); |
|
52 |
|
|
53 |
$this->assertTrue(isset($session->test)); |
|
54 |
$this->assertEquals($data, $session->pull()); |
|
55 |
|
|
56 |
$this->assertFalse(file_exists($filename)); |
|
57 |
$this->assertTrue(rmdir($oldDbFolder.'/test')); |
|
58 |
$this->assertTrue(rmdir($oldDbFolder)); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* @depends testPullEmpty |
|
63 |
*/ |
|
64 |
function testManualExample() { |
|
65 |
$session = new BotSession('test://user1@test'); |
|
66 |
$session->setClass('test'); |
|
67 |
|
|
68 |
// Ustawienie pojedynczej wartości |
|
69 |
$session->zmienna = 'To jest test'; |
|
70 |
$this->assertTrue(isset($session->zmienna)); |
|
71 |
$this->assertEquals('To jest test', $session->zmienna); |
|
72 |
|
|
73 |
// Usunięcie pojedynczej wartości |
|
74 |
unset($session->zmienna); |
|
75 |
$this->assertFalse(isset($session->zmienna)); |
|
76 |
$this->assertEquals(NULL, $session->zmienna); |
|
77 |
|
|
78 |
// Ustawienie pojedynczej wartości ponownie |
|
79 |
$session->zmienna = 'To jest test'; |
|
80 |
$this->assertTrue(isset($session->zmienna)); |
|
81 |
$this->assertEquals('To jest test', $session->zmienna); |
|
82 |
|
|
83 |
// Usunięcie wszystkich danych |
|
84 |
$session->truncate(); |
|
85 |
$this->assertFalse(isset($session->zmienna)); |
|
86 |
$this->assertEquals(NULL, $session->zmienna); |
|
87 |
$this->assertEquals(array(), $session->pull()); |
|
88 |
|
|
89 |
// Dopisanie (nadpisanie) danych |
|
90 |
$array = array( |
|
91 |
'zmienna' => 'To jest test2', |
|
92 |
'zmienna2' => new DateTime('2012-01-10') |
|
93 |
); |
|
94 |
$session->push($array); |
|
95 |
|
|
96 |
$this->assertEquals('To jest test2', $session->zmienna); |
|
97 |
$this->assertEquals($array, $session->pull()); |
|
98 |
|
|
99 |
// push() nie usuwa istniejących danych |
|
100 |
$session->zmienna3 = '333'; |
|
101 |
$session->push($array); |
|
102 |
$this->assertNotEquals($array, $session->pull()); |
|
103 |
|
|
104 |
unset($this->session); |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* @depends testManualExample |
|
109 |
*/ |
|
110 |
function testManualExample2() { |
|
111 |
$session = new BotSession('test://user1@test'); |
|
112 |
$session->setClass('test'); |
|
113 |
|
|
114 |
$array = array( |
|
115 |
'zmienna' => 'To jest test2', |
|
116 |
'zmienna2' => new DateTime('2012-01-10'), |
|
117 |
'zmienna3' => '333' |
|
118 |
); |
|
119 |
|
|
120 |
$this->assertEquals($array, $session->pull()); |
|
121 |
|
|
122 |
|
|
123 |
$session->setClass('test2'); |
|
124 |
$this->assertEquals(array(), $session->pull()); |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* @depends testManualExample2 |
|
129 |
*/ |
|
130 |
function testCleanup() { |
|
131 |
$dbFolder = dirname(__FILE__).'/../../database'; |
|
132 |
foreach(glob($dbFolder.'/*.sqlite') as $file) { |
|
133 |
unlink($file); |
|
134 |
} |
|
135 |
} |
|
136 |
} |