diff options
author | VirtualTam <virtualtam@flibidi.net> | 2015-06-24 23:01:21 +0200 |
---|---|---|
committer | VirtualTam <virtualtam@flibidi.net> | 2015-06-24 23:26:52 +0200 |
commit | 9c8752a2061e67c719125edb6e0d6717d1af8553 (patch) | |
tree | d7f05ff1ce871105bb44625baeacc8e8b2bfec2b /tests | |
parent | 64bc92e3ac8f5e66d2bc14206ede31e6679d8c13 (diff) | |
download | Shaarli-9c8752a2061e67c719125edb6e0d6717d1af8553.tar.gz Shaarli-9c8752a2061e67c719125edb6e0d6717d1af8553.tar.zst Shaarli-9c8752a2061e67c719125edb6e0d6717d1af8553.zip |
LinkDB: do not access global variables
Relates to #218
Removes "hidden" access to the following variables:
- $GLOBALS['config']['datastore']
- PHPPREFIX
- PHPSUFFIX
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/LinkDBTest.php | 32 | ||||
-rw-r--r-- | tests/utils/ReferenceLinkDB.php | 4 |
2 files changed, 15 insertions, 21 deletions
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index f67d4d9b..0d343359 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::$dummyDatastoreSHA1, | 125 | self::$dummyDatastoreSHA1, |
132 | sha1_file(self::$testDatastore) | 126 | sha1_file(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, |
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php index 2cb05bae..59ba671f 100644 --- a/tests/utils/ReferenceLinkDB.php +++ b/tests/utils/ReferenceLinkDB.php | |||
@@ -93,11 +93,11 @@ class ReferenceLinkDB | |||
93 | /** | 93 | /** |
94 | * Writes data to the datastore | 94 | * Writes data to the datastore |
95 | */ | 95 | */ |
96 | public function write($filename, $prefix, $suffix) | 96 | public function write($filename) |
97 | { | 97 | { |
98 | file_put_contents( | 98 | file_put_contents( |
99 | $filename, | 99 | $filename, |
100 | $prefix.base64_encode(gzdeflate(serialize($this->links))).$suffix | 100 | '<?php /* '.base64_encode(gzdeflate(serialize($this->links))).' */ ?>' |
101 | ); | 101 | ); |
102 | } | 102 | } |
103 | 103 | ||