2 namespace Shaarli\Config
;
7 class ConfigPhpTest
extends \PHPUnit_Framework_TestCase
14 public function setUp()
16 $this->configIO
= new ConfigPhp();
20 * Read a simple existing config file.
22 public function testRead()
24 $conf = $this->configIO
->read('tests/utils/config/configPhp.php');
25 $this->assertEquals('root', $conf['login']);
26 $this->assertEquals('lala', $conf['redirector']);
27 $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']);
28 $this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']);
32 * Read a non existent config file -> empty array.
34 public function testReadNonExistent()
36 $this->assertEquals(array(), $this->configIO
->read('nope'));
40 * Write a new config file.
42 public function testWriteNew()
44 $dataFile = 'tests/utils/config/configWrite.php';
47 'redirector' => 'lala',
49 'DATASTORE' => 'data/datastore.php',
52 'WALLABAG_VERSION' => '1',
55 $this->configIO
->write($dataFile, $data);
57 $GLOBALS[\'login\'] = \'root\';
58 $GLOBALS[\'redirector\'] = \'lala\';
59 $GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\';
60 $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\';
62 $this->assertEquals($expected, file_get_contents($dataFile));
67 * Overwrite an existing setting.
69 public function testOverwrite()
71 $source = 'tests/utils/config/configPhp.php';
72 $dest = 'tests/utils/config/configOverwrite.php';
74 $conf = $this->configIO
->read($dest);
75 $conf['redirector'] = 'blabla';
76 $this->configIO
->write($dest, $conf);
77 $conf = $this->configIO
->read($dest);
78 $this->assertEquals('blabla', $conf['redirector']);