aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ApplicationUtilsTest.php8
-rw-r--r--tests/Updater/DummyUpdater.php11
-rw-r--r--tests/Updater/UpdaterTest.php57
-rw-r--r--tests/config/ConfigManagerTest.php28
4 files changed, 51 insertions, 53 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index f92412ba..3da72639 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.php
@@ -276,7 +276,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
276 */ 276 */
277 public function testCheckCurrentResourcePermissions() 277 public function testCheckCurrentResourcePermissions()
278 { 278 {
279 $conf = ConfigManager::getInstance(); 279 $conf = new ConfigManager('');
280 $conf->set('path.thumbnails_cache', 'cache'); 280 $conf->set('path.thumbnails_cache', 'cache');
281 $conf->set('path.config', 'data/config.php'); 281 $conf->set('path.config', 'data/config.php');
282 $conf->set('path.data_dir', 'data'); 282 $conf->set('path.data_dir', 'data');
@@ -290,7 +290,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
290 290
291 $this->assertEquals( 291 $this->assertEquals(
292 array(), 292 array(),
293 ApplicationUtils::checkResourcePermissions() 293 ApplicationUtils::checkResourcePermissions($conf)
294 ); 294 );
295 } 295 }
296 296
@@ -299,7 +299,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
299 */ 299 */
300 public function testCheckCurrentResourcePermissionsErrors() 300 public function testCheckCurrentResourcePermissionsErrors()
301 { 301 {
302 $conf = ConfigManager::getInstance(); 302 $conf = new ConfigManager('');
303 $conf->set('path.thumbnails_cache', 'null/cache'); 303 $conf->set('path.thumbnails_cache', 'null/cache');
304 $conf->set('path.config', 'null/data/config.php'); 304 $conf->set('path.config', 'null/data/config.php');
305 $conf->set('path.data_dir', 'null/data'); 305 $conf->set('path.data_dir', 'null/data');
@@ -322,7 +322,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
322 '"null/tmp" directory is not readable', 322 '"null/tmp" directory is not readable',
323 '"null/tmp" directory is not writable' 323 '"null/tmp" directory is not writable'
324 ), 324 ),
325 ApplicationUtils::checkResourcePermissions() 325 ApplicationUtils::checkResourcePermissions($conf)
326 ); 326 );
327 } 327 }
328} 328}
diff --git a/tests/Updater/DummyUpdater.php b/tests/Updater/DummyUpdater.php
index 6724b203..a0be4413 100644
--- a/tests/Updater/DummyUpdater.php
+++ b/tests/Updater/DummyUpdater.php
@@ -11,13 +11,14 @@ class DummyUpdater extends Updater
11 /** 11 /**
12 * Object constructor. 12 * Object constructor.
13 * 13 *
14 * @param array $doneUpdates Updates which are already done. 14 * @param array $doneUpdates Updates which are already done.
15 * @param LinkDB $linkDB LinkDB instance. 15 * @param LinkDB $linkDB LinkDB instance.
16 * @param boolean $isLoggedIn True if the user is logged in. 16 * @param ConfigManager $conf Configuration Manager instance.
17 * @param boolean $isLoggedIn True if the user is logged in.
17 */ 18 */
18 public function __construct($doneUpdates, $linkDB, $isLoggedIn) 19 public function __construct($doneUpdates, $linkDB, $conf, $isLoggedIn)
19 { 20 {
20 parent::__construct($doneUpdates, $linkDB, $isLoggedIn); 21 parent::__construct($doneUpdates, $linkDB, $conf, $isLoggedIn);
21 22
22 // Retrieve all update methods. 23 // Retrieve all update methods.
23 // For unit test, only retrieve final methods, 24 // For unit test, only retrieve final methods,
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php
index 04883a46..5ed2df6c 100644
--- a/tests/Updater/UpdaterTest.php
+++ b/tests/Updater/UpdaterTest.php
@@ -29,8 +29,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
29 */ 29 */
30 public function setUp() 30 public function setUp()
31 { 31 {
32 ConfigManager::$CONFIG_FILE = self::$configFile; 32 $this->conf = new ConfigManager(self::$configFile);
33 $this->conf = ConfigManager::reset();
34 } 33 }
35 34
36 /** 35 /**
@@ -108,10 +107,10 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
108 'updateMethodDummy3', 107 'updateMethodDummy3',
109 'updateMethodException', 108 'updateMethodException',
110 ); 109 );
111 $updater = new DummyUpdater($updates, array(), true); 110 $updater = new DummyUpdater($updates, array(), $this->conf, true);
112 $this->assertEquals(array(), $updater->update()); 111 $this->assertEquals(array(), $updater->update());
113 112
114 $updater = new DummyUpdater(array(), array(), false); 113 $updater = new DummyUpdater(array(), array(), $this->conf, false);
115 $this->assertEquals(array(), $updater->update()); 114 $this->assertEquals(array(), $updater->update());
116 } 115 }
117 116
@@ -126,7 +125,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
126 'updateMethodDummy2', 125 'updateMethodDummy2',
127 'updateMethodDummy3', 126 'updateMethodDummy3',
128 ); 127 );
129 $updater = new DummyUpdater($updates, array(), true); 128 $updater = new DummyUpdater($updates, array(), $this->conf, true);
130 $this->assertEquals($expectedUpdates, $updater->update()); 129 $this->assertEquals($expectedUpdates, $updater->update());
131 } 130 }
132 131
@@ -142,7 +141,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
142 ); 141 );
143 $expectedUpdate = array('updateMethodDummy2'); 142 $expectedUpdate = array('updateMethodDummy2');
144 143
145 $updater = new DummyUpdater($updates, array(), true); 144 $updater = new DummyUpdater($updates, array(), $this->conf, true);
146 $this->assertEquals($expectedUpdate, $updater->update()); 145 $this->assertEquals($expectedUpdate, $updater->update());
147 } 146 }
148 147
@@ -159,7 +158,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
159 'updateMethodDummy3', 158 'updateMethodDummy3',
160 ); 159 );
161 160
162 $updater = new DummyUpdater($updates, array(), true); 161 $updater = new DummyUpdater($updates, array(), $this->conf, true);
163 $updater->update(); 162 $updater->update();
164 } 163 }
165 164
@@ -172,8 +171,8 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
172 */ 171 */
173 public function testUpdateMergeDeprecatedConfig() 172 public function testUpdateMergeDeprecatedConfig()
174 { 173 {
175 ConfigManager::$CONFIG_FILE = 'tests/utils/config/configPhp'; 174 $this->conf->setConfigFile('tests/utils/config/configPhp');
176 $this->conf = $this->conf->reset(); 175 $this->conf->reset();
177 176
178 $optionsFile = 'tests/Updater/options.php'; 177 $optionsFile = 'tests/Updater/options.php';
179 $options = '<?php 178 $options = '<?php
@@ -181,10 +180,10 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
181 file_put_contents($optionsFile, $options); 180 file_put_contents($optionsFile, $options);
182 181
183 // tmp config file. 182 // tmp config file.
184 ConfigManager::$CONFIG_FILE = 'tests/Updater/config'; 183 $this->conf->setConfigFile('tests/Updater/config');
185 184
186 // merge configs 185 // merge configs
187 $updater = new Updater(array(), array(), true); 186 $updater = new Updater(array(), array(), $this->conf, true);
188 // This writes a new config file in tests/Updater/config.php 187 // This writes a new config file in tests/Updater/config.php
189 $updater->updateMethodMergeDeprecatedConfigFile(); 188 $updater->updateMethodMergeDeprecatedConfigFile();
190 189
@@ -193,7 +192,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
193 $this->assertTrue($this->conf->get('general.default_private_links')); 192 $this->assertTrue($this->conf->get('general.default_private_links'));
194 $this->assertFalse(is_file($optionsFile)); 193 $this->assertFalse(is_file($optionsFile));
195 // Delete the generated file. 194 // Delete the generated file.
196 unlink($this->conf->getConfigFile()); 195 unlink($this->conf->getConfigFileExt());
197 } 196 }
198 197
199 /** 198 /**
@@ -201,7 +200,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
201 */ 200 */
202 public function testMergeDeprecatedConfigNoFile() 201 public function testMergeDeprecatedConfigNoFile()
203 { 202 {
204 $updater = new Updater(array(), array(), true); 203 $updater = new Updater(array(), array(), $this->conf, true);
205 $updater->updateMethodMergeDeprecatedConfigFile(); 204 $updater->updateMethodMergeDeprecatedConfigFile();
206 205
207 $this->assertEquals('root', $this->conf->get('credentials.login')); 206 $this->assertEquals('root', $this->conf->get('credentials.login'));
@@ -216,7 +215,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
216 $refDB->write(self::$testDatastore); 215 $refDB->write(self::$testDatastore);
217 $linkDB = new LinkDB(self::$testDatastore, true, false); 216 $linkDB = new LinkDB(self::$testDatastore, true, false);
218 $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); 217 $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
219 $updater = new Updater(array(), $linkDB, true); 218 $updater = new Updater(array(), $linkDB, $this->conf, true);
220 $updater->updateMethodRenameDashTags(); 219 $updater->updateMethodRenameDashTags();
221 $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); 220 $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
222 } 221 }
@@ -227,29 +226,29 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
227 public function testConfigToJson() 226 public function testConfigToJson()
228 { 227 {
229 $configFile = 'tests/utils/config/configPhp'; 228 $configFile = 'tests/utils/config/configPhp';
230 ConfigManager::$CONFIG_FILE = $configFile; 229 $this->conf->setConfigFile($configFile);
231 $conf = ConfigManager::reset(); 230 $this->conf->reset();
232 231
233 // The ConfigIO is initialized with ConfigPhp. 232 // The ConfigIO is initialized with ConfigPhp.
234 $this->assertTrue($conf->getConfigIO() instanceof ConfigPhp); 233 $this->assertTrue($this->conf->getConfigIO() instanceof ConfigPhp);
235 234
236 $updater = new Updater(array(), array(), false); 235 $updater = new Updater(array(), array(), $this->conf, false);
237 $done = $updater->updateMethodConfigToJson(); 236 $done = $updater->updateMethodConfigToJson();
238 $this->assertTrue($done); 237 $this->assertTrue($done);
239 238
240 // The ConfigIO has been updated to ConfigJson. 239 // The ConfigIO has been updated to ConfigJson.
241 $this->assertTrue($conf->getConfigIO() instanceof ConfigJson); 240 $this->assertTrue($this->conf->getConfigIO() instanceof ConfigJson);
242 $this->assertTrue(file_exists($conf->getConfigFile())); 241 $this->assertTrue(file_exists($this->conf->getConfigFileExt()));
243 242
244 // Check JSON config data. 243 // Check JSON config data.
245 $conf->reload(); 244 $this->conf->reload();
246 $this->assertEquals('root', $conf->get('credentials.login')); 245 $this->assertEquals('root', $this->conf->get('credentials.login'));
247 $this->assertEquals('lala', $conf->get('extras.redirector')); 246 $this->assertEquals('lala', $this->conf->get('extras.redirector'));
248 $this->assertEquals('data/datastore.php', $conf->get('path.datastore')); 247 $this->assertEquals('data/datastore.php', $this->conf->get('path.datastore'));
249 $this->assertEquals('1', $conf->get('plugins.WALLABAG_VERSION')); 248 $this->assertEquals('1', $this->conf->get('plugins.WALLABAG_VERSION'));
250 249
251 rename($configFile . '.save.php', $configFile . '.php'); 250 rename($configFile . '.save.php', $configFile . '.php');
252 unlink($conf->getConfigFile()); 251 unlink($this->conf->getConfigFileExt());
253 } 252 }
254 253
255 /** 254 /**
@@ -257,11 +256,11 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
257 */ 256 */
258 public function testConfigToJsonNothingToDo() 257 public function testConfigToJsonNothingToDo()
259 { 258 {
260 $filetime = filemtime($this->conf->getConfigFile()); 259 $filetime = filemtime($this->conf->getConfigFileExt());
261 $updater = new Updater(array(), array(), false); 260 $updater = new Updater(array(), array(), $this->conf, false);
262 $done = $updater->updateMethodConfigToJson(); 261 $done = $updater->updateMethodConfigToJson();
263 $this->assertTrue($done); 262 $this->assertTrue($done);
264 $expected = filemtime($this->conf->getConfigFile()); 263 $expected = filemtime($this->conf->getConfigFileExt());
265 $this->assertEquals($expected, $filetime); 264 $this->assertEquals($expected, $filetime);
266 } 265 }
267} 266}
diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php
index 9ff0f473..436e3d67 100644
--- a/tests/config/ConfigManagerTest.php
+++ b/tests/config/ConfigManagerTest.php
@@ -15,8 +15,7 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase
15 15
16 public function setUp() 16 public function setUp()
17 { 17 {
18 ConfigManager::$CONFIG_FILE = 'tests/utils/config/configJson'; 18 $this->conf = new ConfigManager('tests/utils/config/configJson');
19 $this->conf = ConfigManager::reset();
20 } 19 }
21 20
22 /** 21 /**
@@ -54,10 +53,10 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase
54 $this->conf->set('paramArray', array('foo' => 'bar')); 53 $this->conf->set('paramArray', array('foo' => 'bar'));
55 $this->conf->set('paramNull', null); 54 $this->conf->set('paramNull', null);
56 55
57 ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; 56 $this->conf->setConfigFile('tests/utils/config/configTmp');
58 $this->conf->write(true); 57 $this->conf->write(true);
59 $this->conf->reload(); 58 $this->conf->reload();
60 unlink($this->conf->getConfigFile()); 59 unlink($this->conf->getConfigFileExt());
61 60
62 $this->assertEquals(42, $this->conf->get('paramInt')); 61 $this->assertEquals(42, $this->conf->get('paramInt'));
63 $this->assertEquals('value1', $this->conf->get('paramString')); 62 $this->assertEquals('value1', $this->conf->get('paramString'));
@@ -73,10 +72,10 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase
73 { 72 {
74 $this->conf->set('foo.bar.key.stuff', 'testSetWriteGetNested'); 73 $this->conf->set('foo.bar.key.stuff', 'testSetWriteGetNested');
75 74
76 ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; 75 $this->conf->setConfigFile('tests/utils/config/configTmp');
77 $this->conf->write(true); 76 $this->conf->write(true);
78 $this->conf->reload(); 77 $this->conf->reload();
79 unlink($this->conf->getConfigFile()); 78 unlink($this->conf->getConfigFileExt());
80 79
81 $this->assertEquals('testSetWriteGetNested', $this->conf->get('foo.bar.key.stuff')); 80 $this->assertEquals('testSetWriteGetNested', $this->conf->get('foo.bar.key.stuff'));
82 } 81 }
@@ -110,8 +109,8 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase
110 */ 109 */
111 public function testWriteMissingParameter() 110 public function testWriteMissingParameter()
112 { 111 {
113 ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; 112 $this->conf->setConfigFile('tests/utils/config/configTmp');
114 $this->assertFalse(file_exists($this->conf->getConfigFile())); 113 $this->assertFalse(file_exists($this->conf->getConfigFileExt()));
115 $this->conf->reload(); 114 $this->conf->reload();
116 115
117 $this->conf->write(true); 116 $this->conf->write(true);
@@ -151,10 +150,9 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase
151 */ 150 */
152 public function testReset() 151 public function testReset()
153 { 152 {
154 $conf = $this->conf; 153 $confIO = $this->conf->getConfigIO();
155 $this->assertTrue($conf === ConfigManager::getInstance()); 154 $this->conf->reset();
156 $this->assertFalse($conf === $this->conf->reset()); 155 $this->assertFalse($confIO === $this->conf->getConfigIO());
157 $this->assertFalse($conf === ConfigManager::getInstance());
158 } 156 }
159 157
160 /** 158 /**
@@ -162,11 +160,11 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase
162 */ 160 */
163 public function testReload() 161 public function testReload()
164 { 162 {
165 ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; 163 $this->conf->setConfigFile('tests/utils/config/configTmp');
166 $newConf = ConfigJson::getPhpHeaders() . '{ "key": "value" }'; 164 $newConf = ConfigJson::getPhpHeaders() . '{ "key": "value" }';
167 file_put_contents($this->conf->getConfigFile(), $newConf); 165 file_put_contents($this->conf->getConfigFileExt(), $newConf);
168 $this->conf->reload(); 166 $this->conf->reload();
169 unlink($this->conf->getConfigFile()); 167 unlink($this->conf->getConfigFileExt());
170 // Previous conf no longer exists, and new values have been loaded. 168 // Previous conf no longer exists, and new values have been loaded.
171 $this->assertFalse($this->conf->exists('credentials.login')); 169 $this->assertFalse($this->conf->exists('credentials.login'));
172 $this->assertEquals('value', $this->conf->get('key')); 170 $this->assertEquals('value', $this->conf->get('key'));