3 namespace Friendica\Test\src\Core\Config\Cache;
5 use Friendica\Core\Config\Cache\ConfigCache;
6 use Friendica\Core\Config\Cache\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 a wrong local.config.php
24 * @expectedException \Exception
25 * @expectedExceptionMessageRegExp /Error loading config file \w+/
27 public function testLoadConfigWrong()
29 $this->delConfigFile('local.config.php');
31 vfsStream::newFile('local.config.php')
32 ->at($this->root->getChild('config'))
33 ->setContent('<?php return true;');
35 $configCacheLoader = new ConfigCacheLoader($this->root->url());
36 $configCache = new ConfigCache();
38 $configCacheLoader->loadConfigFiles($configCache);
42 * Test the loadConfigFiles() method with a local.config.php file
44 public function testLoadConfigFilesLocal()
46 $this->delConfigFile('local.config.php');
48 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
49 '..' . DIRECTORY_SEPARATOR .
50 '..' . DIRECTORY_SEPARATOR .
51 '..' . DIRECTORY_SEPARATOR .
52 'datasets' . DIRECTORY_SEPARATOR .
53 'config' . DIRECTORY_SEPARATOR .
56 vfsStream::newFile('local.config.php')
57 ->at($this->root->getChild('config'))
58 ->setContent(file_get_contents($file));
60 $configCacheLoader = new ConfigCacheLoader($this->root->url());
61 $configCache = new ConfigCache();
63 $configCacheLoader->loadConfigFiles($configCache);
65 $this->assertEquals('testhost', $configCache->get('database', 'hostname'));
66 $this->assertEquals('testuser', $configCache->get('database', 'username'));
67 $this->assertEquals('testpw', $configCache->get('database', 'password'));
68 $this->assertEquals('testdb', $configCache->get('database', 'database'));
70 $this->assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
71 $this->assertEquals('Friendica Social Network', $configCache->get('config', 'sitename'));
75 * Test the loadConfigFile() method with a local.ini.php file
77 public function testLoadConfigFilesINI()
79 $this->delConfigFile('local.config.php');
81 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
82 '..' . DIRECTORY_SEPARATOR .
83 '..' . DIRECTORY_SEPARATOR .
84 '..' . DIRECTORY_SEPARATOR .
85 'datasets' . DIRECTORY_SEPARATOR .
86 'config' . DIRECTORY_SEPARATOR .
89 vfsStream::newFile('local.ini.php')
90 ->at($this->root->getChild('config'))
91 ->setContent(file_get_contents($file));
93 $configCacheLoader = new ConfigCacheLoader($this->root->url());
94 $configCache = new ConfigCache();
96 $configCacheLoader->loadConfigFiles($configCache);
98 $this->assertEquals('testhost', $configCache->get('database', 'hostname'));
99 $this->assertEquals('testuser', $configCache->get('database', 'username'));
100 $this->assertEquals('testpw', $configCache->get('database', 'password'));
101 $this->assertEquals('testdb', $configCache->get('database', 'database'));
103 $this->assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
107 * Test the loadConfigFile() method with a .htconfig.php file
109 public function testLoadConfigFilesHtconfig()
111 $this->delConfigFile('local.config.php');
113 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
114 '..' . DIRECTORY_SEPARATOR .
115 '..' . DIRECTORY_SEPARATOR .
116 '..' . DIRECTORY_SEPARATOR .
117 'datasets' . DIRECTORY_SEPARATOR .
118 'config' . DIRECTORY_SEPARATOR .
119 '.htconfig.test.php';
121 vfsStream::newFile('.htconfig.php')
123 ->setContent(file_get_contents($file));
125 $configCacheLoader = new ConfigCacheLoader($this->root->url());
126 $configCache = new ConfigCache();
128 $configCacheLoader->loadConfigFiles($configCache);
130 $this->assertEquals('testhost', $configCache->get('database', 'hostname'));
131 $this->assertEquals('testuser', $configCache->get('database', 'username'));
132 $this->assertEquals('testpw', $configCache->get('database', 'password'));
133 $this->assertEquals('testdb', $configCache->get('database', 'database'));
134 $this->assertEquals('anotherCharset', $configCache->get('database', 'charset'));
136 $this->assertEquals('/var/run/friendica.pid', $configCache->get('system', 'pidfile'));
137 $this->assertEquals('Europe/Berlin', $configCache->get('system', 'default_timezone'));
138 $this->assertEquals('fr', $configCache->get('system', 'language'));
140 $this->assertEquals('admin@friendica.local', $configCache->get('config', 'admin_email'));
141 $this->assertEquals('Friendly admin', $configCache->get('config', 'admin_nickname'));
143 $this->assertEquals('/another/php', $configCache->get('config', 'php_path'));
144 $this->assertEquals('999', $configCache->get('config', 'max_import_size'));
145 $this->assertEquals('666', $configCache->get('system', 'maximagesize'));
147 $this->assertEquals('quattro,vier,duepuntozero', $configCache->get('system', 'allowed_themes'));
148 $this->assertEquals('1', $configCache->get('system', 'no_regfullname'));
151 public function testLoadAddonConfig()
161 vfsStream::create($structure, $this->root);
163 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
164 '..' . DIRECTORY_SEPARATOR .
165 '..' . DIRECTORY_SEPARATOR .
166 '..' . DIRECTORY_SEPARATOR .
167 'datasets' . DIRECTORY_SEPARATOR .
168 'config' . DIRECTORY_SEPARATOR .
171 vfsStream::newFile('test.config.php')
172 ->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
173 ->setContent(file_get_contents($file));
175 $configCacheLoader = new ConfigCacheLoader($this->root->url());
177 $conf = $configCacheLoader->loadAddonConfig('test');
179 $this->assertEquals('testhost', $conf['database']['hostname']);
180 $this->assertEquals('testuser', $conf['database']['username']);
181 $this->assertEquals('testpw', $conf['database']['password']);
182 $this->assertEquals('testdb', $conf['database']['database']);
184 $this->assertEquals('admin@test.it', $conf['config']['admin_email']);