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/ConfigPhpTest.php | 82 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/config/ConfigPhpTest.php (limited to 'tests/config/ConfigPhpTest.php') 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'); + } +} -- cgit v1.2.3 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/config/ConfigPhpTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/config/ConfigPhpTest.php') 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); } } -- cgit v1.2.3