2018-08-27 04:15:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Test\src\Core\Console;
|
|
|
|
|
2019-03-13 20:51:04 +00:00
|
|
|
use Friendica\Core\Config\Cache\ConfigCache;
|
2018-10-31 09:16:15 +00:00
|
|
|
use Friendica\Core\Console\AutomaticInstallation;
|
2019-03-13 22:05:33 +00:00
|
|
|
use Friendica\Core\Logger;
|
2018-10-31 09:24:07 +00:00
|
|
|
use Friendica\Test\Util\DBAMockTrait;
|
2018-10-31 09:16:15 +00:00
|
|
|
use Friendica\Test\Util\DBStructureMockTrait;
|
2018-11-01 12:44:47 +00:00
|
|
|
use Friendica\Test\Util\L10nMockTrait;
|
2018-11-01 09:30:44 +00:00
|
|
|
use Friendica\Test\Util\RendererMockTrait;
|
2019-03-13 22:05:33 +00:00
|
|
|
use Friendica\Util\Logger\VoidLogger;
|
2018-08-27 04:15:55 +00:00
|
|
|
use org\bovigo\vfs\vfsStream;
|
2018-10-31 10:03:15 +00:00
|
|
|
use org\bovigo\vfs\vfsStreamFile;
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @runTestsInSeparateProcesses
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
* @requires PHP 7.0
|
|
|
|
*/
|
|
|
|
class AutomaticInstallationConsoleTest extends ConsoleTest
|
|
|
|
{
|
2018-11-01 12:44:47 +00:00
|
|
|
use L10nMockTrait;
|
2018-10-31 09:24:07 +00:00
|
|
|
use DBAMockTrait;
|
2018-10-31 09:16:15 +00:00
|
|
|
use DBStructureMockTrait;
|
2018-11-01 09:30:44 +00:00
|
|
|
use RendererMockTrait;
|
2018-10-31 09:16:15 +00:00
|
|
|
|
2018-08-27 04:15:55 +00:00
|
|
|
private $db_host;
|
|
|
|
private $db_port;
|
|
|
|
private $db_data;
|
|
|
|
private $db_user;
|
|
|
|
private $db_pass;
|
|
|
|
|
2018-10-31 10:03:15 +00:00
|
|
|
/**
|
|
|
|
* @var vfsStreamFile Assert file without DB credentials
|
|
|
|
*/
|
2018-10-31 09:16:15 +00:00
|
|
|
private $assertFile;
|
2018-10-31 10:03:15 +00:00
|
|
|
/**
|
|
|
|
* @var vfsStreamFile Assert file with DB credentials
|
|
|
|
*/
|
2018-10-31 09:16:15 +00:00
|
|
|
private $assertFileDb;
|
|
|
|
|
2018-08-27 04:15:55 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2018-11-25 06:44:09 +00:00
|
|
|
if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
|
2018-08-27 04:15:55 +00:00
|
|
|
$this->root->getChild('config')
|
2018-11-25 06:44:09 +00:00
|
|
|
->removeChild('local.config.php');
|
2018-08-27 04:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->db_host = getenv('MYSQL_HOST');
|
2018-11-30 14:06:22 +00:00
|
|
|
$this->db_port = !empty(getenv('MYSQL_PORT')) ? getenv('MYSQL_PORT') : null;
|
2018-08-27 04:15:55 +00:00
|
|
|
$this->db_data = getenv('MYSQL_DATABASE');
|
|
|
|
$this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
|
|
|
|
$this->db_pass = getenv('MYSQL_PASSWORD');
|
2018-10-30 11:47:44 +00:00
|
|
|
|
2018-11-01 12:44:47 +00:00
|
|
|
$this->mockL10nT();
|
2018-10-31 10:03:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 11:43:34 +00:00
|
|
|
/**
|
2018-11-25 06:44:09 +00:00
|
|
|
* Creates the arguments which is asserted to be passed to 'replaceMacros()' for creating the local.config.php
|
2018-11-01 11:43:34 +00:00
|
|
|
*
|
2019-03-13 22:05:33 +00:00
|
|
|
* @param ConfigCache $config The config cache of this test
|
2018-11-01 11:43:34 +00:00
|
|
|
*
|
|
|
|
* @return array The arguments to pass to the mock for 'replaceMacros()'
|
|
|
|
*/
|
2019-03-13 22:05:33 +00:00
|
|
|
private function createArgumentsForMacro(ConfigCache $config)
|
2018-10-31 10:03:15 +00:00
|
|
|
{
|
2018-11-01 09:30:44 +00:00
|
|
|
$args = [
|
2019-03-13 22:05:33 +00:00
|
|
|
'$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'),
|
2018-11-01 09:30:44 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
return $args;
|
2018-08-27 04:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function assertFinished($txt, $withconfig = false, $copyfile = false)
|
|
|
|
{
|
|
|
|
$cfg = '';
|
|
|
|
|
|
|
|
if ($withconfig) {
|
|
|
|
$cfg = <<<CFG
|
|
|
|
|
|
|
|
|
|
|
|
Creating config file...
|
2018-10-30 10:30:19 +00:00
|
|
|
|
|
|
|
Complete!
|
2018-08-27 04:15:55 +00:00
|
|
|
CFG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($copyfile) {
|
|
|
|
$cfg = <<<CFG
|
|
|
|
|
|
|
|
|
|
|
|
Copying config file...
|
2018-10-30 10:30:19 +00:00
|
|
|
|
|
|
|
Complete!
|
2018-08-27 04:15:55 +00:00
|
|
|
CFG;
|
|
|
|
}
|
|
|
|
|
|
|
|
$finished = <<<FIN
|
2018-10-30 10:30:19 +00:00
|
|
|
Initializing setup...
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
2018-10-30 10:30:19 +00:00
|
|
|
Checking environment...
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
|
|
|
|
|
|
|
|
Complete!
|
2018-10-30 10:30:19 +00:00
|
|
|
{$cfg}
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
Checking database...
|
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
|
|
|
Inserting data into database...
|
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
|
|
|
Installing theme
|
|
|
|
|
|
|
|
Complete
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Installation is finished
|
|
|
|
|
|
|
|
|
|
|
|
FIN;
|
|
|
|
$this->assertEquals($finished, $txt);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function assertStuckDB($txt)
|
|
|
|
{
|
|
|
|
$finished = <<<FIN
|
|
|
|
Initializing setup...
|
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
2018-10-31 09:16:15 +00:00
|
|
|
Checking environment...
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
|
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
2018-10-31 09:16:15 +00:00
|
|
|
Creating config file...
|
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
2018-08-27 04:15:55 +00:00
|
|
|
Checking database...
|
|
|
|
|
|
|
|
[Error] --------
|
2018-10-31 11:37:01 +00:00
|
|
|
Could not connect to database.:
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
FIN;
|
|
|
|
|
|
|
|
$this->assertEquals($finished, $txt);
|
|
|
|
}
|
|
|
|
|
2019-03-13 20:51:04 +00:00
|
|
|
public function dataInstaller()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'empty' => [
|
|
|
|
'data' => [
|
|
|
|
'database' => [
|
|
|
|
'hostname' => '',
|
|
|
|
'username' => '',
|
|
|
|
'password' => '',
|
|
|
|
'database' => '',
|
|
|
|
],
|
|
|
|
'config' => [
|
|
|
|
'php_path' => '',
|
|
|
|
'hostname' => '',
|
|
|
|
'admin_email' => '',
|
|
|
|
],
|
|
|
|
'system' => [
|
|
|
|
'urlpath' => '',
|
2019-03-13 22:05:33 +00:00
|
|
|
'url' => '',
|
2019-03-13 20:51:04 +00:00
|
|
|
'basepath' => '',
|
|
|
|
'ssl_policy' => '',
|
|
|
|
'default_timezone' => '',
|
|
|
|
'language' => '',
|
|
|
|
],
|
|
|
|
],
|
2019-03-13 22:05:33 +00:00
|
|
|
],
|
|
|
|
'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',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2019-03-13 20:51:04 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:46:00 +00:00
|
|
|
/**
|
|
|
|
* Test the automatic installation without any parameter
|
2019-03-13 20:51:04 +00:00
|
|
|
* @dataProvider dataInstaller
|
2019-03-11 21:46:00 +00:00
|
|
|
*/
|
2019-03-13 20:51:04 +00:00
|
|
|
public function testEmpty(array $data)
|
2019-03-11 21:46:00 +00:00
|
|
|
{
|
2019-03-13 20:51:04 +00:00
|
|
|
$configCache = new ConfigCache();
|
|
|
|
$configCache->load($data);
|
|
|
|
$configCache->set('system', 'basepath', $this->root->url());
|
2019-03-13 22:05:33 +00:00
|
|
|
$configCache->set('config', 'php_path', trim(shell_exec('which php')));
|
2019-03-13 20:51:04 +00:00
|
|
|
|
2019-03-13 22:05:33 +00:00
|
|
|
$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);
|
|
|
|
});
|
2019-03-13 20:51:04 +00:00
|
|
|
|
2019-03-11 21:46:00 +00:00
|
|
|
$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);
|
2019-03-13 22:05:33 +00:00
|
|
|
$this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro($configCache), '', 1);
|
2019-03-11 21:46:00 +00:00
|
|
|
|
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
|
|
|
|
|
|
|
$txt = $this->dumpExecute($console);
|
|
|
|
|
2019-03-13 20:51:04 +00:00
|
|
|
$this->assertFinished($txt, true, false);
|
2019-03-13 22:05:33 +00:00
|
|
|
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
|
2019-03-11 21:46:00 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 04:15:55 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
2019-03-13 20:51:04 +00:00
|
|
|
* @dataProvider dataInstaller
|
2018-08-27 04:15:55 +00:00
|
|
|
*/
|
2019-03-13 20:51:04 +00:00
|
|
|
public function testWithConfig(array $data)
|
2018-08-27 04:15:55 +00:00
|
|
|
{
|
2019-03-13 22:05:33 +00:00
|
|
|
$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());
|
|
|
|
|
2018-10-31 09:16:15 +00:00
|
|
|
$this->mockConnect(true, 1);
|
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockExistsTable('user', false, 1);
|
2019-02-03 23:04:16 +00:00
|
|
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
2018-10-31 09:16:15 +00:00
|
|
|
|
2019-03-13 22:05:33 +00:00
|
|
|
$conf = function ($cat, $key) use ($configCache) {
|
|
|
|
return $configCache->get($cat, $key);
|
|
|
|
};
|
|
|
|
|
2018-08-27 04:15:55 +00:00
|
|
|
$config = <<<CONF
|
2018-11-25 06:44:09 +00:00
|
|
|
<?php
|
2018-08-27 04:15:55 +00:00
|
|
|
|
2018-11-25 06:44:09 +00:00
|
|
|
// Local configuration
|
|
|
|
|
|
|
|
// If you're unsure about what any of the config keys below do, please check the config/defaults.config.php for detailed
|
|
|
|
// documentation of their data type and behavior.
|
|
|
|
|
|
|
|
return [
|
|
|
|
'database' => [
|
2019-03-13 22:05:33 +00:00
|
|
|
'hostname' => '{$conf('database','hostname')}',
|
|
|
|
'username' => '{$conf('database', 'username')}',
|
|
|
|
'password' => '{$conf('database', 'password')}',
|
|
|
|
'database' => '{$conf('database', 'database')}',
|
2018-11-25 06:44:09 +00:00
|
|
|
'charset' => 'utf8mb4',
|
|
|
|
],
|
|
|
|
|
|
|
|
// ****************************************************************
|
|
|
|
// The configuration below will be overruled by the admin panel.
|
|
|
|
// Changes made below will only have an effect if the database does
|
|
|
|
// not contain any configuration for the friendica system.
|
|
|
|
// ****************************************************************
|
|
|
|
|
|
|
|
'config' => [
|
2019-03-13 22:05:33 +00:00
|
|
|
'admin_email' => '{$conf('config', 'admin_email')}',
|
|
|
|
'hostname' => '{$conf('config', 'hostname')}',
|
2018-11-25 06:44:09 +00:00
|
|
|
'sitename' => 'Friendica Social Network',
|
2018-12-28 01:56:15 +00:00
|
|
|
'register_policy' => \Friendica\Module\Register::OPEN,
|
2018-11-25 06:44:09 +00:00
|
|
|
'register_text' => '',
|
|
|
|
],
|
|
|
|
'system' => [
|
2019-03-13 22:05:33 +00:00
|
|
|
'basepath => '{$conf('system', 'basepath')}',
|
|
|
|
'urlpath => '{$conf('system', 'urlpath')}',
|
|
|
|
'url' => '{$conf('system', 'url')}',
|
|
|
|
'default_timezone' => '{$conf('system', 'default_timezone')}',
|
|
|
|
'language' => '{$conf('system', 'language')}',
|
2018-11-25 06:44:09 +00:00
|
|
|
],
|
|
|
|
];
|
2018-08-27 04:15:55 +00:00
|
|
|
CONF;
|
|
|
|
|
2018-11-25 06:44:09 +00:00
|
|
|
vfsStream::newFile('prepared.config.php')
|
2018-08-27 04:15:55 +00:00
|
|
|
->at($this->root)
|
|
|
|
->setContent($config);
|
|
|
|
|
2018-10-31 10:57:51 +00:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-11-25 06:44:09 +00:00
|
|
|
$console->setOption('f', 'prepared.config.php');
|
2018-10-31 09:16:15 +00:00
|
|
|
|
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
$this->assertFinished($txt, false, true);
|
|
|
|
|
2018-11-25 06:44:09 +00:00
|
|
|
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
|
2019-03-13 22:05:33 +00:00
|
|
|
$this->assertEquals($config, file_get_contents($this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')->url()));
|
2018-08-27 04:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
2019-03-13 22:05:33 +00:00
|
|
|
* @dataProvider dataInstaller
|
2018-08-27 04:15:55 +00:00
|
|
|
*/
|
2019-03-13 22:05:33 +00:00
|
|
|
public function testWithEnvironmentAndSave(array $data)
|
2018-08-27 04:15:55 +00:00
|
|
|
{
|
2019-03-13 22:05:33 +00:00
|
|
|
$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);
|
|
|
|
|
2018-10-31 09:16:15 +00:00
|
|
|
$this->mockConnect(true, 1);
|
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockExistsTable('user', false, 1);
|
2019-02-03 23:04:16 +00:00
|
|
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
2018-10-31 09:16:15 +00:00
|
|
|
|
2018-11-25 06:44:09 +00:00
|
|
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
2019-03-13 22:05:33 +00:00
|
|
|
$this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro($configCache), '', 1);
|
2018-11-01 09:30:44 +00:00
|
|
|
|
2018-08-27 04:15:55 +00:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_LANG=de'));
|
2018-10-31 09:16:15 +00:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_URL_PATH=/friendica'));
|
|
|
|
|
2018-10-31 10:57:51 +00:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-10-31 09:16:15 +00:00
|
|
|
$console->setOption('savedb', true);
|
2018-08-27 04:15:55 +00:00
|
|
|
|
2018-10-31 09:16:15 +00:00
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-27 04:15:55 +00:00
|
|
|
|
2019-03-13 22:05:33 +00:00
|
|
|
print_r($configCache);
|
|
|
|
|
2018-08-27 04:15:55 +00:00
|
|
|
$this->assertFinished($txt, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
|
|
|
public function testWithEnvironmentWithoutSave()
|
|
|
|
{
|
2018-10-31 09:16:15 +00:00
|
|
|
$this->mockConnect(true, 1);
|
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockExistsTable('user', false, 1);
|
2019-02-03 23:04:16 +00:00
|
|
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
2018-10-31 09:16:15 +00:00
|
|
|
|
2018-11-25 06:44:09 +00:00
|
|
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
2018-11-01 09:30:44 +00:00
|
|
|
$this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(false), '', 1);
|
|
|
|
|
2018-08-27 04:15:55 +00:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_LANG=de'));
|
2018-10-05 17:51:14 +00:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_URL_PATH=/friendica'));
|
2018-08-27 04:15:55 +00:00
|
|
|
|
2018-10-31 10:57:51 +00:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-08-27 04:15:55 +00:00
|
|
|
|
2018-10-31 09:24:07 +00:00
|
|
|
$txt = $this->dumpExecute($console);
|
2018-10-31 09:16:15 +00:00
|
|
|
|
2018-10-31 09:24:07 +00:00
|
|
|
$this->assertFinished($txt, true);
|
2018-08-27 04:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
|
|
|
public function testWithArguments()
|
|
|
|
{
|
2018-10-31 09:16:15 +00:00
|
|
|
$this->mockConnect(true, 1);
|
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockExistsTable('user', false, 1);
|
2019-02-03 23:04:16 +00:00
|
|
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
2018-10-31 09:16:15 +00:00
|
|
|
|
2018-11-25 06:44:09 +00:00
|
|
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
2018-11-01 09:30:44 +00:00
|
|
|
$this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(true), '', 1);
|
|
|
|
|
2018-10-31 10:57:51 +00:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-10-31 09:16:15 +00:00
|
|
|
|
|
|
|
$console->setOption('dbhost', $this->db_host);
|
|
|
|
$console->setOption('dbuser', $this->db_user);
|
2018-08-27 04:15:55 +00:00
|
|
|
if (!empty($this->db_pass)) {
|
2018-10-31 09:16:15 +00:00
|
|
|
$console->setOption('dbpass', $this->db_pass);
|
2018-08-27 04:15:55 +00:00
|
|
|
}
|
|
|
|
if (!empty($this->db_port)) {
|
2018-10-31 09:16:15 +00:00
|
|
|
$console->setOption('dbport', $this->db_port);
|
2018-08-27 04:15:55 +00:00
|
|
|
}
|
2018-10-31 09:16:15 +00:00
|
|
|
$console->setOption('dbdata', $this->db_data);
|
2018-08-27 04:15:55 +00:00
|
|
|
|
2018-10-31 09:16:15 +00:00
|
|
|
$console->setOption('admin', 'admin@friendica.local');
|
|
|
|
$console->setOption('tz', 'Europe/Berlin');
|
|
|
|
$console->setOption('lang', 'de');
|
2018-08-27 04:15:55 +00:00
|
|
|
|
2018-10-31 09:16:15 +00:00
|
|
|
$console->setOption('urlpath', '/friendica');
|
2018-10-05 17:51:14 +00:00
|
|
|
|
2018-10-31 09:24:07 +00:00
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-27 04:15:55 +00:00
|
|
|
|
2018-10-31 09:24:07 +00:00
|
|
|
$this->assertFinished($txt, true);
|
2018-08-27 04:15:55 +00:00
|
|
|
}
|
|
|
|
|
2018-10-08 00:15:27 +00:00
|
|
|
/**
|
|
|
|
* @runTestsInSeparateProcesses
|
2018-10-22 18:59:51 +00:00
|
|
|
* @preserveGlobalState disabled
|
2018-10-08 00:15:27 +00:00
|
|
|
*/
|
2018-08-27 04:15:55 +00:00
|
|
|
public function testNoDatabaseConnection()
|
|
|
|
{
|
2018-10-31 09:16:15 +00:00
|
|
|
$this->mockConnect(false, 1);
|
2018-10-22 18:59:51 +00:00
|
|
|
|
2018-11-25 06:44:09 +00:00
|
|
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
2018-11-01 09:30:44 +00:00
|
|
|
$this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(false), '', 1);
|
|
|
|
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_LANG=de'));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_URL_PATH=/friendica'));
|
|
|
|
|
2018-10-31 10:57:51 +00:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-08-27 04:15:55 +00:00
|
|
|
|
2018-10-31 09:24:07 +00:00
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-27 04:15:55 +00:00
|
|
|
|
2018-10-31 09:24:07 +00:00
|
|
|
$this->assertStuckDB($txt);
|
2018-08-27 04:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetHelp()
|
|
|
|
{
|
|
|
|
// Usable to purposely fail if new commands are added without taking tests into account
|
|
|
|
$theHelp = <<<HELP
|
|
|
|
Installation - Install Friendica automatically
|
|
|
|
Synopsis
|
|
|
|
bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f]
|
|
|
|
|
|
|
|
Description
|
2018-11-25 06:44:09 +00:00
|
|
|
Installs Friendica with data based on the local.config.php file or environment variables
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
Notes
|
|
|
|
Not checking .htaccess/URL-Rewrite during CLI installation.
|
|
|
|
|
|
|
|
Options
|
2018-10-05 17:51:14 +00:00
|
|
|
-h|--help|-? Show help information
|
|
|
|
-v Show more debug information.
|
|
|
|
-a All setup checks are required (except .htaccess)
|
2018-11-25 06:44:09 +00:00
|
|
|
-f|--file <config> prepared config file (e.g. "config/local.config.php" itself) which will override every other config option - except the environment variables)
|
2018-10-05 17:51:14 +00:00
|
|
|
-s|--savedb Save the DB credentials to the file (if environment variables is used)
|
|
|
|
-H|--dbhost <host> The host of the mysql/mariadb database (env MYSQL_HOST)
|
|
|
|
-p|--dbport <port> The port of the mysql/mariadb database (env MYSQL_PORT)
|
|
|
|
-d|--dbdata <database> The name of the mysql/mariadb database (env MYSQL_DATABASE)
|
|
|
|
-U|--dbuser <username> The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME)
|
|
|
|
-P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
|
2018-10-08 00:15:27 +00:00
|
|
|
-u|--urlpath <url_path> The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH)
|
2018-10-05 17:51:14 +00:00
|
|
|
-b|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
|
|
|
|
-A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
|
|
|
|
-T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
|
|
|
|
-L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
Environment variables
|
|
|
|
MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used)
|
|
|
|
MYSQL_PORT The port of the mysql/mariadb database
|
|
|
|
MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb)
|
|
|
|
MYSQL_PASSWORD The password of the mysql/mariadb database login
|
|
|
|
MYSQL_DATABASE The name of the mysql/mariadb database
|
2018-10-05 17:51:14 +00:00
|
|
|
FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica')
|
2018-08-27 04:15:55 +00:00
|
|
|
FRIENDICA_PHP_PATH The path of the PHP binary
|
|
|
|
FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access)
|
|
|
|
FRIENDICA_TZ The timezone of Friendica
|
|
|
|
FRIENDICA_LANG The langauge of Friendica
|
|
|
|
|
|
|
|
Examples
|
2018-11-25 06:44:09 +00:00
|
|
|
bin/console autoinstall -f 'input.config.php
|
|
|
|
Installs Friendica with the prepared 'input.config.php' file
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
bin/console autoinstall --savedb
|
2018-11-25 06:44:09 +00:00
|
|
|
Installs Friendica with environment variables and saves them to the 'config/local.config.php' file
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica
|
|
|
|
Installs Friendica with a local mysql database with credentials
|
|
|
|
|
|
|
|
HELP;
|
|
|
|
|
2018-10-31 10:57:51 +00:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-10-31 09:16:15 +00:00
|
|
|
$console->setOption('help', true);
|
|
|
|
|
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-27 04:15:55 +00:00
|
|
|
|
|
|
|
$this->assertEquals($txt, $theHelp);
|
|
|
|
}
|
|
|
|
}
|