]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/config/ConfigPhpTest.php
add label to form - accessibility issue
[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
cb4ddbe4
A
39 /**
40 * Read an empty existent config file -> array with blank default values.
41 */
42 public function testReadEmpty()
43 {
44 $dataFile = 'tests/utils/config/emptyConfigPhp.php';
45 $conf = $this->configIO->read($dataFile);
46 $this->assertEmpty($conf['login']);
47 $this->assertEmpty($conf['title']);
48 $this->assertEmpty($conf['titleLink']);
49 $this->assertEmpty($conf['config']);
50 $this->assertEmpty($conf['plugins']);
51 }
52
59404d79
A
53 /**
54 * Write a new config file.
55 */
56 public function testWriteNew()
57 {
684e662a 58 $dataFile = 'tests/utils/config/configWrite.php';
59404d79
A
59 $data = array(
60 'login' => 'root',
61 'redirector' => 'lala',
62 'config' => array(
63 'DATASTORE' => 'data/datastore.php',
64 ),
65 'plugins' => array(
66 'WALLABAG_VERSION' => '1',
67 )
68 );
69 $this->configIO->write($dataFile, $data);
70 $expected = '<?php
71$GLOBALS[\'login\'] = \'root\';
72$GLOBALS[\'redirector\'] = \'lala\';
73$GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\';
74$GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\';
75';
684e662a
A
76 $this->assertEquals($expected, file_get_contents($dataFile));
77 unlink($dataFile);
59404d79
A
78 }
79
80 /**
81 * Overwrite an existing setting.
82 */
83 public function testOverwrite()
84 {
684e662a
A
85 $source = 'tests/utils/config/configPhp.php';
86 $dest = 'tests/utils/config/configOverwrite.php';
87 copy($source, $dest);
59404d79
A
88 $conf = $this->configIO->read($dest);
89 $conf['redirector'] = 'blabla';
90 $this->configIO->write($dest, $conf);
91 $conf = $this->configIO->read($dest);
92 $this->assertEquals('blabla', $conf['redirector']);
684e662a 93 unlink($dest);
59404d79
A
94 }
95}