]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/config/ConfigPhpTest.php
Fix input size for dropdown search form
[github/shaarli/Shaarli.git] / tests / config / ConfigPhpTest.php
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 * 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
53 /**
54 * Write a new config file.
55 */
56 public function testWriteNew()
57 {
58 $dataFile = 'tests/utils/config/configWrite.php';
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 ';
76 $this->assertEquals($expected, file_get_contents($dataFile));
77 unlink($dataFile);
78 }
79
80 /**
81 * Overwrite an existing setting.
82 */
83 public function testOverwrite()
84 {
85 $source = 'tests/utils/config/configPhp.php';
86 $dest = 'tests/utils/config/configOverwrite.php';
87 copy($source, $dest);
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']);
93 unlink($dest);
94 }
95 }