3 require_once 'application/config/ConfigPhp.php';
8 class ConfigPhpTest
extends PHPUnit_Framework_TestCase
15 public function setUp()
17 $this->configIO
= new ConfigPhp();
21 * Read a simple existing config file.
23 public function testRead()
25 $conf = $this->configIO
->read('tests/utils/config/configPhp.php');
26 $this->assertEquals('root', $conf['login']);
27 $this->assertEquals('lala', $conf['redirector']);
28 $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']);
29 $this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']);
33 * Read a non existent config file -> empty array.
35 public function testReadNonExistent()
37 $this->assertEquals(array(), $this->configIO
->read('nope'));
41 * Write a new config file.
43 public function testWriteNew()
45 $dataFile = 'tests/utils/config/configWrite.php';
48 'redirector' => 'lala',
50 'DATASTORE' => 'data/datastore.php',
53 'WALLABAG_VERSION' => '1',
56 $this->configIO
->write($dataFile, $data);
58 $GLOBALS[\'login\'] = \'root\';
59 $GLOBALS[\'redirector\'] = \'lala\';
60 $GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\';
61 $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\';
63 $this->assertEquals($expected, file_get_contents($dataFile));
68 * Overwrite an existing setting.
70 public function testOverwrite()
72 $source = 'tests/utils/config/configPhp.php';
73 $dest = 'tests/utils/config/configOverwrite.php';
75 $conf = $this->configIO
->read($dest);
76 $conf['redirector'] = 'blabla';
77 $this->configIO
->write($dest, $conf);
78 $conf = $this->configIO
->read($dest);
79 $this->assertEquals('blabla', $conf['redirector']);