namespace Friendica\Test\src\Core\Console;
+use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Console\AutomaticInstallation;
-use Friendica\Core\Installer;
+use Friendica\Core\Logger;
use Friendica\Test\Util\DBAMockTrait;
use Friendica\Test\Util\DBStructureMockTrait;
use Friendica\Test\Util\L10nMockTrait;
use Friendica\Test\Util\RendererMockTrait;
+use Friendica\Util\Logger\VoidLogger;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamFile;
$this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
$this->db_pass = getenv('MYSQL_PASSWORD');
- $this->configMock
- ->shouldReceive('get')
- ->with('config', 'php_path')
- ->andReturn(null);
-
- $this->configMock->shouldReceive('set')
- ->with('config', 'php_path', \Mockery::any())->once();
- $this->configMock->shouldReceive('set')
- ->with('config', 'hostname', '')->once();
- $this->configMock->shouldReceive('set')
- ->with('system', 'basepath', \Mockery::any())->once();
- $this->configMock->shouldReceive('set')
- ->with('system', 'urlpath' , '')->once();
- $this->configMock->shouldReceive('set')
- ->with('system', 'ssl_policy', SSL_POLICY_NONE)->once();
- $this->mode->shouldReceive('isInstall')
- ->andReturn(false);
-
$this->mockL10nT();
}
/**
* Creates the arguments which is asserted to be passed to 'replaceMacros()' for creating the local.config.php
*
- * @param bool $withDb if true, DB will get saved too
+ * @param ConfigCache $config The config cache of this test
*
* @return array The arguments to pass to the mock for 'replaceMacros()'
*/
- private function createArgumentsForMacro($withDb)
+ private function createArgumentsForMacro(ConfigCache $config)
{
$args = [
- '$phpath' => trim(shell_exec('which php')),
- '$dbhost' => (($withDb) ? $this->db_host . (isset($this->db_port) ? ':' . $this->db_port : '') : ''),
- '$dbuser' => (($withDb) ? $this->db_user : ''),
- '$dbpass' => (($withDb) ? $this->db_pass : ''),
- '$dbdata' => (($withDb) ? $this->db_data : ''),
- '$timezone' => Installer::DEFAULT_TZ,
- '$language' => Installer::DEFAULT_LANG,
- '$urlpath' => '/friendica',
- '$basepath' => '/test',
- '$hostname' => 'friendica.local',
- '$adminmail' => 'admin@friendica.local'
+ '$dbhost' => $config->get('database','hostname'),
+ '$dbuser' => $config->get('database','username'),
+ '$dbpass' => $config->get('database','password'),
+ '$dbdata' => $config->get('database','database'),
+
+ '$phpath' => $config->get('config','php_path'),
+ '$adminmail' => $config->get('config','admin_email'),
+ '$hostname' => $config->get('config','hostname'),
+
+ '$urlpath' => $config->get('system','urlpath'),
+ '$baseurl' => $config->get('system','url'),
+ '$sslpolicy' => $config->get('system','ssl_policy'),
+ '$timezone' => $config->get('system','default_timezone'),
+ '$language' => $config->get('system','language'),
+ '$basepath' => $config->get('system','basepath'),
];
return $args;
$this->assertEquals($finished, $txt);
}
+ public function dataInstaller()
+ {
+ return [
+ 'empty' => [
+ 'data' => [
+ 'database' => [
+ 'hostname' => '',
+ 'username' => '',
+ 'password' => '',
+ 'database' => '',
+ ],
+ 'config' => [
+ 'php_path' => '',
+ 'hostname' => '',
+ 'admin_email' => '',
+ ],
+ 'system' => [
+ 'urlpath' => '',
+ 'url' => '',
+ 'basepath' => '',
+ 'ssl_policy' => '',
+ 'default_timezone' => '',
+ 'language' => '',
+ ],
+ ],
+ ],
+ 'normal' => [
+ 'data' => [
+ 'database' => [
+ 'hostname' => getenv('MYSQL_HOST'),
+ 'port' =>!empty(getenv('MYSQL_PORT')) ? getenv('MYSQL_PORT') : null,
+ 'username' => getenv('MYSQL_USERNAME'),
+ 'password' => getenv('MYSQL_PASSWORD'),
+ 'database' => getenv('MYSQL_DATABASE'),
+ ],
+ 'config' => [
+ 'php_path' => '',
+ 'hostname' => 'friendica.local',
+ 'admin_email' => 'admin@philipp.info',
+ ],
+ 'system' => [
+ 'urlpath' => 'test/it',
+ 'url' => 'friendica.local/test/it',
+ 'basepath' => '',
+ 'ssl_policy' => '2',
+ 'default_timezone' => 'en',
+ 'language' => 'Europe/Berlin',
+ ],
+ ],
+ ],
+ ];
+ }
+
/**
* Test the automatic installation without any parameter
+ * @dataProvider dataInstaller
*/
- public function testEmpty()
+ public function testEmpty(array $data)
{
+ $configCache = new ConfigCache();
+ $configCache->load($data);
+ $configCache->set('system', 'basepath', $this->root->url());
+ $configCache->set('config', 'php_path', trim(shell_exec('which php')));
+
+ $this->mockApp($this->root, null, true);
+
+ $this->configMock->shouldReceive('set');
+ $this->configMock->shouldReceive('has')->andReturn(true);
+ $this->configMock->shouldReceive('get')->andReturnUsing(function ($cat, $key) use ($configCache) {
+ return $configCache->get($cat, $key);
+ });
+
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
- $this->configMock->shouldReceive('set')
- ->with('database', 'hostname', Installer::DEFAULT_HOST)->once();
- $this->configMock->shouldReceive('set')
- ->with('database', 'username', '')->once();
- $this->configMock->shouldReceive('set')
- ->with('database', 'password', '')->once();
- $this->configMock->shouldReceive('set')
- ->with('database', 'database', '')->once();
-
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
- $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
+ $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro($configCache), '', 1);
$console = new AutomaticInstallation($this->consoleArgv);
$txt = $this->dumpExecute($console);
- $this->assertFinished($txt, false, true);
-
+ $this->assertFinished($txt, true, false);
+ $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
}
/**
* @medium
+ * @dataProvider dataInstaller
*/
- public function testWithConfig()
+ public function testWithConfig(array $data)
{
+ $configCache = new ConfigCache();
+ $configCache->load($data);
+ $configCache->set('system', 'basepath', $this->root->url());
+ $configCache->set('config', 'php_path', trim(shell_exec('which php')));
+
+ $this->mockApp($this->root, $configCache, true);
+ $this->mode->shouldReceive('isInstall')->andReturn(false);
+ Logger::init(new VoidLogger());
+
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
+ $conf = function ($cat, $key) use ($configCache) {
+ return $configCache->get($cat, $key);
+ };
+
$config = <<<CONF
<?php
return [
'database' => [
- 'hostname' => '',
- 'username' => '',
- 'password' => '',
- 'database' => '',
+ 'hostname' => '{$conf('database','hostname')}',
+ 'username' => '{$conf('database', 'username')}',
+ 'password' => '{$conf('database', 'password')}',
+ 'database' => '{$conf('database', 'database')}',
'charset' => 'utf8mb4',
],
// ****************************************************************
'config' => [
- 'admin_email' => '',
+ 'admin_email' => '{$conf('config', 'admin_email')}',
+ 'hostname' => '{$conf('config', 'hostname')}',
'sitename' => 'Friendica Social Network',
'register_policy' => \Friendica\Module\Register::OPEN,
'register_text' => '',
],
'system' => [
- 'default_timezone' => 'UTC',
- 'language' => 'en',
+ 'basepath => '{$conf('system', 'basepath')}',
+ 'urlpath => '{$conf('system', 'urlpath')}',
+ 'url' => '{$conf('system', 'url')}',
+ 'default_timezone' => '{$conf('system', 'default_timezone')}',
+ 'language' => '{$conf('system', 'language')}',
],
];
CONF;
$this->assertFinished($txt, false, true);
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
+ $this->assertEquals($config, file_get_contents($this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')->url()));
}
/**
* @medium
+ * @dataProvider dataInstaller
*/
- public function testWithEnvironmentAndSave()
+ public function testWithEnvironmentAndSave(array $data)
{
+ $configCache = new ConfigCache();
+ $configCache->set('system', 'basepath', $this->root->url());
+ $configCache->set('config', 'php_path', trim(shell_exec('which php')));
+
+ $this->mockApp($this->root, $configCache);
+
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
- $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(true), '', 1);
+ $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro($configCache), '', 1);
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
$this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
$txt = $this->dumpExecute($console);
+ print_r($configCache);
+
$this->assertFinished($txt, true);
}