2 namespace Shaarli\Config
;
7 * We run tests in separate processes due to the usage for $GLOBALS
8 * which are kept between tests.
9 * @runTestsInSeparateProcesses
11 class ConfigPhpTest
extends \PHPUnit\Framework\TestCase
18 public function setUp()
20 $this->configIO
= new ConfigPhp();
24 * Read a simple existing config file.
26 public function testRead()
28 $conf = $this->configIO
->read('tests/utils/config/configPhp.php');
29 $this->assertEquals('root', $conf['login']);
30 $this->assertEquals('lala', $conf['redirector']);
31 $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']);
32 $this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']);
36 * Read a non existent config file -> empty array.
38 public function testReadNonExistent()
40 $this->assertEquals(array(), $this->configIO
->read('nope'));
44 * Read an empty existent config file -> array with blank default values.
46 public function testReadEmpty()
48 $dataFile = 'tests/utils/config/emptyConfigPhp.php';
49 $conf = $this->configIO
->read($dataFile);
50 $this->assertEmpty($conf['login']);
51 $this->assertEmpty($conf['title']);
52 $this->assertEmpty($conf['titleLink']);
53 $this->assertEmpty($conf['config']);
54 $this->assertEmpty($conf['plugins']);
58 * Write a new config file.
60 public function testWriteNew()
62 $dataFile = 'tests/utils/config/configWrite.php';
65 'redirector' => 'lala',
67 'DATASTORE' => 'data/datastore.php',
70 'WALLABAG_VERSION' => '1',
73 $this->configIO
->write($dataFile, $data);
75 $GLOBALS[\'login\'] = \'root\';
76 $GLOBALS[\'redirector\'] = \'lala\';
77 $GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\';
78 $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\';
80 $this->assertEquals($expected, file_get_contents($dataFile));
85 * Overwrite an existing setting.
87 public function testOverwrite()
89 $source = 'tests/utils/config/configPhp.php';
90 $dest = 'tests/utils/config/configOverwrite.php';
92 $conf = $this->configIO
->read($dest);
93 $conf['redirector'] = 'blabla';
94 $this->configIO
->write($dest, $conf);
95 $conf = $this->configIO
->read($dest);
96 $this->assertEquals('blabla', $conf['redirector']);