]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | namespace Shaarli\Config; | |
3 | ||
4 | /** | |
5 | * Class ConfigPhpTest | |
6 | */ | |
7 | class ConfigPhpTest extends \PHPUnit_Framework_TestCase | |
8 | { | |
9 | /** | |
10 | * @var ConfigPhp | |
11 | */ | |
12 | protected $configIO; | |
13 | ||
14 | public function setUp() | |
15 | { | |
16 | $this->configIO = new ConfigPhp(); | |
17 | } | |
18 | ||
19 | /** | |
20 | * Read a simple existing config file. | |
21 | */ | |
22 | public function testRead() | |
23 | { | |
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']); | |
29 | } | |
30 | ||
31 | /** | |
32 | * Read a non existent config file -> empty array. | |
33 | */ | |
34 | public function testReadNonExistent() | |
35 | { | |
36 | $this->assertEquals(array(), $this->configIO->read('nope')); | |
37 | } | |
38 | ||
39 | /** | |
40 | * Write a new config file. | |
41 | */ | |
42 | public function testWriteNew() | |
43 | { | |
44 | $dataFile = 'tests/utils/config/configWrite.php'; | |
45 | $data = array( | |
46 | 'login' => 'root', | |
47 | 'redirector' => 'lala', | |
48 | 'config' => array( | |
49 | 'DATASTORE' => 'data/datastore.php', | |
50 | ), | |
51 | 'plugins' => array( | |
52 | 'WALLABAG_VERSION' => '1', | |
53 | ) | |
54 | ); | |
55 | $this->configIO->write($dataFile, $data); | |
56 | $expected = '<?php | |
57 | $GLOBALS[\'login\'] = \'root\'; | |
58 | $GLOBALS[\'redirector\'] = \'lala\'; | |
59 | $GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\'; | |
60 | $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\'; | |
61 | '; | |
62 | $this->assertEquals($expected, file_get_contents($dataFile)); | |
63 | unlink($dataFile); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Overwrite an existing setting. | |
68 | */ | |
69 | public function testOverwrite() | |
70 | { | |
71 | $source = 'tests/utils/config/configPhp.php'; | |
72 | $dest = 'tests/utils/config/configOverwrite.php'; | |
73 | copy($source, $dest); | |
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']); | |
79 | unlink($dest); | |
80 | } | |
81 | } |