From 59404d7909b21682ec0782778452a8a70e38b25e Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 18 May 2016 21:43:59 +0200 Subject: Introduce a configuration manager (not plugged yet) --- tests/config/ConfigManagerTest.php | 48 +++++++++++++++ tests/config/ConfigPhpTest.php | 82 +++++++++++++++++++++++++ tests/config/ConfigPluginTest.php | 121 +++++++++++++++++++++++++++++++++++++ tests/config/php/configOK.php | 14 +++++ 4 files changed, 265 insertions(+) create mode 100644 tests/config/ConfigManagerTest.php create mode 100644 tests/config/ConfigPhpTest.php create mode 100644 tests/config/ConfigPluginTest.php create mode 100644 tests/config/php/configOK.php (limited to 'tests/config') diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php new file mode 100644 index 00000000..1b6358f3 --- /dev/null +++ b/tests/config/ConfigManagerTest.php @@ -0,0 +1,48 @@ +conf = ConfigManager::getInstance(); + } + + public function tearDown() + { + @unlink($this->conf->getConfigFile()); + } + + public function testSetWriteGet() + { + // This won't work with ConfigPhp. + $this->markTestIncomplete(); + + $this->conf->set('paramInt', 42); + $this->conf->set('paramString', 'value1'); + $this->conf->set('paramBool', false); + $this->conf->set('paramArray', array('foo' => 'bar')); + $this->conf->set('paramNull', null); + + $this->conf->write(true); + $this->conf->reload(); + + $this->assertEquals(42, $this->conf->get('paramInt')); + $this->assertEquals('value1', $this->conf->get('paramString')); + $this->assertFalse($this->conf->get('paramBool')); + $this->assertEquals(array('foo' => 'bar'), $this->conf->get('paramArray')); + $this->assertEquals(null, $this->conf->get('paramNull')); + } + +} \ No newline at end of file diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php new file mode 100644 index 00000000..0f849bd5 --- /dev/null +++ b/tests/config/ConfigPhpTest.php @@ -0,0 +1,82 @@ +configIO = new ConfigPhp(); + } + + /** + * Read a simple existing config file. + */ + public function testRead() + { + $conf = $this->configIO->read('tests/config/php/configOK'); + $this->assertEquals('root', $conf['login']); + $this->assertEquals('lala', $conf['redirector']); + $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']); + $this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']); + } + + /** + * Read a non existent config file -> empty array. + */ + public function testReadNonExistent() + { + $this->assertEquals(array(), $this->configIO->read('nope')); + } + + /** + * Write a new config file. + */ + public function testWriteNew() + { + $dataFile = 'tests/config/php/configWrite'; + $data = array( + 'login' => 'root', + 'redirector' => 'lala', + 'config' => array( + 'DATASTORE' => 'data/datastore.php', + ), + 'plugins' => array( + 'WALLABAG_VERSION' => '1', + ) + ); + $this->configIO->write($dataFile, $data); + $expected = 'assertEquals($expected, file_get_contents($dataFile .'.php')); + unlink($dataFile .'.php'); + } + + /** + * Overwrite an existing setting. + */ + public function testOverwrite() + { + $source = 'tests/config/php/configOK.php'; + $dest = 'tests/config/php/configOverwrite'; + copy($source, $dest . '.php'); + $conf = $this->configIO->read($dest); + $conf['redirector'] = 'blabla'; + $this->configIO->write($dest, $conf); + $conf = $this->configIO->read($dest); + $this->assertEquals('blabla', $conf['redirector']); + unlink($dest .'.php'); + } +} diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php new file mode 100644 index 00000000..716631b0 --- /dev/null +++ b/tests/config/ConfigPluginTest.php @@ -0,0 +1,121 @@ + 2, // no plugin related + 'plugin2' => 0, // new - at the end + 'plugin3' => 0, // 2nd + 'order_plugin3' => 8, + 'plugin4' => 0, // 1st + 'order_plugin4' => 5, + ); + + $expected = array( + 'plugin3', + 'plugin4', + 'plugin2', + ); + + $out = save_plugin_config($data); + $this->assertEquals($expected, $out); + } + + /** + * Test save_plugin_config with invalid data. + * + * @expectedException PluginConfigOrderException + */ + public function testSavePluginConfigInvalid() + { + $data = array( + 'plugin2' => 0, + 'plugin3' => 0, + 'order_plugin3' => 0, + 'plugin4' => 0, + 'order_plugin4' => 0, + ); + + save_plugin_config($data); + } + + /** + * Test save_plugin_config without data. + */ + public function testSavePluginConfigEmpty() + { + $this->assertEquals(array(), save_plugin_config(array())); + } + + /** + * Test validate_plugin_order with valid data. + */ + public function testValidatePluginOrderValid() + { + $data = array( + 'order_plugin1' => 2, + 'plugin2' => 0, + 'plugin3' => 0, + 'order_plugin3' => 1, + 'plugin4' => 0, + 'order_plugin4' => 5, + ); + + $this->assertTrue(validate_plugin_order($data)); + } + + /** + * Test validate_plugin_order with invalid data. + */ + public function testValidatePluginOrderInvalid() + { + $data = array( + 'order_plugin1' => 2, + 'order_plugin3' => 1, + 'order_plugin4' => 1, + ); + + $this->assertFalse(validate_plugin_order($data)); + } + + /** + * Test load_plugin_parameter_values. + */ + public function testLoadPluginParameterValues() + { + $plugins = array( + 'plugin_name' => array( + 'parameters' => array( + 'param1' => true, + 'param2' => false, + 'param3' => '', + ) + ) + ); + + $parameters = array( + 'param1' => 'value1', + 'param2' => 'value2', + ); + + $result = load_plugin_parameter_values($plugins, $parameters); + $this->assertEquals('value1', $result['plugin_name']['parameters']['param1']); + $this->assertEquals('value2', $result['plugin_name']['parameters']['param2']); + $this->assertEquals('', $result['plugin_name']['parameters']['param3']); + } +} diff --git a/tests/config/php/configOK.php b/tests/config/php/configOK.php new file mode 100644 index 00000000..b91ad293 --- /dev/null +++ b/tests/config/php/configOK.php @@ -0,0 +1,14 @@ + Date: Wed, 18 May 2016 21:48:24 +0200 Subject: Replace $GLOBALS configuration with the configuration manager in the whole code base --- tests/config/ConfigPhpTest.php | 16 ++++++++-------- tests/config/php/configOK.php | 14 -------------- 2 files changed, 8 insertions(+), 22 deletions(-) delete mode 100644 tests/config/php/configOK.php (limited to 'tests/config') diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php index 0f849bd5..58cd8d2a 100644 --- a/tests/config/ConfigPhpTest.php +++ b/tests/config/ConfigPhpTest.php @@ -22,7 +22,7 @@ class ConfigPhpTest extends PHPUnit_Framework_TestCase */ public function testRead() { - $conf = $this->configIO->read('tests/config/php/configOK'); + $conf = $this->configIO->read('tests/utils/config/configPhp.php'); $this->assertEquals('root', $conf['login']); $this->assertEquals('lala', $conf['redirector']); $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']); @@ -42,7 +42,7 @@ class ConfigPhpTest extends PHPUnit_Framework_TestCase */ public function testWriteNew() { - $dataFile = 'tests/config/php/configWrite'; + $dataFile = 'tests/utils/config/configWrite.php'; $data = array( 'login' => 'root', 'redirector' => 'lala', @@ -60,8 +60,8 @@ $GLOBALS[\'redirector\'] = \'lala\'; $GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\'; $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\'; '; - $this->assertEquals($expected, file_get_contents($dataFile .'.php')); - unlink($dataFile .'.php'); + $this->assertEquals($expected, file_get_contents($dataFile)); + unlink($dataFile); } /** @@ -69,14 +69,14 @@ $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\'; */ public function testOverwrite() { - $source = 'tests/config/php/configOK.php'; - $dest = 'tests/config/php/configOverwrite'; - copy($source, $dest . '.php'); + $source = 'tests/utils/config/configPhp.php'; + $dest = 'tests/utils/config/configOverwrite.php'; + copy($source, $dest); $conf = $this->configIO->read($dest); $conf['redirector'] = 'blabla'; $this->configIO->write($dest, $conf); $conf = $this->configIO->read($dest); $this->assertEquals('blabla', $conf['redirector']); - unlink($dest .'.php'); + unlink($dest); } } diff --git a/tests/config/php/configOK.php b/tests/config/php/configOK.php deleted file mode 100644 index b91ad293..00000000 --- a/tests/config/php/configOK.php +++ /dev/null @@ -1,14 +0,0 @@ - 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/config/ConfigJsonTest.php | 125 +++++++++++++++++++++++++++++++ tests/config/ConfigManagerTest.php | 146 ++++++++++++++++++++++++++++++++++--- 2 files changed, 261 insertions(+), 10 deletions(-) create mode 100644 tests/config/ConfigJsonTest.php (limited to 'tests/config') diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php new file mode 100644 index 00000000..5b3bce46 --- /dev/null +++ b/tests/config/ConfigJsonTest.php @@ -0,0 +1,125 @@ +configIO = new ConfigJson(); + } + + /** + * Read a simple existing config file. + */ + public function testRead() + { + $conf = $this->configIO->read('tests/utils/config/configJson.json.php'); + $this->assertEquals('root', $conf['login']); + $this->assertEquals('lala', $conf['redirector']); + $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']); + $this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']); + } + + /** + * Read a non existent config file -> empty array. + */ + public function testReadNonExistent() + { + $this->assertEquals(array(), $this->configIO->read('nope')); + } + + /** + * Read a non existent config file -> empty array. + * + * @expectedException Exception + * @expectedExceptionMessage An error occured while parsing JSON file: error code #4 + */ + public function testReadInvalidJson() + { + $this->configIO->read('tests/utils/config/configInvalid.json.php'); + } + + /** + * Write a new config file. + */ + public function testWriteNew() + { + $dataFile = 'tests/utils/config/configWrite.json.php'; + $data = array( + 'login' => 'root', + 'redirector' => 'lala', + 'config' => array( + 'DATASTORE' => 'data/datastore.php', + ), + 'plugins' => array( + 'WALLABAG_VERSION' => '1', + ) + ); + $this->configIO->write($dataFile, $data); + // PHP 5.3 doesn't support json pretty print. + if (defined('JSON_PRETTY_PRINT')) { + $expected = '{ + "login": "root", + "redirector": "lala", + "config": { + "DATASTORE": "data\/datastore.php" + }, + "plugins": { + "WALLABAG_VERSION": "1" + } +}'; + } else { + $expected = '{"login":"root","redirector":"lala","config":{"DATASTORE":"data\/datastore.php"},"plugins":{"WALLABAG_VERSION":"1"}}'; + } + $expected = ConfigJson::$PHP_HEADER . $expected; + $this->assertEquals($expected, file_get_contents($dataFile)); + unlink($dataFile); + } + + /** + * Overwrite an existing setting. + */ + public function testOverwrite() + { + $source = 'tests/utils/config/configJson.json.php'; + $dest = 'tests/utils/config/configOverwrite.json.php'; + copy($source, $dest); + $conf = $this->configIO->read($dest); + $conf['redirector'] = 'blabla'; + $this->configIO->write($dest, $conf); + $conf = $this->configIO->read($dest); + $this->assertEquals('blabla', $conf['redirector']); + unlink($dest); + } + + /** + * Write to invalid path. + * + * @expectedException IOException + */ + public function testWriteInvalidArray() + { + $conf = array('conf' => 'value'); + @$this->configIO->write(array(), $conf); + } + + /** + * Write to invalid path. + * + * @expectedException IOException + */ + public function testWriteInvalidBlank() + { + $conf = array('conf' => 'value'); + @$this->configIO->write('', $conf); + } +} diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php index 1b6358f3..7390699c 100644 --- a/tests/config/ConfigManagerTest.php +++ b/tests/config/ConfigManagerTest.php @@ -6,7 +6,7 @@ * Note: it only test the manager with ConfigJson, * ConfigPhp is only a workaround to handle the transition to JSON type. */ -class ConfigManagerTest extends \PHPUnit_Framework_TestCase +class ConfigManagerTest extends PHPUnit_Framework_TestCase { /** * @var ConfigManager @@ -15,28 +15,49 @@ class ConfigManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { - ConfigManager::$CONFIG_FILE = 'tests/config/config'; - $this->conf = ConfigManager::getInstance(); + ConfigManager::$CONFIG_FILE = 'tests/utils/config/configJson'; + $this->conf = ConfigManager::reset(); } - public function tearDown() + /** + * Simple config test: + * 1. Set settings. + * 2. Check settings value. + */ + public function testSetGet() { - @unlink($this->conf->getConfigFile()); + $this->conf->set('paramInt', 42); + $this->conf->set('paramString', 'value1'); + $this->conf->set('paramBool', false); + $this->conf->set('paramArray', array('foo' => 'bar')); + $this->conf->set('paramNull', null); + + $this->assertEquals(42, $this->conf->get('paramInt')); + $this->assertEquals('value1', $this->conf->get('paramString')); + $this->assertFalse($this->conf->get('paramBool')); + $this->assertEquals(array('foo' => 'bar'), $this->conf->get('paramArray')); + $this->assertEquals(null, $this->conf->get('paramNull')); } + /** + * Set/write/get config test: + * 1. Set settings. + * 2. Write it to the config file. + * 3. Read the file. + * 4. Check settings value. + */ public function testSetWriteGet() { - // This won't work with ConfigPhp. - $this->markTestIncomplete(); - $this->conf->set('paramInt', 42); $this->conf->set('paramString', 'value1'); $this->conf->set('paramBool', false); $this->conf->set('paramArray', array('foo' => 'bar')); $this->conf->set('paramNull', null); + ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; $this->conf->write(true); $this->conf->reload(); + unlink($this->conf->getConfigFile()); $this->assertEquals(42, $this->conf->get('paramInt')); $this->assertEquals('value1', $this->conf->get('paramString')); @@ -44,5 +65,110 @@ class ConfigManagerTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('foo' => 'bar'), $this->conf->get('paramArray')); $this->assertEquals(null, $this->conf->get('paramNull')); } - -} \ No newline at end of file + + /** + * Test set/write/get with nested keys. + */ + public function testSetWriteGetNested() + { + $this->conf->set('foo.bar.key.stuff', 'testSetWriteGetNested'); + + ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; + $this->conf->write(true); + $this->conf->reload(); + unlink($this->conf->getConfigFile()); + + $this->assertEquals('testSetWriteGetNested', $this->conf->get('foo.bar.key.stuff')); + } + + /** + * Set with an empty key. + * + * @expectedException Exception + * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*# + */ + public function testSetEmptyKey() + { + $this->conf->set('', 'stuff'); + } + + /** + * Set with an array key. + * + * @expectedException Exception + * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*# + */ + public function testSetArrayKey() + { + $this->conf->set(array('foo' => 'bar'), 'stuff'); + } + + /** + * Try to write the config without mandatory parameter (e.g. 'login'). + * + * @expectedException MissingFieldConfigException + */ + public function testWriteMissingParameter() + { + ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; + $this->assertFalse(file_exists($this->conf->getConfigFile())); + $this->conf->reload(); + + $this->conf->write(true); + } + + /** + * Try to get non existent config keys. + */ + public function testGetNonExistent() + { + $this->assertEquals('', $this->conf->get('nope.test')); + $this->assertEquals('default', $this->conf->get('nope.test', 'default')); + } + + /** + * Test the 'exists' method with existent values. + */ + public function testExistsOk() + { + $this->assertTrue($this->conf->exists('login')); + $this->assertTrue($this->conf->exists('config.foo')); + } + + /** + * Test the 'exists' method with non existent or invalid values. + */ + public function testExistsKo() + { + $this->assertFalse($this->conf->exists('nope')); + $this->assertFalse($this->conf->exists('nope.nope')); + $this->assertFalse($this->conf->exists('')); + $this->assertFalse($this->conf->exists(false)); + } + + /** + * Reset the ConfigManager instance. + */ + public function testReset() + { + $conf = $this->conf; + $this->assertTrue($conf === ConfigManager::getInstance()); + $this->assertFalse($conf === $this->conf->reset()); + $this->assertFalse($conf === ConfigManager::getInstance()); + } + + /** + * Reload the config from file. + */ + public function testReload() + { + ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; + $newConf = ConfigJson::$PHP_HEADER . '{ "key": "value" }'; + file_put_contents($this->conf->getConfigFile(), $newConf); + $this->conf->reload(); + unlink($this->conf->getConfigFile()); + // Previous conf no longer exists, and new values have been loaded. + $this->assertFalse($this->conf->exists('login')); + $this->assertEquals('value', $this->conf->get('key')); + } +} -- 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/config/ConfigJsonTest.php | 38 +++++++++++++++++++++++--------------- tests/config/ConfigManagerTest.php | 6 +++--- 2 files changed, 26 insertions(+), 18 deletions(-) (limited to 'tests/config') diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php index 5b3bce46..0960c729 100644 --- a/tests/config/ConfigJsonTest.php +++ b/tests/config/ConfigJsonTest.php @@ -23,9 +23,9 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase public function testRead() { $conf = $this->configIO->read('tests/utils/config/configJson.json.php'); - $this->assertEquals('root', $conf['login']); - $this->assertEquals('lala', $conf['redirector']); - $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']); + $this->assertEquals('root', $conf['credentials']['login']); + $this->assertEquals('lala', $conf['extras']['redirector']); + $this->assertEquals('tests/utils/config/datastore.php', $conf['path']['datastore']); $this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']); } @@ -55,10 +55,14 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase { $dataFile = 'tests/utils/config/configWrite.json.php'; $data = array( - 'login' => 'root', - 'redirector' => 'lala', - 'config' => array( - 'DATASTORE' => 'data/datastore.php', + 'credentials' => array( + 'login' => 'root', + ), + 'path' => array( + 'datastore' => 'data/datastore.php', + ), + 'extras' => array( + 'redirector' => 'lala', ), 'plugins' => array( 'WALLABAG_VERSION' => '1', @@ -68,19 +72,23 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase // PHP 5.3 doesn't support json pretty print. if (defined('JSON_PRETTY_PRINT')) { $expected = '{ - "login": "root", - "redirector": "lala", - "config": { - "DATASTORE": "data\/datastore.php" + "credentials": { + "login": "root" + }, + "path": { + "datastore": "data\/datastore.php" + }, + "extras": { + "redirector": "lala" }, "plugins": { "WALLABAG_VERSION": "1" } }'; } else { - $expected = '{"login":"root","redirector":"lala","config":{"DATASTORE":"data\/datastore.php"},"plugins":{"WALLABAG_VERSION":"1"}}'; + $expected = '{"credentials":{"login":"root"},"path":{"datastore":"data\/datastore.php"},"extras":{"redirector":"lala"},"plugins":{"WALLABAG_VERSION":"1"}}'; } - $expected = ConfigJson::$PHP_HEADER . $expected; + $expected = ConfigJson::getPhpHeaders() . $expected; $this->assertEquals($expected, file_get_contents($dataFile)); unlink($dataFile); } @@ -94,10 +102,10 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase $dest = 'tests/utils/config/configOverwrite.json.php'; copy($source, $dest); $conf = $this->configIO->read($dest); - $conf['redirector'] = 'blabla'; + $conf['extras']['redirector'] = 'blabla'; $this->configIO->write($dest, $conf); $conf = $this->configIO->read($dest); - $this->assertEquals('blabla', $conf['redirector']); + $this->assertEquals('blabla', $conf['extras']['redirector']); unlink($dest); } diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php index 7390699c..9ff0f473 100644 --- a/tests/config/ConfigManagerTest.php +++ b/tests/config/ConfigManagerTest.php @@ -131,7 +131,7 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase */ public function testExistsOk() { - $this->assertTrue($this->conf->exists('login')); + $this->assertTrue($this->conf->exists('credentials.login')); $this->assertTrue($this->conf->exists('config.foo')); } @@ -163,12 +163,12 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase public function testReload() { ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; - $newConf = ConfigJson::$PHP_HEADER . '{ "key": "value" }'; + $newConf = ConfigJson::getPhpHeaders() . '{ "key": "value" }'; file_put_contents($this->conf->getConfigFile(), $newConf); $this->conf->reload(); unlink($this->conf->getConfigFile()); // Previous conf no longer exists, and new values have been loaded. - $this->assertFalse($this->conf->exists('login')); + $this->assertFalse($this->conf->exists('credentials.login')); $this->assertEquals('value', $this->conf->get('key')); } } -- 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/config/ConfigManagerTest.php | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'tests/config') 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 public function setUp() { - ConfigManager::$CONFIG_FILE = 'tests/utils/config/configJson'; - $this->conf = ConfigManager::reset(); + $this->conf = new ConfigManager('tests/utils/config/configJson'); } /** @@ -54,10 +53,10 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase $this->conf->set('paramArray', array('foo' => 'bar')); $this->conf->set('paramNull', null); - ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; + $this->conf->setConfigFile('tests/utils/config/configTmp'); $this->conf->write(true); $this->conf->reload(); - unlink($this->conf->getConfigFile()); + unlink($this->conf->getConfigFileExt()); $this->assertEquals(42, $this->conf->get('paramInt')); $this->assertEquals('value1', $this->conf->get('paramString')); @@ -73,10 +72,10 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase { $this->conf->set('foo.bar.key.stuff', 'testSetWriteGetNested'); - ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; + $this->conf->setConfigFile('tests/utils/config/configTmp'); $this->conf->write(true); $this->conf->reload(); - unlink($this->conf->getConfigFile()); + unlink($this->conf->getConfigFileExt()); $this->assertEquals('testSetWriteGetNested', $this->conf->get('foo.bar.key.stuff')); } @@ -110,8 +109,8 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase */ public function testWriteMissingParameter() { - ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; - $this->assertFalse(file_exists($this->conf->getConfigFile())); + $this->conf->setConfigFile('tests/utils/config/configTmp'); + $this->assertFalse(file_exists($this->conf->getConfigFileExt())); $this->conf->reload(); $this->conf->write(true); @@ -151,10 +150,9 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase */ public function testReset() { - $conf = $this->conf; - $this->assertTrue($conf === ConfigManager::getInstance()); - $this->assertFalse($conf === $this->conf->reset()); - $this->assertFalse($conf === ConfigManager::getInstance()); + $confIO = $this->conf->getConfigIO(); + $this->conf->reset(); + $this->assertFalse($confIO === $this->conf->getConfigIO()); } /** @@ -162,11 +160,11 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase */ public function testReload() { - ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; + $this->conf->setConfigFile('tests/utils/config/configTmp'); $newConf = ConfigJson::getPhpHeaders() . '{ "key": "value" }'; - file_put_contents($this->conf->getConfigFile(), $newConf); + file_put_contents($this->conf->getConfigFileExt(), $newConf); $this->conf->reload(); - unlink($this->conf->getConfigFile()); + unlink($this->conf->getConfigFileExt()); // Previous conf no longer exists, and new values have been loaded. $this->assertFalse($this->conf->exists('credentials.login')); $this->assertEquals('value', $this->conf->get('key')); -- 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/config/ConfigJsonTest.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tests/config') diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php index 0960c729..359e9112 100644 --- a/tests/config/ConfigJsonTest.php +++ b/tests/config/ConfigJsonTest.php @@ -24,8 +24,8 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase { $conf = $this->configIO->read('tests/utils/config/configJson.json.php'); $this->assertEquals('root', $conf['credentials']['login']); - $this->assertEquals('lala', $conf['extras']['redirector']); - $this->assertEquals('tests/utils/config/datastore.php', $conf['path']['datastore']); + $this->assertEquals('lala', $conf['redirector']['url']); + $this->assertEquals('tests/utils/config/datastore.php', $conf['resource']['datastore']); $this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']); } @@ -58,11 +58,11 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase 'credentials' => array( 'login' => 'root', ), - 'path' => array( + 'resource' => array( 'datastore' => 'data/datastore.php', ), - 'extras' => array( - 'redirector' => 'lala', + 'redirector' => array( + 'url' => 'lala', ), 'plugins' => array( 'WALLABAG_VERSION' => '1', @@ -75,18 +75,18 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase "credentials": { "login": "root" }, - "path": { + "resource": { "datastore": "data\/datastore.php" }, - "extras": { - "redirector": "lala" + "redirector": { + "url": "lala" }, "plugins": { "WALLABAG_VERSION": "1" } }'; } else { - $expected = '{"credentials":{"login":"root"},"path":{"datastore":"data\/datastore.php"},"extras":{"redirector":"lala"},"plugins":{"WALLABAG_VERSION":"1"}}'; + $expected = '{"credentials":{"login":"root"},"resource":{"datastore":"data\/datastore.php"},"redirector":{"url":"lala"},"plugins":{"WALLABAG_VERSION":"1"}}'; } $expected = ConfigJson::getPhpHeaders() . $expected; $this->assertEquals($expected, file_get_contents($dataFile)); @@ -102,10 +102,10 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase $dest = 'tests/utils/config/configOverwrite.json.php'; copy($source, $dest); $conf = $this->configIO->read($dest); - $conf['extras']['redirector'] = 'blabla'; + $conf['redirector']['url'] = 'blabla'; $this->configIO->write($dest, $conf); $conf = $this->configIO->read($dest); - $this->assertEquals('blabla', $conf['extras']['redirector']); + $this->assertEquals('blabla', $conf['redirector']['url']); unlink($dest); } -- cgit v1.2.3 From 5ff23f02b80ec6ddee28dee869171ee8e3656b7c Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 20 Jun 2016 18:30:37 +0200 Subject: Add closing PHP tags to JSON config files --- tests/config/ConfigJsonTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/config') diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php index 359e9112..99c88820 100644 --- a/tests/config/ConfigJsonTest.php +++ b/tests/config/ConfigJsonTest.php @@ -88,7 +88,7 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase } else { $expected = '{"credentials":{"login":"root"},"resource":{"datastore":"data\/datastore.php"},"redirector":{"url":"lala"},"plugins":{"WALLABAG_VERSION":"1"}}'; } - $expected = ConfigJson::getPhpHeaders() . $expected; + $expected = ConfigJson::getPhpHeaders() . $expected . ConfigJson::getPhpSuffix(); $this->assertEquals($expected, file_get_contents($dataFile)); unlink($dataFile); } -- cgit v1.2.3