diff options
Diffstat (limited to 'tests/LinkDBTest.php')
-rw-r--r-- | tests/LinkDBTest.php | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 3b68dd20..a54fc501 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -7,9 +7,6 @@ require_once 'application/LinkDB.php'; | |||
7 | require_once 'application/Utils.php'; | 7 | require_once 'application/Utils.php'; |
8 | require_once 'tests/utils/ReferenceLinkDB.php'; | 8 | require_once 'tests/utils/ReferenceLinkDB.php'; |
9 | 9 | ||
10 | define('PHPPREFIX', '<?php /* '); | ||
11 | define('PHPSUFFIX', ' */ ?>'); | ||
12 | |||
13 | 10 | ||
14 | /** | 11 | /** |
15 | * Unitary tests for LinkDB | 12 | * Unitary tests for LinkDB |
@@ -38,11 +35,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
38 | public static function setUpBeforeClass() | 35 | public static function setUpBeforeClass() |
39 | { | 36 | { |
40 | self::$refDB = new ReferenceLinkDB(); | 37 | self::$refDB = new ReferenceLinkDB(); |
41 | self::$refDB->write(self::$testDatastore, PHPPREFIX, PHPSUFFIX); | 38 | self::$refDB->write(self::$testDatastore); |
42 | 39 | ||
43 | $GLOBALS['config']['DATASTORE'] = self::$testDatastore; | 40 | self::$publicLinkDB = new LinkDB(self::$testDatastore, false, false); |
44 | self::$publicLinkDB = new LinkDB(false, false); | 41 | self::$privateLinkDB = new LinkDB(self::$testDatastore, true, false); |
45 | self::$privateLinkDB = new LinkDB(true, false); | ||
46 | } | 42 | } |
47 | 43 | ||
48 | /** | 44 | /** |
@@ -50,7 +46,6 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
50 | */ | 46 | */ |
51 | protected function setUp() | 47 | protected function setUp() |
52 | { | 48 | { |
53 | $GLOBALS['config']['DATASTORE'] = self::$testDatastore; | ||
54 | if (file_exists(self::$testDatastore)) { | 49 | if (file_exists(self::$testDatastore)) { |
55 | unlink(self::$testDatastore); | 50 | unlink(self::$testDatastore); |
56 | } | 51 | } |
@@ -76,7 +71,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
76 | */ | 71 | */ |
77 | public function testConstructLoggedIn() | 72 | public function testConstructLoggedIn() |
78 | { | 73 | { |
79 | new LinkDB(true, false); | 74 | new LinkDB(self::$testDatastore, true, false); |
80 | $this->assertFileExists(self::$testDatastore); | 75 | $this->assertFileExists(self::$testDatastore); |
81 | } | 76 | } |
82 | 77 | ||
@@ -85,7 +80,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
85 | */ | 80 | */ |
86 | public function testConstructLoggedOut() | 81 | public function testConstructLoggedOut() |
87 | { | 82 | { |
88 | new LinkDB(false, false); | 83 | new LinkDB(self::$testDatastore, false, false); |
89 | $this->assertFileExists(self::$testDatastore); | 84 | $this->assertFileExists(self::$testDatastore); |
90 | } | 85 | } |
91 | 86 | ||
@@ -97,8 +92,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
97 | */ | 92 | */ |
98 | public function testConstructDatastoreNotWriteable() | 93 | public function testConstructDatastoreNotWriteable() |
99 | { | 94 | { |
100 | $GLOBALS['config']['DATASTORE'] = 'null/store.db'; | 95 | new LinkDB('null/store.db', false, false); |
101 | new LinkDB(false, false); | ||
102 | } | 96 | } |
103 | 97 | ||
104 | /** | 98 | /** |
@@ -106,7 +100,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
106 | */ | 100 | */ |
107 | public function testCheckDBNew() | 101 | public function testCheckDBNew() |
108 | { | 102 | { |
109 | $linkDB = new LinkDB(false, false); | 103 | $linkDB = new LinkDB(self::$testDatastore, false, false); |
110 | unlink(self::$testDatastore); | 104 | unlink(self::$testDatastore); |
111 | $this->assertFileNotExists(self::$testDatastore); | 105 | $this->assertFileNotExists(self::$testDatastore); |
112 | 106 | ||
@@ -126,7 +120,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
126 | */ | 120 | */ |
127 | public function testCheckDBLoad() | 121 | public function testCheckDBLoad() |
128 | { | 122 | { |
129 | $linkDB = new LinkDB(false, false); | 123 | $linkDB = new LinkDB(self::$testDatastore, false, false); |
130 | $this->assertEquals( | 124 | $this->assertEquals( |
131 | self::$dummyDatastoreFilesize, | 125 | self::$dummyDatastoreFilesize, |
132 | filesize(self::$testDatastore) | 126 | filesize(self::$testDatastore) |
@@ -147,8 +141,8 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
147 | */ | 141 | */ |
148 | public function testReadEmptyDB() | 142 | public function testReadEmptyDB() |
149 | { | 143 | { |
150 | file_put_contents(self::$testDatastore, PHPPREFIX.'S7QysKquBQA='.PHPSUFFIX); | 144 | file_put_contents(self::$testDatastore, '<?php /* S7QysKquBQA= */ ?>'); |
151 | $emptyDB = new LinkDB(false, false); | 145 | $emptyDB = new LinkDB(self::$testDatastore, false, false); |
152 | $this->assertEquals(0, sizeof($emptyDB)); | 146 | $this->assertEquals(0, sizeof($emptyDB)); |
153 | $this->assertEquals(0, count($emptyDB)); | 147 | $this->assertEquals(0, count($emptyDB)); |
154 | } | 148 | } |
@@ -180,7 +174,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
180 | */ | 174 | */ |
181 | public function testSaveDB() | 175 | public function testSaveDB() |
182 | { | 176 | { |
183 | $testDB = new LinkDB(true, false); | 177 | $testDB = new LinkDB(self::$testDatastore, true, false); |
184 | $dbSize = sizeof($testDB); | 178 | $dbSize = sizeof($testDB); |
185 | 179 | ||
186 | $link = array( | 180 | $link = array( |
@@ -198,7 +192,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
198 | 192 | ||
199 | $testDB->savedb(); | 193 | $testDB->savedb(); |
200 | 194 | ||
201 | $testDB = new LinkDB(true, false); | 195 | $testDB = new LinkDB(self::$testDatastore, true, false); |
202 | $this->assertEquals($dbSize + 1, sizeof($testDB)); | 196 | $this->assertEquals($dbSize + 1, sizeof($testDB)); |
203 | } | 197 | } |
204 | 198 | ||
@@ -222,7 +216,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
222 | */ | 216 | */ |
223 | public function testCountHiddenPublic() | 217 | public function testCountHiddenPublic() |
224 | { | 218 | { |
225 | $linkDB = new LinkDB(false, true); | 219 | $linkDB = new LinkDB(self::$testDatastore, false, true); |
226 | 220 | ||
227 | $this->assertEquals( | 221 | $this->assertEquals( |
228 | 0, | 222 | 0, |