3 namespace Friendica\Test\Core\Config;
5 use Friendica\Core\Config\ConfigCache;
6 use Friendica\Core\Config\ConfigCacheLoader;
7 use Friendica\Test\MockedTest;
8 use Friendica\Test\Util\VFSTrait;
9 use org\bovigo\vfs\vfsStream;
11 class ConfigCacheLoaderTest extends MockedTest
15 protected function setUp()
23 * Test the loadConfigFiles() method with default values
25 public function testLoadConfigFiles()
27 $configCacheLoader = new ConfigCacheLoader($this->root->url());
28 $configCache = new ConfigCache();
30 $configCacheLoader->loadConfigFiles($configCache);
32 $this->assertEquals($this->root->url(), $configCache->get('system', 'basepath'));
36 * Test the loadConfigFiles() method with a wrong local.config.php
37 * @expectedException \Exception
38 * @expectedExceptionMessageRegExp /Error loading config file \w+/
40 public function testLoadConfigWrong()
42 $this->delConfigFile('local.config.php');
44 vfsStream::newFile('local.config.php')
45 ->at($this->root->getChild('config'))
46 ->setContent('<?php return true;');
48 $configCacheLoader = new ConfigCacheLoader($this->root->url());
49 $configCache = new ConfigCache();
51 $configCacheLoader->loadConfigFiles($configCache);
55 * Test the loadConfigFiles() method with a local.config.php file
57 public function testLoadConfigFilesLocal()
59 $this->delConfigFile('local.config.php');
61 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
62 '..' . DIRECTORY_SEPARATOR .
63 '..' . DIRECTORY_SEPARATOR .
64 'datasets' . DIRECTORY_SEPARATOR .
65 'config' . DIRECTORY_SEPARATOR .
68 vfsStream::newFile('local.config.php')
69 ->at($this->root->getChild('config'))
70 ->setContent(file_get_contents($file));
72 $configCacheLoader = new ConfigCacheLoader($this->root->url());
73 $configCache = new ConfigCache();
75 $configCacheLoader->loadConfigFiles($configCache);
77 $this->assertEquals('testhost', $configCache->get('database', 'hostname'));
78 $this->assertEquals('testuser', $configCache->get('database', 'username'));
79 $this->assertEquals('testpw', $configCache->get('database', 'password'));
80 $this->assertEquals('testdb', $configCache->get('database', 'database'));
82 $this->assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
83 $this->assertEquals('Friendica Social Network', $configCache->get('config', 'sitename'));
87 * Test the loadConfigFile() method with a local.ini.php file
89 public function testLoadConfigFilesINI()
91 $this->delConfigFile('local.config.php');
93 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
94 '..' . DIRECTORY_SEPARATOR .
95 '..' . DIRECTORY_SEPARATOR .
96 'datasets' . DIRECTORY_SEPARATOR .
97 'config' . DIRECTORY_SEPARATOR .
100 vfsStream::newFile('local.ini.php')
101 ->at($this->root->getChild('config'))
102 ->setContent(file_get_contents($file));
104 $configCacheLoader = new ConfigCacheLoader($this->root->url());
105 $configCache = new ConfigCache();
107 $configCacheLoader->loadConfigFiles($configCache);
109 $this->assertEquals('testhost', $configCache->get('database', 'hostname'));
110 $this->assertEquals('testuser', $configCache->get('database', 'username'));
111 $this->assertEquals('testpw', $configCache->get('database', 'password'));
112 $this->assertEquals('testdb', $configCache->get('database', 'database'));
114 $this->assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
118 * Test the loadConfigFile() method with a .htconfig.php file
120 public function testLoadConfigFilesHtconfig()
122 $this->delConfigFile('local.config.php');
124 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
125 '..' . DIRECTORY_SEPARATOR .
126 '..' . DIRECTORY_SEPARATOR .
127 'datasets' . DIRECTORY_SEPARATOR .
128 'config' . DIRECTORY_SEPARATOR .
129 '.htconfig.test.php';
131 vfsStream::newFile('.htconfig.php')
133 ->setContent(file_get_contents($file));
135 $configCacheLoader = new ConfigCacheLoader($this->root->url());
136 $configCache = new ConfigCache();
138 $configCacheLoader->loadConfigFiles($configCache);
140 $this->assertEquals('testhost', $configCache->get('database', 'hostname'));
141 $this->assertEquals('testuser', $configCache->get('database', 'username'));
142 $this->assertEquals('testpw', $configCache->get('database', 'password'));
143 $this->assertEquals('testdb', $configCache->get('database', 'database'));
145 $this->assertEquals('/var/run/friendica.pid', $configCache->get('system', 'pidfile'));
146 $this->assertEquals('Europe/Berlin', $configCache->get('system', 'default_timezone'));
147 $this->assertEquals('fr', $configCache->get('system', 'language'));
150 public function testLoadAddonConfig()
160 vfsStream::create($structure, $this->root);
162 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
163 '..' . DIRECTORY_SEPARATOR .
164 '..' . DIRECTORY_SEPARATOR .
165 'datasets' . DIRECTORY_SEPARATOR .
166 'config' . DIRECTORY_SEPARATOR .
169 vfsStream::newFile('test.config.php')
170 ->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
171 ->setContent(file_get_contents($file));
173 $configCacheLoader = new ConfigCacheLoader($this->root->url());
175 $conf = $configCacheLoader->loadAddonConfig('test');
177 $this->assertEquals('testhost', $conf['database']['hostname']);
178 $this->assertEquals('testuser', $conf['database']['username']);
179 $this->assertEquals('testpw', $conf['database']['password']);
180 $this->assertEquals('testdb', $conf['database']['database']);
182 $this->assertEquals('admin@test.it', $conf['config']['admin_email']);