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 * Read an empty existent config file -> array with blank default values.
42 public function testReadEmpty()
44 $dataFile = 'tests/utils/config/emptyConfigPhp.php';
45 $conf = $this->configIO
->read($dataFile);
46 $this->assertEmpty($conf['login']);
47 $this->assertEmpty($conf['title']);
48 $this->assertEmpty($conf['titleLink']);
49 $this->assertEmpty($conf['config']);
50 $this->assertEmpty($conf['plugins']);
54 * Write a new config file.
56 public function testWriteNew()
58 $dataFile = 'tests/utils/config/configWrite.php';
61 'redirector' => 'lala',
63 'DATASTORE' => 'data/datastore.php',
66 'WALLABAG_VERSION' => '1',
69 $this->configIO
->write($dataFile, $data);
71 $GLOBALS[\'login\'] = \'root\';
72 $GLOBALS[\'redirector\'] = \'lala\';
73 $GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\';
74 $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\';
76 $this->assertEquals($expected, file_get_contents($dataFile));
81 * Overwrite an existing setting.
83 public function testOverwrite()
85 $source = 'tests/utils/config/configPhp.php';
86 $dest = 'tests/utils/config/configOverwrite.php';
88 $conf = $this->configIO
->read($dest);
89 $conf['redirector'] = 'blabla';
90 $this->configIO
->write($dest, $conf);
91 $conf = $this->configIO
->read($dest);
92 $this->assertEquals('blabla', $conf['redirector']);