]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/config/ConfigPhpTest.php
Compatibility with PHPUnit 9
[github/shaarli/Shaarli.git] / tests / config / ConfigPhpTest.php
CommitLineData
59404d79 1<?php
3c66e564 2namespace Shaarli\Config;
59404d79
A
3
4/**
5 * Class ConfigPhpTest
def39d0d
A
6 *
7 * We run tests in separate processes due to the usage for $GLOBALS
8 * which are kept between tests.
9 * @runTestsInSeparateProcesses
59404d79 10 */
a5a9cf23 11class ConfigPhpTest extends \Shaarli\TestCase
59404d79
A
12{
13 /**
14 * @var ConfigPhp
15 */
16 protected $configIO;
17
8f60e120 18 protected function setUp(): void
59404d79
A
19 {
20 $this->configIO = new ConfigPhp();
21 }
22
23 /**
24 * Read a simple existing config file.
25 */
26 public function testRead()
27 {
684e662a 28 $conf = $this->configIO->read('tests/utils/config/configPhp.php');
59404d79
A
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']);
33 }
34
35 /**
36 * Read a non existent config file -> empty array.
37 */
38 public function testReadNonExistent()
39 {
40 $this->assertEquals(array(), $this->configIO->read('nope'));
41 }
42
cb4ddbe4
A
43 /**
44 * Read an empty existent config file -> array with blank default values.
45 */
46 public function testReadEmpty()
47 {
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']);
55 }
56
59404d79
A
57 /**
58 * Write a new config file.
59 */
60 public function testWriteNew()
61 {
684e662a 62 $dataFile = 'tests/utils/config/configWrite.php';
59404d79
A
63 $data = array(
64 'login' => 'root',
65 'redirector' => 'lala',
66 'config' => array(
67 'DATASTORE' => 'data/datastore.php',
68 ),
69 'plugins' => array(
70 'WALLABAG_VERSION' => '1',
71 )
72 );
73 $this->configIO->write($dataFile, $data);
74 $expected = '<?php
75$GLOBALS[\'login\'] = \'root\';
76$GLOBALS[\'redirector\'] = \'lala\';
77$GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\';
78$GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\';
79';
684e662a
A
80 $this->assertEquals($expected, file_get_contents($dataFile));
81 unlink($dataFile);
59404d79
A
82 }
83
84 /**
85 * Overwrite an existing setting.
86 */
87 public function testOverwrite()
88 {
684e662a
A
89 $source = 'tests/utils/config/configPhp.php';
90 $dest = 'tests/utils/config/configOverwrite.php';
91 copy($source, $dest);
59404d79
A
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']);
684e662a 97 unlink($dest);
59404d79
A
98 }
99}