aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Updater
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-06-09 20:04:02 +0200
committerArthurHoaro <arthur@hoa.ro>2016-06-11 09:30:56 +0200
commit278d9ee2836df7d805845077f26f8cecd16f0f4f (patch)
tree9155cab8890074e83b54efaa649bfa74885d3ab5 /tests/Updater
parent7f179985b497053c59338667fe49c390aa626ab7 (diff)
downloadShaarli-278d9ee2836df7d805845077f26f8cecd16f0f4f.tar.gz
Shaarli-278d9ee2836df7d805845077f26f8cecd16f0f4f.tar.zst
Shaarli-278d9ee2836df7d805845077f26f8cecd16f0f4f.zip
ConfigManager no longer uses singleton pattern
Diffstat (limited to 'tests/Updater')
-rw-r--r--tests/Updater/DummyUpdater.php11
-rw-r--r--tests/Updater/UpdaterTest.php57
2 files changed, 34 insertions, 34 deletions
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}