diff options
Diffstat (limited to 'tests/Updater/UpdaterTest.php')
-rw-r--r-- | tests/Updater/UpdaterTest.php | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 8bfb4ba3..f8de2f70 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php | |||
@@ -20,9 +20,9 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
20 | protected static $testDatastore = 'sandbox/datastore.php'; | 20 | protected static $testDatastore = 'sandbox/datastore.php'; |
21 | 21 | ||
22 | /** | 22 | /** |
23 | * @var string Config file path. | 23 | * @var string Config file path (without extension). |
24 | */ | 24 | */ |
25 | protected static $configFile = 'tests/Updater/config.php'; | 25 | protected static $configFile = 'tests/utils/config/configUpdater'; |
26 | 26 | ||
27 | /** | 27 | /** |
28 | * @var ConfigManager | 28 | * @var ConfigManager |
@@ -52,8 +52,9 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
52 | ) | 52 | ) |
53 | ); | 53 | ); |
54 | 54 | ||
55 | ConfigManager::$CONFIG_FILE = 'tests/Updater/config'; | 55 | ConfigManager::$CONFIG_FILE = self::$configFile; |
56 | $this->conf = ConfigManager::getInstance(); | 56 | $this->conf = ConfigManager::reset(); |
57 | $this->conf->reload(); | ||
57 | foreach (self::$configFields as $key => $value) { | 58 | foreach (self::$configFields as $key => $value) { |
58 | $this->conf->set($key, $value); | 59 | $this->conf->set($key, $value); |
59 | } | 60 | } |
@@ -67,8 +68,8 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
67 | */ | 68 | */ |
68 | public function tearDown() | 69 | public function tearDown() |
69 | { | 70 | { |
70 | if (is_file(self::$configFile)) { | 71 | if (is_file('tests/Updater/config.json')) { |
71 | unlink(self::$configFile); | 72 | unlink('tests/Updater/config.json'); |
72 | } | 73 | } |
73 | 74 | ||
74 | if (is_file(self::$configFields['config']['DATADIR'] . '/options.php')) { | 75 | if (is_file(self::$configFields['config']['DATADIR'] . '/options.php')) { |
@@ -214,6 +215,8 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
214 | { | 215 | { |
215 | // Use writeConfig to create a options.php | 216 | // Use writeConfig to create a options.php |
216 | ConfigManager::$CONFIG_FILE = 'tests/Updater/options'; | 217 | ConfigManager::$CONFIG_FILE = 'tests/Updater/options'; |
218 | $this->conf->setConfigIO(new ConfigPhp()); | ||
219 | |||
217 | $invert = !$this->conf->get('privateLinkByDefault'); | 220 | $invert = !$this->conf->get('privateLinkByDefault'); |
218 | $this->conf->set('privateLinkByDefault', $invert); | 221 | $this->conf->set('privateLinkByDefault', $invert); |
219 | $this->conf->write(true); | 222 | $this->conf->write(true); |
@@ -225,12 +228,15 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
225 | 228 | ||
226 | // merge configs | 229 | // merge configs |
227 | $updater = new Updater(array(), array(), true); | 230 | $updater = new Updater(array(), array(), true); |
231 | // This writes a new config file in tests/Updater/config.php | ||
228 | $updater->updateMethodMergeDeprecatedConfigFile(); | 232 | $updater->updateMethodMergeDeprecatedConfigFile(); |
229 | 233 | ||
230 | // make sure updated field is changed | 234 | // make sure updated field is changed |
231 | $this->conf->reload(); | 235 | $this->conf->reload(); |
232 | $this->assertEquals($invert, $this->conf->get('privateLinkByDefault')); | 236 | $this->assertEquals($invert, $this->conf->get('privateLinkByDefault')); |
233 | $this->assertFalse(is_file($optionsFile)); | 237 | $this->assertFalse(is_file($optionsFile)); |
238 | // Delete the generated file. | ||
239 | unlink($this->conf->getConfigFile()); | ||
234 | } | 240 | } |
235 | 241 | ||
236 | /** | 242 | /** |
@@ -257,4 +263,52 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
257 | $updater->updateMethodRenameDashTags(); | 263 | $updater->updateMethodRenameDashTags(); |
258 | $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); | 264 | $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); |
259 | } | 265 | } |
266 | |||
267 | /** | ||
268 | * Convert old PHP config file to JSON config. | ||
269 | */ | ||
270 | public function testConfigToJson() | ||
271 | { | ||
272 | $configFile = 'tests/utils/config/configPhp'; | ||
273 | ConfigManager::$CONFIG_FILE = $configFile; | ||
274 | $conf = ConfigManager::reset(); | ||
275 | |||
276 | // The ConfigIO is initialized with ConfigPhp. | ||
277 | $this->assertTrue($conf->getConfigIO() instanceof ConfigPhp); | ||
278 | |||
279 | $updater = new Updater(array(), array(), false); | ||
280 | $done = $updater->updateMethodConfigToJson(); | ||
281 | $this->assertTrue($done); | ||
282 | |||
283 | // The ConfigIO has been updated to ConfigJson. | ||
284 | $this->assertTrue($conf->getConfigIO() instanceof ConfigJson); | ||
285 | $this->assertTrue(file_exists($conf->getConfigFile())); | ||
286 | |||
287 | // Check JSON config data. | ||
288 | $conf->reload(); | ||
289 | $this->assertEquals('root', $conf->get('login')); | ||
290 | $this->assertEquals('lala', $conf->get('redirector')); | ||
291 | $this->assertEquals('data/datastore.php', $conf->get('config.DATASTORE')); | ||
292 | $this->assertEquals('1', $conf->get('plugins.WALLABAG_VERSION')); | ||
293 | |||
294 | rename($configFile . '.save.php', $configFile . '.php'); | ||
295 | unlink($conf->getConfigFile()); | ||
296 | } | ||
297 | |||
298 | /** | ||
299 | * Launch config conversion update with an existing JSON file => nothing to do. | ||
300 | */ | ||
301 | public function testConfigToJsonNothingToDo() | ||
302 | { | ||
303 | $configFile = 'tests/utils/config/configUpdateDone'; | ||
304 | ConfigManager::$CONFIG_FILE = $configFile; | ||
305 | $conf = ConfigManager::reset(); | ||
306 | $conf->reload(); | ||
307 | $filetime = filemtime($conf->getConfigFile()); | ||
308 | $updater = new Updater(array(), array(), false); | ||
309 | $done = $updater->updateMethodConfigToJson(); | ||
310 | $this->assertTrue($done); | ||
311 | $expected = filemtime($conf->getConfigFile()); | ||
312 | $this->assertEquals($expected, $filetime); | ||
313 | } | ||
260 | } | 314 | } |