]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/config/ConfigPhpTest.php
Merge remote-tracking branch 'origin/doc-tagcloud' into doc-overhaul
[github/shaarli/Shaarli.git] / tests / config / ConfigPhpTest.php
CommitLineData
59404d79 1<?php
3c66e564 2namespace Shaarli\Config;
59404d79
A
3
4/**
5 * Class ConfigPhpTest
6 */
3c66e564 7class ConfigPhpTest extends \PHPUnit_Framework_TestCase
59404d79
A
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 {
684e662a 24 $conf = $this->configIO->read('tests/utils/config/configPhp.php');
59404d79
A
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 {
684e662a 44 $dataFile = 'tests/utils/config/configWrite.php';
59404d79
A
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';
684e662a
A
62 $this->assertEquals($expected, file_get_contents($dataFile));
63 unlink($dataFile);
59404d79
A
64 }
65
66 /**
67 * Overwrite an existing setting.
68 */
69 public function testOverwrite()
70 {
684e662a
A
71 $source = 'tests/utils/config/configPhp.php';
72 $dest = 'tests/utils/config/configOverwrite.php';
73 copy($source, $dest);
59404d79
A
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']);
684e662a 79 unlink($dest);
59404d79
A
80 }
81}