From 684e662a58b02bde225e44d3677987b6fc3adf0b Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 18 May 2016 21:48:24 +0200 Subject: Replace $GLOBALS configuration with the configuration manager in the whole code base --- tests/Updater/UpdaterTest.php | 80 ++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 32 deletions(-) (limited to 'tests/Updater/UpdaterTest.php') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index a29d9067..8bfb4ba3 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -1,5 +1,6 @@ false, 'privateLinkByDefault' => false, 'config' => array( - 'CONFIG_FILE' => 'tests/Updater/config.php', 'DATADIR' => 'tests/Updater', 'PAGECACHE' => 'sandbox/pagecache', 'config1' => 'config1data', 'config2' => 'config2data', ) ); + + ConfigManager::$CONFIG_FILE = 'tests/Updater/config'; + $this->conf = ConfigManager::getInstance(); + foreach (self::$configFields as $key => $value) { + $this->conf->set($key, $value); + } + $this->conf->write(true); } /** @@ -50,16 +67,16 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function tearDown() { - if (is_file(self::$configFields['config']['CONFIG_FILE'])) { - unlink(self::$configFields['config']['CONFIG_FILE']); + if (is_file(self::$configFile)) { + unlink(self::$configFile); } if (is_file(self::$configFields['config']['DATADIR'] . '/options.php')) { unlink(self::$configFields['config']['DATADIR'] . '/options.php'); } - if (is_file(self::$configFields['config']['DATADIR'] . '/updates.json')) { - unlink(self::$configFields['config']['DATADIR'] . '/updates.json'); + if (is_file(self::$configFields['config']['DATADIR'] . '/updates.txt')) { + unlink(self::$configFields['config']['DATADIR'] . '/updates.txt'); } } @@ -69,7 +86,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase public function testReadEmptyUpdatesFile() { $this->assertEquals(array(), read_updates_file('')); - $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.json'; + $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; touch($updatesFile); $this->assertEquals(array(), read_updates_file($updatesFile)); } @@ -79,7 +96,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testReadWriteUpdatesFile() { - $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.json'; + $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; $updatesMethods = array('m1', 'm2', 'm3'); write_updates_file($updatesFile, $updatesMethods); @@ -112,7 +129,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testWriteUpdatesFileNotWritable() { - $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.json'; + $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; touch($updatesFile); chmod($updatesFile, 0444); @write_updates_file($updatesFile, array('test')); @@ -131,10 +148,10 @@ class UpdaterTest extends PHPUnit_Framework_TestCase 'updateMethodDummy3', 'updateMethodException', ); - $updater = new DummyUpdater($updates, array(), array(), true); + $updater = new DummyUpdater($updates, array(), true); $this->assertEquals(array(), $updater->update()); - $updater = new DummyUpdater(array(), array(), array(), false); + $updater = new DummyUpdater(array(), array(), false); $this->assertEquals(array(), $updater->update()); } @@ -149,7 +166,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase 'updateMethodDummy2', 'updateMethodDummy3', ); - $updater = new DummyUpdater($updates, array(), array(), true); + $updater = new DummyUpdater($updates, array(), true); $this->assertEquals($expectedUpdates, $updater->update()); } @@ -165,7 +182,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase ); $expectedUpdate = array('updateMethodDummy2'); - $updater = new DummyUpdater($updates, array(), array(), true); + $updater = new DummyUpdater($updates, array(), true); $this->assertEquals($expectedUpdate, $updater->update()); } @@ -182,7 +199,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase 'updateMethodDummy3', ); - $updater = new DummyUpdater($updates, array(), array(), true); + $updater = new DummyUpdater($updates, array(), true); $updater->update(); } @@ -195,26 +212,25 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testUpdateMergeDeprecatedConfig() { - // init - writeConfig(self::$configFields, true); - $configCopy = self::$configFields; - $invert = !$configCopy['privateLinkByDefault']; - $configCopy['privateLinkByDefault'] = $invert; - // Use writeConfig to create a options.php - $configCopy['config']['CONFIG_FILE'] = 'tests/Updater/options.php'; - writeConfig($configCopy, true); + ConfigManager::$CONFIG_FILE = 'tests/Updater/options'; + $invert = !$this->conf->get('privateLinkByDefault'); + $this->conf->set('privateLinkByDefault', $invert); + $this->conf->write(true); + + $optionsFile = 'tests/Updater/options.php'; + $this->assertTrue(is_file($optionsFile)); - $this->assertTrue(is_file($configCopy['config']['CONFIG_FILE'])); + ConfigManager::$CONFIG_FILE = 'tests/Updater/config'; // merge configs - $updater = new Updater(array(), self::$configFields, array(), true); + $updater = new Updater(array(), array(), true); $updater->updateMethodMergeDeprecatedConfigFile(); // make sure updated field is changed - include self::$configFields['config']['CONFIG_FILE']; - $this->assertEquals($invert, $GLOBALS['privateLinkByDefault']); - $this->assertFalse(is_file($configCopy['config']['CONFIG_FILE'])); + $this->conf->reload(); + $this->assertEquals($invert, $this->conf->get('privateLinkByDefault')); + $this->assertFalse(is_file($optionsFile)); } /** @@ -222,22 +238,22 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testMergeDeprecatedConfigNoFile() { - writeConfig(self::$configFields, true); - - $updater = new Updater(array(), self::$configFields, array(), true); + $updater = new Updater(array(), array(), true); $updater->updateMethodMergeDeprecatedConfigFile(); - include self::$configFields['config']['CONFIG_FILE']; - $this->assertEquals(self::$configFields['login'], $GLOBALS['login']); + $this->assertEquals(self::$configFields['login'], $this->conf->get('login')); } + /** + * Test renameDashTags update method. + */ public function testRenameDashTags() { $refDB = new ReferenceLinkDB(); $refDB->write(self::$testDatastore); $linkDB = new LinkDB(self::$testDatastore, true, false); $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); - $updater = new Updater(array(), self::$configFields, $linkDB, true); + $updater = new Updater(array(), $linkDB, true); $updater->updateMethodRenameDashTags(); $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); } -- cgit v1.2.3 From b74b96bfbd0b778ac50fd17f5e107c51435b1678 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 29 May 2016 12:32:14 +0200 Subject: Adds ConfigJson which handle the configuration in JSON format. Also use the Updater to make the transition --- tests/Updater/UpdaterTest.php | 66 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) (limited to 'tests/Updater/UpdaterTest.php') 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 protected static $testDatastore = 'sandbox/datastore.php'; /** - * @var string Config file path. + * @var string Config file path (without extension). */ - protected static $configFile = 'tests/Updater/config.php'; + protected static $configFile = 'tests/utils/config/configUpdater'; /** * @var ConfigManager @@ -52,8 +52,9 @@ class UpdaterTest extends PHPUnit_Framework_TestCase ) ); - ConfigManager::$CONFIG_FILE = 'tests/Updater/config'; - $this->conf = ConfigManager::getInstance(); + ConfigManager::$CONFIG_FILE = self::$configFile; + $this->conf = ConfigManager::reset(); + $this->conf->reload(); foreach (self::$configFields as $key => $value) { $this->conf->set($key, $value); } @@ -67,8 +68,8 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function tearDown() { - if (is_file(self::$configFile)) { - unlink(self::$configFile); + if (is_file('tests/Updater/config.json')) { + unlink('tests/Updater/config.json'); } if (is_file(self::$configFields['config']['DATADIR'] . '/options.php')) { @@ -214,6 +215,8 @@ class UpdaterTest extends PHPUnit_Framework_TestCase { // Use writeConfig to create a options.php ConfigManager::$CONFIG_FILE = 'tests/Updater/options'; + $this->conf->setConfigIO(new ConfigPhp()); + $invert = !$this->conf->get('privateLinkByDefault'); $this->conf->set('privateLinkByDefault', $invert); $this->conf->write(true); @@ -225,12 +228,15 @@ class UpdaterTest extends PHPUnit_Framework_TestCase // merge configs $updater = new Updater(array(), array(), true); + // This writes a new config file in tests/Updater/config.php $updater->updateMethodMergeDeprecatedConfigFile(); // make sure updated field is changed $this->conf->reload(); $this->assertEquals($invert, $this->conf->get('privateLinkByDefault')); $this->assertFalse(is_file($optionsFile)); + // Delete the generated file. + unlink($this->conf->getConfigFile()); } /** @@ -257,4 +263,52 @@ class UpdaterTest extends PHPUnit_Framework_TestCase $updater->updateMethodRenameDashTags(); $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); } + + /** + * Convert old PHP config file to JSON config. + */ + public function testConfigToJson() + { + $configFile = 'tests/utils/config/configPhp'; + ConfigManager::$CONFIG_FILE = $configFile; + $conf = ConfigManager::reset(); + + // The ConfigIO is initialized with ConfigPhp. + $this->assertTrue($conf->getConfigIO() instanceof ConfigPhp); + + $updater = new Updater(array(), array(), false); + $done = $updater->updateMethodConfigToJson(); + $this->assertTrue($done); + + // The ConfigIO has been updated to ConfigJson. + $this->assertTrue($conf->getConfigIO() instanceof ConfigJson); + $this->assertTrue(file_exists($conf->getConfigFile())); + + // Check JSON config data. + $conf->reload(); + $this->assertEquals('root', $conf->get('login')); + $this->assertEquals('lala', $conf->get('redirector')); + $this->assertEquals('data/datastore.php', $conf->get('config.DATASTORE')); + $this->assertEquals('1', $conf->get('plugins.WALLABAG_VERSION')); + + rename($configFile . '.save.php', $configFile . '.php'); + unlink($conf->getConfigFile()); + } + + /** + * Launch config conversion update with an existing JSON file => nothing to do. + */ + public function testConfigToJsonNothingToDo() + { + $configFile = 'tests/utils/config/configUpdateDone'; + ConfigManager::$CONFIG_FILE = $configFile; + $conf = ConfigManager::reset(); + $conf->reload(); + $filetime = filemtime($conf->getConfigFile()); + $updater = new Updater(array(), array(), false); + $done = $updater->updateMethodConfigToJson(); + $this->assertTrue($done); + $expected = filemtime($conf->getConfigFile()); + $this->assertEquals($expected, $filetime); + } } -- cgit v1.2.3 From da10377b3c263d96a46cf9101c202554343d2cd0 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 29 May 2016 16:10:32 +0200 Subject: Rename configuration keys and fix GLOBALS in templates --- tests/Updater/UpdaterTest.php | 97 +++++++++++-------------------------------- 1 file changed, 25 insertions(+), 72 deletions(-) (limited to 'tests/Updater/UpdaterTest.php') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index f8de2f70..04883a46 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -9,11 +9,6 @@ require_once 'tests/Updater/DummyUpdater.php'; */ class UpdaterTest extends PHPUnit_Framework_TestCase { - /** - * @var array Configuration input set. - */ - private static $configFields; - /** * @var string Path to test datastore. */ @@ -22,7 +17,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase /** * @var string Config file path (without extension). */ - protected static $configFile = 'tests/utils/config/configUpdater'; + protected static $configFile = 'tests/utils/config/configJson'; /** * @var ConfigManager @@ -34,51 +29,8 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function setUp() { - self::$configFields = array( - 'login' => 'login', - 'hash' => 'hash', - 'salt' => 'salt', - 'timezone' => 'Europe/Paris', - 'title' => 'title', - 'titleLink' => 'titleLink', - 'redirector' => '', - 'disablesessionprotection' => false, - 'privateLinkByDefault' => false, - 'config' => array( - 'DATADIR' => 'tests/Updater', - 'PAGECACHE' => 'sandbox/pagecache', - 'config1' => 'config1data', - 'config2' => 'config2data', - ) - ); - ConfigManager::$CONFIG_FILE = self::$configFile; $this->conf = ConfigManager::reset(); - $this->conf->reload(); - foreach (self::$configFields as $key => $value) { - $this->conf->set($key, $value); - } - $this->conf->write(true); - } - - /** - * Executed after each test. - * - * @return void - */ - public function tearDown() - { - if (is_file('tests/Updater/config.json')) { - unlink('tests/Updater/config.json'); - } - - if (is_file(self::$configFields['config']['DATADIR'] . '/options.php')) { - unlink(self::$configFields['config']['DATADIR'] . '/options.php'); - } - - if (is_file(self::$configFields['config']['DATADIR'] . '/updates.txt')) { - unlink(self::$configFields['config']['DATADIR'] . '/updates.txt'); - } } /** @@ -87,9 +39,10 @@ class UpdaterTest extends PHPUnit_Framework_TestCase public function testReadEmptyUpdatesFile() { $this->assertEquals(array(), read_updates_file('')); - $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; + $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt'; touch($updatesFile); $this->assertEquals(array(), read_updates_file($updatesFile)); + unlink($updatesFile); } /** @@ -97,7 +50,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testReadWriteUpdatesFile() { - $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; + $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt'; $updatesMethods = array('m1', 'm2', 'm3'); write_updates_file($updatesFile, $updatesMethods); @@ -109,6 +62,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase write_updates_file($updatesFile, $updatesMethods); $readMethods = read_updates_file($updatesFile); $this->assertEquals($readMethods, $updatesMethods); + unlink($updatesFile); } /** @@ -130,10 +84,15 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testWriteUpdatesFileNotWritable() { - $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; + $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt'; touch($updatesFile); chmod($updatesFile, 0444); - @write_updates_file($updatesFile, array('test')); + try { + @write_updates_file($updatesFile, array('test')); + } catch (Exception $e) { + unlink($updatesFile); + throw $e; + } } /** @@ -213,17 +172,15 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testUpdateMergeDeprecatedConfig() { - // Use writeConfig to create a options.php - ConfigManager::$CONFIG_FILE = 'tests/Updater/options'; - $this->conf->setConfigIO(new ConfigPhp()); - - $invert = !$this->conf->get('privateLinkByDefault'); - $this->conf->set('privateLinkByDefault', $invert); - $this->conf->write(true); + ConfigManager::$CONFIG_FILE = 'tests/utils/config/configPhp'; + $this->conf = $this->conf->reset(); $optionsFile = 'tests/Updater/options.php'; - $this->assertTrue(is_file($optionsFile)); + $options = 'conf->reload(); - $this->assertEquals($invert, $this->conf->get('privateLinkByDefault')); + $this->assertTrue($this->conf->get('general.default_private_links')); $this->assertFalse(is_file($optionsFile)); // Delete the generated file. unlink($this->conf->getConfigFile()); @@ -247,7 +204,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase $updater = new Updater(array(), array(), true); $updater->updateMethodMergeDeprecatedConfigFile(); - $this->assertEquals(self::$configFields['login'], $this->conf->get('login')); + $this->assertEquals('root', $this->conf->get('credentials.login')); } /** @@ -286,9 +243,9 @@ class UpdaterTest extends PHPUnit_Framework_TestCase // Check JSON config data. $conf->reload(); - $this->assertEquals('root', $conf->get('login')); - $this->assertEquals('lala', $conf->get('redirector')); - $this->assertEquals('data/datastore.php', $conf->get('config.DATASTORE')); + $this->assertEquals('root', $conf->get('credentials.login')); + $this->assertEquals('lala', $conf->get('extras.redirector')); + $this->assertEquals('data/datastore.php', $conf->get('path.datastore')); $this->assertEquals('1', $conf->get('plugins.WALLABAG_VERSION')); rename($configFile . '.save.php', $configFile . '.php'); @@ -300,15 +257,11 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testConfigToJsonNothingToDo() { - $configFile = 'tests/utils/config/configUpdateDone'; - ConfigManager::$CONFIG_FILE = $configFile; - $conf = ConfigManager::reset(); - $conf->reload(); - $filetime = filemtime($conf->getConfigFile()); + $filetime = filemtime($this->conf->getConfigFile()); $updater = new Updater(array(), array(), false); $done = $updater->updateMethodConfigToJson(); $this->assertTrue($done); - $expected = filemtime($conf->getConfigFile()); + $expected = filemtime($this->conf->getConfigFile()); $this->assertEquals($expected, $filetime); } } -- cgit v1.2.3 From 278d9ee2836df7d805845077f26f8cecd16f0f4f Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 9 Jun 2016 20:04:02 +0200 Subject: ConfigManager no longer uses singleton pattern --- tests/Updater/UpdaterTest.php | 57 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 29 deletions(-) (limited to 'tests/Updater/UpdaterTest.php') 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 */ public function setUp() { - ConfigManager::$CONFIG_FILE = self::$configFile; - $this->conf = ConfigManager::reset(); + $this->conf = new ConfigManager(self::$configFile); } /** @@ -108,10 +107,10 @@ class UpdaterTest extends PHPUnit_Framework_TestCase 'updateMethodDummy3', 'updateMethodException', ); - $updater = new DummyUpdater($updates, array(), true); + $updater = new DummyUpdater($updates, array(), $this->conf, true); $this->assertEquals(array(), $updater->update()); - $updater = new DummyUpdater(array(), array(), false); + $updater = new DummyUpdater(array(), array(), $this->conf, false); $this->assertEquals(array(), $updater->update()); } @@ -126,7 +125,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase 'updateMethodDummy2', 'updateMethodDummy3', ); - $updater = new DummyUpdater($updates, array(), true); + $updater = new DummyUpdater($updates, array(), $this->conf, true); $this->assertEquals($expectedUpdates, $updater->update()); } @@ -142,7 +141,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase ); $expectedUpdate = array('updateMethodDummy2'); - $updater = new DummyUpdater($updates, array(), true); + $updater = new DummyUpdater($updates, array(), $this->conf, true); $this->assertEquals($expectedUpdate, $updater->update()); } @@ -159,7 +158,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase 'updateMethodDummy3', ); - $updater = new DummyUpdater($updates, array(), true); + $updater = new DummyUpdater($updates, array(), $this->conf, true); $updater->update(); } @@ -172,8 +171,8 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testUpdateMergeDeprecatedConfig() { - ConfigManager::$CONFIG_FILE = 'tests/utils/config/configPhp'; - $this->conf = $this->conf->reset(); + $this->conf->setConfigFile('tests/utils/config/configPhp'); + $this->conf->reset(); $optionsFile = 'tests/Updater/options.php'; $options = 'conf->setConfigFile('tests/Updater/config'); // merge configs - $updater = new Updater(array(), array(), true); + $updater = new Updater(array(), array(), $this->conf, true); // This writes a new config file in tests/Updater/config.php $updater->updateMethodMergeDeprecatedConfigFile(); @@ -193,7 +192,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $this->assertTrue($this->conf->get('general.default_private_links')); $this->assertFalse(is_file($optionsFile)); // Delete the generated file. - unlink($this->conf->getConfigFile()); + unlink($this->conf->getConfigFileExt()); } /** @@ -201,7 +200,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; */ public function testMergeDeprecatedConfigNoFile() { - $updater = new Updater(array(), array(), true); + $updater = new Updater(array(), array(), $this->conf, true); $updater->updateMethodMergeDeprecatedConfigFile(); $this->assertEquals('root', $this->conf->get('credentials.login')); @@ -216,7 +215,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $refDB->write(self::$testDatastore); $linkDB = new LinkDB(self::$testDatastore, true, false); $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); - $updater = new Updater(array(), $linkDB, true); + $updater = new Updater(array(), $linkDB, $this->conf, true); $updater->updateMethodRenameDashTags(); $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); } @@ -227,29 +226,29 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; public function testConfigToJson() { $configFile = 'tests/utils/config/configPhp'; - ConfigManager::$CONFIG_FILE = $configFile; - $conf = ConfigManager::reset(); + $this->conf->setConfigFile($configFile); + $this->conf->reset(); // The ConfigIO is initialized with ConfigPhp. - $this->assertTrue($conf->getConfigIO() instanceof ConfigPhp); + $this->assertTrue($this->conf->getConfigIO() instanceof ConfigPhp); - $updater = new Updater(array(), array(), false); + $updater = new Updater(array(), array(), $this->conf, false); $done = $updater->updateMethodConfigToJson(); $this->assertTrue($done); // The ConfigIO has been updated to ConfigJson. - $this->assertTrue($conf->getConfigIO() instanceof ConfigJson); - $this->assertTrue(file_exists($conf->getConfigFile())); + $this->assertTrue($this->conf->getConfigIO() instanceof ConfigJson); + $this->assertTrue(file_exists($this->conf->getConfigFileExt())); // Check JSON config data. - $conf->reload(); - $this->assertEquals('root', $conf->get('credentials.login')); - $this->assertEquals('lala', $conf->get('extras.redirector')); - $this->assertEquals('data/datastore.php', $conf->get('path.datastore')); - $this->assertEquals('1', $conf->get('plugins.WALLABAG_VERSION')); + $this->conf->reload(); + $this->assertEquals('root', $this->conf->get('credentials.login')); + $this->assertEquals('lala', $this->conf->get('extras.redirector')); + $this->assertEquals('data/datastore.php', $this->conf->get('path.datastore')); + $this->assertEquals('1', $this->conf->get('plugins.WALLABAG_VERSION')); rename($configFile . '.save.php', $configFile . '.php'); - unlink($conf->getConfigFile()); + unlink($this->conf->getConfigFileExt()); } /** @@ -257,11 +256,11 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; */ public function testConfigToJsonNothingToDo() { - $filetime = filemtime($this->conf->getConfigFile()); - $updater = new Updater(array(), array(), false); + $filetime = filemtime($this->conf->getConfigFileExt()); + $updater = new Updater(array(), array(), $this->conf, false); $done = $updater->updateMethodConfigToJson(); $this->assertTrue($done); - $expected = filemtime($this->conf->getConfigFile()); + $expected = filemtime($this->conf->getConfigFileExt()); $this->assertEquals($expected, $filetime); } } -- cgit v1.2.3 From 894a3c4bf38d8dcadb6941049b9167e5101805bd Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 11 Jun 2016 09:08:02 +0200 Subject: Rename configuration key for better sections --- tests/Updater/UpdaterTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests/Updater/UpdaterTest.php') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 5ed2df6c..6bdce08b 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -38,7 +38,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase public function testReadEmptyUpdatesFile() { $this->assertEquals(array(), read_updates_file('')); - $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt'; + $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; touch($updatesFile); $this->assertEquals(array(), read_updates_file($updatesFile)); unlink($updatesFile); @@ -49,7 +49,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testReadWriteUpdatesFile() { - $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt'; + $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; $updatesMethods = array('m1', 'm2', 'm3'); write_updates_file($updatesFile, $updatesMethods); @@ -83,7 +83,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function testWriteUpdatesFileNotWritable() { - $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt'; + $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; touch($updatesFile); chmod($updatesFile, 0444); try { @@ -189,7 +189,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; // make sure updated field is changed $this->conf->reload(); - $this->assertTrue($this->conf->get('general.default_private_links')); + $this->assertTrue($this->conf->get('privacy.default_private_links')); $this->assertFalse(is_file($optionsFile)); // Delete the generated file. unlink($this->conf->getConfigFileExt()); @@ -243,8 +243,8 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; // Check JSON config data. $this->conf->reload(); $this->assertEquals('root', $this->conf->get('credentials.login')); - $this->assertEquals('lala', $this->conf->get('extras.redirector')); - $this->assertEquals('data/datastore.php', $this->conf->get('path.datastore')); + $this->assertEquals('lala', $this->conf->get('redirector.url')); + $this->assertEquals('data/datastore.php', $this->conf->get('resource.datastore')); $this->assertEquals('1', $this->conf->get('plugins.WALLABAG_VERSION')); rename($configFile . '.save.php', $configFile . '.php'); -- cgit v1.2.3