diff options
Diffstat (limited to 'tests/config/ConfigPhpTest.php')
-rw-r--r-- | tests/config/ConfigPhpTest.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php new file mode 100644 index 00000000..0f849bd5 --- /dev/null +++ b/tests/config/ConfigPhpTest.php | |||
@@ -0,0 +1,82 @@ | |||
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/config/php/configOK'); | ||
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/config/php/configWrite'; | ||
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 .'.php')); | ||
64 | unlink($dataFile .'.php'); | ||
65 | } | ||
66 | |||
67 | /** | ||
68 | * Overwrite an existing setting. | ||
69 | */ | ||
70 | public function testOverwrite() | ||
71 | { | ||
72 | $source = 'tests/config/php/configOK.php'; | ||
73 | $dest = 'tests/config/php/configOverwrite'; | ||
74 | copy($source, $dest . '.php'); | ||
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 .'.php'); | ||
81 | } | ||
82 | } | ||