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