3 namespace Friendica\Test\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 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 '..' . DIRECTORY_SEPARATOR .
65 'datasets' . DIRECTORY_SEPARATOR .
66 'config' . DIRECTORY_SEPARATOR .
69 vfsStream::newFile('local.config.php')
70 ->at($this->root->getChild('config'))
71 ->setContent(file_get_contents($file));
73 $configCacheLoader = new ConfigCacheLoader($this->root->url());
74 $configCache = new ConfigCache();
76 $configCacheLoader->loadConfigFiles($configCache);
78 $this->assertEquals('testhost', $configCache->get('database', 'hostname'));
79 $this->assertEquals('testuser', $configCache->get('database', 'username'));
80 $this->assertEquals('testpw', $configCache->get('database', 'password'));
81 $this->assertEquals('testdb', $configCache->get('database', 'database'));
83 $this->assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
84 $this->assertEquals('Friendica Social Network', $configCache->get('config', 'sitename'));
88 * Test the loadConfigFile() method with a local.ini.php file
90 public function testLoadConfigFilesINI()
92 $this->delConfigFile('local.config.php');
94 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
95 '..' . DIRECTORY_SEPARATOR .
96 '..' . DIRECTORY_SEPARATOR .
97 '..' . DIRECTORY_SEPARATOR .
98 'datasets' . DIRECTORY_SEPARATOR .
99 'config' . DIRECTORY_SEPARATOR .
102 vfsStream::newFile('local.ini.php')
103 ->at($this->root->getChild('config'))
104 ->setContent(file_get_contents($file));
106 $configCacheLoader = new ConfigCacheLoader($this->root->url());
107 $configCache = new ConfigCache();
109 $configCacheLoader->loadConfigFiles($configCache);
111 $this->assertEquals('testhost', $configCache->get('database', 'hostname'));
112 $this->assertEquals('testuser', $configCache->get('database', 'username'));
113 $this->assertEquals('testpw', $configCache->get('database', 'password'));
114 $this->assertEquals('testdb', $configCache->get('database', 'database'));
116 $this->assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
120 * Test the loadConfigFile() method with a .htconfig.php file
122 public function testLoadConfigFilesHtconfig()
124 $this->delConfigFile('local.config.php');
126 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
127 '..' . DIRECTORY_SEPARATOR .
128 '..' . DIRECTORY_SEPARATOR .
129 '..' . DIRECTORY_SEPARATOR .
130 'datasets' . DIRECTORY_SEPARATOR .
131 'config' . DIRECTORY_SEPARATOR .
132 '.htconfig.test.php';
134 vfsStream::newFile('.htconfig.php')
136 ->setContent(file_get_contents($file));
138 $configCacheLoader = new ConfigCacheLoader($this->root->url());
139 $configCache = new ConfigCache();
141 $configCacheLoader->loadConfigFiles($configCache);
143 $this->assertEquals('testhost', $configCache->get('database', 'hostname'));
144 $this->assertEquals('testuser', $configCache->get('database', 'username'));
145 $this->assertEquals('testpw', $configCache->get('database', 'password'));
146 $this->assertEquals('testdb', $configCache->get('database', 'database'));
148 $this->assertEquals('/var/run/friendica.pid', $configCache->get('system', 'pidfile'));
149 $this->assertEquals('Europe/Berlin', $configCache->get('system', 'default_timezone'));
150 $this->assertEquals('fr', $configCache->get('system', 'language'));
153 public function testLoadAddonConfig()
163 vfsStream::create($structure, $this->root);
165 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
166 '..' . DIRECTORY_SEPARATOR .
167 '..' . DIRECTORY_SEPARATOR .
168 '..' . DIRECTORY_SEPARATOR .
169 'datasets' . DIRECTORY_SEPARATOR .
170 'config' . DIRECTORY_SEPARATOR .
173 vfsStream::newFile('test.config.php')
174 ->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
175 ->setContent(file_get_contents($file));
177 $configCacheLoader = new ConfigCacheLoader($this->root->url());
179 $conf = $configCacheLoader->loadAddonConfig('test');
181 $this->assertEquals('testhost', $conf['database']['hostname']);
182 $this->assertEquals('testuser', $conf['database']['username']);
183 $this->assertEquals('testpw', $conf['database']['password']);
184 $this->assertEquals('testdb', $conf['database']['database']);
186 $this->assertEquals('admin@test.it', $conf['config']['admin_email']);