2018-08-27 06:15:55 +02:00
|
|
|
<?php
|
|
|
|
|
2019-05-02 23:17:35 +02:00
|
|
|
namespace Friendica\Test\src\Console;
|
2018-08-27 06:15:55 +02:00
|
|
|
|
2019-05-02 23:17:35 +02:00
|
|
|
use Friendica\Console\AutomaticInstallation;
|
2019-03-13 21:51:04 +01:00
|
|
|
use Friendica\Core\Config\Cache\ConfigCache;
|
2019-03-14 00:19:52 +01:00
|
|
|
use Friendica\Core\Installer;
|
2019-03-13 23:05:33 +01:00
|
|
|
use Friendica\Core\Logger;
|
2018-10-31 10:24:07 +01:00
|
|
|
use Friendica\Test\Util\DBAMockTrait;
|
2018-10-31 10:16:15 +01:00
|
|
|
use Friendica\Test\Util\DBStructureMockTrait;
|
2018-11-01 13:44:47 +01:00
|
|
|
use Friendica\Test\Util\L10nMockTrait;
|
2018-11-01 10:30:44 +01:00
|
|
|
use Friendica\Test\Util\RendererMockTrait;
|
2019-04-13 21:59:05 +02:00
|
|
|
use Friendica\Util\BaseURL;
|
2019-03-13 23:05:33 +01:00
|
|
|
use Friendica\Util\Logger\VoidLogger;
|
2018-08-27 06:15:55 +02:00
|
|
|
use org\bovigo\vfs\vfsStream;
|
2018-10-31 11:03:15 +01:00
|
|
|
use org\bovigo\vfs\vfsStreamFile;
|
2018-08-27 06:15:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @requires PHP 7.0
|
|
|
|
*/
|
|
|
|
class AutomaticInstallationConsoleTest extends ConsoleTest
|
|
|
|
{
|
2018-11-01 13:44:47 +01:00
|
|
|
use L10nMockTrait;
|
2018-10-31 10:24:07 +01:00
|
|
|
use DBAMockTrait;
|
2018-10-31 10:16:15 +01:00
|
|
|
use DBStructureMockTrait;
|
2018-11-01 10:30:44 +01:00
|
|
|
use RendererMockTrait;
|
2018-10-31 10:16:15 +01:00
|
|
|
|
2018-10-31 11:03:15 +01:00
|
|
|
/**
|
|
|
|
* @var vfsStreamFile Assert file without DB credentials
|
|
|
|
*/
|
2018-10-31 10:16:15 +01:00
|
|
|
private $assertFile;
|
2018-10-31 11:03:15 +01:00
|
|
|
/**
|
|
|
|
* @var vfsStreamFile Assert file with DB credentials
|
|
|
|
*/
|
2018-10-31 10:16:15 +01:00
|
|
|
private $assertFileDb;
|
|
|
|
|
2019-03-14 02:09:34 +01:00
|
|
|
/**
|
|
|
|
* @var ConfigCache The configuration cache to check after each test
|
|
|
|
*/
|
|
|
|
private $configCache;
|
|
|
|
|
2018-08-27 06:15:55 +02:00
|
|
|
public function setUp()
|
|
|
|
{
|
2019-07-10 22:33:26 +02:00
|
|
|
$this->markTestSkipped('Needs class \'Installer\' as constructing argument for console tests');
|
|
|
|
|
2018-08-27 06:15:55 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
|
2018-08-27 06:15:55 +02:00
|
|
|
$this->root->getChild('config')
|
2018-11-25 01:44:09 -05:00
|
|
|
->removeChild('local.config.php');
|
2018-08-27 06:15:55 +02:00
|
|
|
}
|
|
|
|
|
2018-11-01 13:44:47 +01:00
|
|
|
$this->mockL10nT();
|
2019-03-14 02:09:34 +01:00
|
|
|
|
|
|
|
$this->configCache = new ConfigCache();
|
|
|
|
$this->configCache->set('system', 'basepath', $this->root->url());
|
|
|
|
$this->configCache->set('config', 'php_path', trim(shell_exec('which php')));
|
2019-03-23 18:44:52 +01:00
|
|
|
$this->configCache->set('system', 'theme', 'smarty3');
|
2019-03-14 02:09:34 +01:00
|
|
|
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->mockApp($this->root, true);
|
2019-03-14 02:09:34 +01:00
|
|
|
|
|
|
|
$this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) {
|
|
|
|
if ($key !== 'basepath') {
|
|
|
|
return $this->configCache->set($cat, $key, $value);
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->configMock->shouldReceive('has')->andReturn(true);
|
|
|
|
$this->configMock->shouldReceive('get')->andReturnUsing(function ($cat, $key) {
|
|
|
|
return $this->configCache->get($cat, $key);
|
|
|
|
});
|
|
|
|
$this->configMock->shouldReceive('load')->andReturnUsing(function ($config, $overwrite = false) {
|
|
|
|
return $this->configCache->load($config, $overwrite);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->mode->shouldReceive('isInstall')->andReturn(true);
|
|
|
|
Logger::init(new VoidLogger());
|
2018-10-31 11:03:15 +01:00
|
|
|
}
|
|
|
|
|
2018-11-01 12:43:34 +01:00
|
|
|
/**
|
2019-03-14 00:19:52 +01:00
|
|
|
* Returns the dataset for each automatic installation test
|
2018-11-01 12:43:34 +01:00
|
|
|
*
|
2019-03-14 00:19:52 +01:00
|
|
|
* @return array the dataset
|
2018-11-01 12:43:34 +01:00
|
|
|
*/
|
2019-03-14 00:19:52 +01:00
|
|
|
public function dataInstaller()
|
2018-10-31 11:03:15 +01:00
|
|
|
{
|
2019-03-14 00:19:52 +01:00
|
|
|
return [
|
|
|
|
'empty' => [
|
|
|
|
'data' => [
|
|
|
|
'database' => [
|
|
|
|
'hostname' => '',
|
|
|
|
'username' => '',
|
|
|
|
'password' => '',
|
|
|
|
'database' => '',
|
|
|
|
'port' => '',
|
|
|
|
],
|
|
|
|
'config' => [
|
|
|
|
'php_path' => '',
|
2019-03-26 22:04:31 +01:00
|
|
|
'hostname' => 'friendica.local',
|
2019-03-14 00:19:52 +01:00
|
|
|
'admin_email' => '',
|
|
|
|
],
|
|
|
|
'system' => [
|
2019-03-26 22:04:31 +01:00
|
|
|
'basepath' => '',
|
2019-03-14 00:19:52 +01:00
|
|
|
'urlpath' => '',
|
2019-03-26 22:04:31 +01:00
|
|
|
'url' => 'http://friendica.local',
|
2019-04-13 21:59:05 +02:00
|
|
|
'ssl_policy' => 0,
|
2019-03-14 00:19:52 +01:00
|
|
|
'default_timezone' => '',
|
|
|
|
'language' => '',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'normal' => [
|
|
|
|
'data' => [
|
|
|
|
'database' => [
|
2019-03-14 02:09:34 +01:00
|
|
|
'hostname' => 'testhost',
|
|
|
|
'port' => 3306,
|
|
|
|
'username' => 'friendica',
|
|
|
|
'password' => 'a password',
|
|
|
|
'database' => 'database',
|
2019-03-14 00:19:52 +01:00
|
|
|
],
|
|
|
|
'config' => [
|
|
|
|
'php_path' => '',
|
2019-03-26 22:04:31 +01:00
|
|
|
'hostname' => 'friendica.local',
|
2019-03-14 00:19:52 +01:00
|
|
|
'admin_email' => 'admin@philipp.info',
|
|
|
|
],
|
|
|
|
'system' => [
|
|
|
|
'urlpath' => 'test/it',
|
2019-03-26 22:04:31 +01:00
|
|
|
'url' => 'http://friendica.local/test/it',
|
|
|
|
'basepath' => '',
|
|
|
|
'ssl_policy' => '2',
|
2019-03-14 00:19:52 +01:00
|
|
|
'default_timezone' => 'en',
|
|
|
|
'language' => 'Europe/Berlin',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2019-03-14 02:09:34 +01:00
|
|
|
'special' => [
|
|
|
|
'data' => [
|
|
|
|
'database' => [
|
|
|
|
'hostname' => 'testhost.new.domain',
|
|
|
|
'port' => 3341,
|
|
|
|
'username' => 'fr"§%ica',
|
|
|
|
'password' => '$%\"gse',
|
|
|
|
'database' => 'db',
|
|
|
|
],
|
|
|
|
'config' => [
|
|
|
|
'php_path' => '',
|
2019-03-26 22:04:31 +01:00
|
|
|
'hostname' => 'friendica.local',
|
2019-03-14 02:09:34 +01:00
|
|
|
'admin_email' => 'admin@philipp.info',
|
|
|
|
],
|
|
|
|
'system' => [
|
|
|
|
'urlpath' => 'test/it',
|
2019-03-26 22:04:31 +01:00
|
|
|
'url' => 'https://friendica.local/test/it',
|
|
|
|
'basepath' => '',
|
|
|
|
'ssl_policy' => '1',
|
2019-03-14 02:09:34 +01:00
|
|
|
'default_timezone' => 'en',
|
|
|
|
'language' => 'Europe/Berlin',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2018-11-01 10:30:44 +01:00
|
|
|
];
|
2018-08-27 06:15:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function assertFinished($txt, $withconfig = false, $copyfile = false)
|
|
|
|
{
|
|
|
|
$cfg = '';
|
|
|
|
|
|
|
|
if ($withconfig) {
|
|
|
|
$cfg = <<<CFG
|
|
|
|
|
|
|
|
|
|
|
|
Creating config file...
|
2018-10-30 11:30:19 +01:00
|
|
|
|
|
|
|
Complete!
|
2018-08-27 06:15:55 +02:00
|
|
|
CFG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($copyfile) {
|
|
|
|
$cfg = <<<CFG
|
|
|
|
|
|
|
|
|
|
|
|
Copying config file...
|
2018-10-30 11:30:19 +01:00
|
|
|
|
|
|
|
Complete!
|
2018-08-27 06:15:55 +02:00
|
|
|
CFG;
|
|
|
|
}
|
|
|
|
|
|
|
|
$finished = <<<FIN
|
2018-10-30 11:30:19 +01:00
|
|
|
Initializing setup...
|
2018-08-27 06:15:55 +02:00
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
2018-10-30 11:30:19 +01:00
|
|
|
Checking environment...
|
2018-08-27 06:15:55 +02:00
|
|
|
|
|
|
|
NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
|
|
|
|
|
|
|
|
Complete!
|
2018-10-30 11:30:19 +01:00
|
|
|
{$cfg}
|
2018-08-27 06:15:55 +02: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 10:16:15 +01:00
|
|
|
Checking environment...
|
2018-08-27 06:15:55 +02:00
|
|
|
|
|
|
|
NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
|
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
2018-10-31 10:16:15 +01:00
|
|
|
Creating config file...
|
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
2018-08-27 06:15:55 +02:00
|
|
|
Checking database...
|
|
|
|
|
|
|
|
[Error] --------
|
2018-10-31 12:37:01 +01:00
|
|
|
Could not connect to database.:
|
2018-08-27 06:15:55 +02:00
|
|
|
|
|
|
|
|
2019-03-26 22:04:31 +01:00
|
|
|
FIN;
|
|
|
|
|
|
|
|
$this->assertEquals($finished, $txt);
|
|
|
|
}
|
|
|
|
|
2019-04-13 21:59:05 +02:00
|
|
|
private function assertStuckURL($txt)
|
2019-03-26 22:04:31 +01:00
|
|
|
{
|
|
|
|
$finished = <<<FIN
|
|
|
|
Initializing setup...
|
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
|
|
|
Checking environment...
|
|
|
|
|
|
|
|
NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
|
|
|
|
|
|
|
|
Complete!
|
|
|
|
|
|
|
|
|
|
|
|
Creating config file...
|
|
|
|
|
2019-04-13 21:59:05 +02:00
|
|
|
The Friendica URL has to be set during CLI installation.
|
2019-03-26 22:04:31 +01:00
|
|
|
|
2018-08-27 06:15:55 +02:00
|
|
|
FIN;
|
|
|
|
|
|
|
|
$this->assertEquals($finished, $txt);
|
|
|
|
}
|
|
|
|
|
2019-03-11 22:46:00 +01:00
|
|
|
/**
|
2019-03-14 02:09:34 +01:00
|
|
|
* Asserts one config entry
|
|
|
|
*
|
|
|
|
* @param string $cat The category to test
|
|
|
|
* @param string $key The key to test
|
|
|
|
* @param null|array $assertion The asserted value (null = empty, or array/string)
|
|
|
|
* @param string $default_value The default value
|
2019-03-11 22:46:00 +01:00
|
|
|
*/
|
2019-03-14 02:09:34 +01:00
|
|
|
public function assertConfigEntry($cat, $key, $assertion = null, $default_value = null)
|
2019-03-11 22:46:00 +01:00
|
|
|
{
|
2019-03-14 02:09:34 +01:00
|
|
|
if (!empty($assertion[$cat][$key])) {
|
|
|
|
$this->assertEquals($assertion[$cat][$key], $this->configCache->get($cat, $key));
|
|
|
|
} elseif (!empty($assertion) && !is_array($assertion)) {
|
|
|
|
$this->assertEquals($assertion, $this->configCache->get($cat, $key));
|
|
|
|
} elseif (!empty($default_value)) {
|
|
|
|
$this->assertEquals($default_value, $this->configCache->get($cat, $key));
|
|
|
|
} else {
|
|
|
|
$this->assertEmpty($this->configCache->get($cat, $key), $this->configCache->get($cat, $key));
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 21:51:04 +01:00
|
|
|
|
2019-03-14 02:09:34 +01:00
|
|
|
/**
|
|
|
|
* Asserts all config entries
|
|
|
|
*
|
|
|
|
* @param null|array $assertion The optional assertion array
|
|
|
|
* @param boolean $saveDb True, if the db credentials should get saved to the file
|
|
|
|
* @param boolean $default True, if we use the default values
|
|
|
|
* @param boolean $defaultDb True, if we use the default value for the DB
|
2019-03-26 22:04:31 +01:00
|
|
|
* @param boolean $realBasepath True, if we use the real basepath of the installation, not the mocked one
|
2019-03-14 02:09:34 +01:00
|
|
|
*/
|
2019-03-26 22:04:31 +01:00
|
|
|
public function assertConfig($assertion = null, $saveDb = false, $default = true, $defaultDb = true, $realBasepath = false)
|
2019-03-14 02:09:34 +01:00
|
|
|
{
|
|
|
|
if (!empty($assertion['database']['hostname'])) {
|
|
|
|
$assertion['database']['hostname'] .= (!empty($assertion['database']['port']) ? ':' . $assertion['database']['port'] : '');
|
|
|
|
}
|
2019-03-13 23:05:33 +01:00
|
|
|
|
2019-03-14 02:09:34 +01:00
|
|
|
$this->assertConfigEntry('database', 'hostname', ($saveDb) ? $assertion : null, (!$saveDb || $defaultDb) ? Installer::DEFAULT_HOST : null);
|
|
|
|
$this->assertConfigEntry('database', 'username', ($saveDb) ? $assertion : null);
|
|
|
|
$this->assertConfigEntry('database', 'password', ($saveDb) ? $assertion : null);
|
|
|
|
$this->assertConfigEntry('database', 'database', ($saveDb) ? $assertion : null);
|
|
|
|
|
|
|
|
$this->assertConfigEntry('config', 'admin_email', $assertion);
|
|
|
|
$this->assertConfigEntry('config', 'php_path', trim(shell_exec('which php')));
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->assertConfigEntry('config', 'hostname', $assertion);
|
2019-03-13 21:51:04 +01:00
|
|
|
|
2019-03-14 02:09:34 +01:00
|
|
|
$this->assertConfigEntry('system', 'default_timezone', $assertion, ($default) ? Installer::DEFAULT_TZ : null);
|
|
|
|
$this->assertConfigEntry('system', 'language', $assertion, ($default) ? Installer::DEFAULT_LANG : null);
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->assertConfigEntry('system', 'url', $assertion);
|
|
|
|
$this->assertConfigEntry('system', 'urlpath', $assertion);
|
2019-04-13 21:59:05 +02:00
|
|
|
$this->assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? BaseURL::DEFAULT_SSL_SCHEME : null);
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->assertConfigEntry('system', 'basepath', ($realBasepath) ? $this->root->url() : $assertion);
|
2019-03-14 02:09:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the automatic installation without any parameter/setting
|
2019-03-26 22:04:31 +01:00
|
|
|
* Should stuck because of missing hostname
|
2019-03-14 02:09:34 +01:00
|
|
|
*/
|
|
|
|
public function testEmpty()
|
|
|
|
{
|
2019-03-26 22:04:31 +01:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
|
|
|
|
|
|
|
$txt = $this->dumpExecute($console);
|
|
|
|
|
2019-04-13 21:59:05 +02:00
|
|
|
$this->assertStuckURL($txt);
|
2019-03-26 22:04:31 +01:00
|
|
|
}
|
2019-03-14 10:00:05 +01:00
|
|
|
|
2019-03-26 22:04:31 +01:00
|
|
|
/**
|
|
|
|
* Test the automatic installation without any parameter/setting
|
2019-04-13 21:59:05 +02:00
|
|
|
* except URL
|
2019-03-26 22:04:31 +01:00
|
|
|
*/
|
2019-04-13 21:59:05 +02:00
|
|
|
public function testEmptyWithURL()
|
2019-03-26 22:04:31 +01:00
|
|
|
{
|
2019-03-11 22:46:00 +01: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-06-07 00:36:10 +02:00
|
|
|
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
|
2019-03-11 22:46:00 +01:00
|
|
|
|
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2019-04-13 21:59:05 +02:00
|
|
|
$console->setOption('url', 'http://friendica.local');
|
2019-03-11 22:46:00 +01:00
|
|
|
|
|
|
|
$txt = $this->dumpExecute($console);
|
|
|
|
|
2019-03-13 21:51:04 +01:00
|
|
|
$this->assertFinished($txt, true, false);
|
2019-03-13 23:05:33 +01:00
|
|
|
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
|
2019-03-14 00:19:52 +01:00
|
|
|
|
2019-04-13 21:59:05 +02:00
|
|
|
$this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local', 'ssl_policy' => 0, 'urlPath' => '']], false, true, true, true);
|
2019-03-11 22:46:00 +01:00
|
|
|
}
|
|
|
|
|
2018-08-27 06:15:55 +02:00
|
|
|
/**
|
2019-03-14 00:19:52 +01:00
|
|
|
* Test the automatic installation with a prepared config file
|
2019-03-13 21:51:04 +01:00
|
|
|
* @dataProvider dataInstaller
|
2018-08-27 06:15:55 +02:00
|
|
|
*/
|
2019-03-13 21:51:04 +01:00
|
|
|
public function testWithConfig(array $data)
|
2018-08-27 06:15:55 +02:00
|
|
|
{
|
2018-10-31 10:16:15 +01:00
|
|
|
$this->mockConnect(true, 1);
|
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockExistsTable('user', false, 1);
|
2019-02-04 00:04:16 +01:00
|
|
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
2018-10-31 10:16:15 +01:00
|
|
|
|
2019-03-14 02:09:34 +01:00
|
|
|
$conf = function ($cat, $key) use ($data) {
|
|
|
|
if ($cat == 'database' && $key == 'hostname' && !empty($data['database']['port'])) {
|
|
|
|
return $data[$cat][$key] . ':' . $data['database']['port'];
|
|
|
|
}
|
|
|
|
return $data[$cat][$key];
|
2019-03-13 23:05:33 +01:00
|
|
|
};
|
|
|
|
|
2018-08-27 06:15:55 +02:00
|
|
|
$config = <<<CONF
|
2018-11-25 01:44:09 -05:00
|
|
|
<?php
|
2018-08-27 06:15:55 +02:00
|
|
|
|
2018-11-25 01:44:09 -05: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-14 02:09:34 +01:00
|
|
|
'hostname' => '{$conf('database', 'hostname')}',
|
2019-03-13 23:05:33 +01:00
|
|
|
'username' => '{$conf('database', 'username')}',
|
|
|
|
'password' => '{$conf('database', 'password')}',
|
|
|
|
'database' => '{$conf('database', 'database')}',
|
2018-11-25 01:44:09 -05: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 23:05:33 +01:00
|
|
|
'admin_email' => '{$conf('config', 'admin_email')}',
|
2019-03-26 22:04:31 +01:00
|
|
|
'hostname' => '{$conf('config', 'hostname')}',
|
2018-11-25 01:44:09 -05:00
|
|
|
'sitename' => 'Friendica Social Network',
|
2018-12-27 20:56:15 -05:00
|
|
|
'register_policy' => \Friendica\Module\Register::OPEN,
|
2018-11-25 01:44:09 -05:00
|
|
|
'register_text' => '',
|
|
|
|
],
|
|
|
|
'system' => [
|
2019-03-26 22:04:31 +01:00
|
|
|
'basepath' => '{$conf('system', 'basepath')}',
|
2019-03-14 02:09:34 +01:00
|
|
|
'urlpath' => '{$conf('system', 'urlpath')}',
|
2019-03-26 22:04:31 +01:00
|
|
|
'url' => '{$conf('system', 'url')}',
|
|
|
|
'ssl_policy' => '{$conf('system', 'ssl_policy')}',
|
2019-03-13 23:05:33 +01:00
|
|
|
'default_timezone' => '{$conf('system', 'default_timezone')}',
|
|
|
|
'language' => '{$conf('system', 'language')}',
|
2018-11-25 01:44:09 -05:00
|
|
|
],
|
|
|
|
];
|
2018-08-27 06:15:55 +02:00
|
|
|
CONF;
|
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
vfsStream::newFile('prepared.config.php')
|
2018-08-27 06:15:55 +02:00
|
|
|
->at($this->root)
|
|
|
|
->setContent($config);
|
|
|
|
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-11-25 01:44:09 -05:00
|
|
|
$console->setOption('f', 'prepared.config.php');
|
2018-10-31 10:16:15 +01:00
|
|
|
|
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-27 06:15:55 +02:00
|
|
|
|
|
|
|
$this->assertFinished($txt, false, true);
|
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
|
2019-03-13 23:05:33 +01:00
|
|
|
$this->assertEquals($config, file_get_contents($this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')->url()));
|
2019-03-14 02:09:34 +01:00
|
|
|
|
2019-03-14 10:00:05 +01:00
|
|
|
$this->assertConfig($data, true, false, false);
|
2018-08-27 06:15:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-14 00:19:52 +01:00
|
|
|
* Test the automatic installation with environment variables
|
|
|
|
* Includes saving the DB credentials to the file
|
2019-03-13 23:05:33 +01:00
|
|
|
* @dataProvider dataInstaller
|
2018-08-27 06:15:55 +02:00
|
|
|
*/
|
2019-03-13 23:05:33 +01:00
|
|
|
public function testWithEnvironmentAndSave(array $data)
|
2018-08-27 06:15:55 +02:00
|
|
|
{
|
2018-10-31 10:16:15 +01:00
|
|
|
$this->mockConnect(true, 1);
|
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockExistsTable('user', false, 1);
|
2019-02-04 00:04:16 +01:00
|
|
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
2018-10-31 10:16:15 +01:00
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
2019-06-07 00:36:10 +02:00
|
|
|
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
|
2019-03-14 00:19:52 +01:00
|
|
|
|
|
|
|
$this->assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname']));
|
|
|
|
$this->assertTrue(putenv('MYSQL_PORT=' . $data['database']['port']));
|
|
|
|
$this->assertTrue(putenv('MYSQL_DATABASE=' . $data['database']['database']));
|
|
|
|
$this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
|
|
|
|
$this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
|
|
|
|
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname']));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath']));
|
2019-04-13 21:59:05 +02:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_URL=' . $data['system']['url']));
|
2019-03-14 00:19:52 +01:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path']));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone']));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language']));
|
2018-10-31 10:16:15 +01:00
|
|
|
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-10-31 10:16:15 +01:00
|
|
|
$console->setOption('savedb', true);
|
2018-08-27 06:15:55 +02:00
|
|
|
|
2018-10-31 10:16:15 +01:00
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-27 06:15:55 +02:00
|
|
|
|
|
|
|
$this->assertFinished($txt, true);
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->assertConfig($data, true, true, false, true);
|
2018-08-27 06:15:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-14 00:19:52 +01:00
|
|
|
* Test the automatic installation with environment variables
|
|
|
|
* Don't save the db credentials to the file
|
|
|
|
* @dataProvider dataInstaller
|
2018-08-27 06:15:55 +02:00
|
|
|
*/
|
2019-03-14 00:19:52 +01:00
|
|
|
public function testWithEnvironmentWithoutSave(array $data)
|
2018-08-27 06:15:55 +02:00
|
|
|
{
|
2018-10-31 10:16:15 +01:00
|
|
|
$this->mockConnect(true, 1);
|
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockExistsTable('user', false, 1);
|
2019-02-04 00:04:16 +01:00
|
|
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
2018-10-31 10:16:15 +01:00
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
2019-06-07 00:36:10 +02:00
|
|
|
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
|
2019-03-14 00:19:52 +01:00
|
|
|
|
|
|
|
$this->assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname']));
|
|
|
|
$this->assertTrue(putenv('MYSQL_PORT=' . $data['database']['port']));
|
|
|
|
$this->assertTrue(putenv('MYSQL_DATABASE=' . $data['database']['database']));
|
|
|
|
$this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
|
|
|
|
$this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
|
|
|
|
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname']));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath']));
|
2019-04-13 21:59:05 +02:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_URL=' . $data['system']['url']));
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path']));
|
2019-03-14 00:19:52 +01:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone']));
|
|
|
|
$this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language']));
|
2018-08-27 06:15:55 +02:00
|
|
|
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-08-27 06:15:55 +02:00
|
|
|
|
2018-10-31 10:24:07 +01:00
|
|
|
$txt = $this->dumpExecute($console);
|
2018-10-31 10:16:15 +01:00
|
|
|
|
2018-10-31 10:24:07 +01:00
|
|
|
$this->assertFinished($txt, true);
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->assertConfig($data, false, true, false, true);
|
2018-08-27 06:15:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-14 00:19:52 +01:00
|
|
|
* Test the automatic installation with arguments
|
|
|
|
* @dataProvider dataInstaller
|
2018-08-27 06:15:55 +02:00
|
|
|
*/
|
2019-03-14 00:19:52 +01:00
|
|
|
public function testWithArguments(array $data)
|
2018-08-27 06:15:55 +02:00
|
|
|
{
|
2018-10-31 10:16:15 +01:00
|
|
|
$this->mockConnect(true, 1);
|
|
|
|
$this->mockConnected(true, 1);
|
|
|
|
$this->mockExistsTable('user', false, 1);
|
2019-02-04 00:04:16 +01:00
|
|
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
2018-10-31 10:16:15 +01:00
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
2019-06-07 00:36:10 +02:00
|
|
|
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
|
2018-11-01 10:30:44 +01:00
|
|
|
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-10-31 10:16:15 +01:00
|
|
|
|
2019-03-14 02:09:34 +01:00
|
|
|
$option = function($var, $cat, $key) use ($data, $console) {
|
|
|
|
if (!empty($data[$cat][$key])) {
|
|
|
|
$console->setOption($var, $data[$cat][$key]);
|
|
|
|
}
|
|
|
|
};
|
2019-03-26 22:04:31 +01:00
|
|
|
$option('dbhost' , 'database', 'hostname');
|
|
|
|
$option('dbport' , 'database', 'port');
|
|
|
|
$option('dbuser' , 'database', 'username');
|
|
|
|
$option('dbpass' , 'database', 'password');
|
|
|
|
$option('dbdata' , 'database', 'database');
|
2019-04-13 21:59:05 +02:00
|
|
|
$option('url' , 'system' , 'url');
|
2019-03-26 22:04:31 +01:00
|
|
|
$option('phppath' , 'config' , 'php_path');
|
|
|
|
$option('admin' , 'config' , 'admin_email');
|
|
|
|
$option('tz' , 'system' , 'default_timezone');
|
|
|
|
$option('lang' , 'system' , 'language');
|
|
|
|
$option('basepath' , 'system' , 'basepath');
|
2018-10-05 19:51:14 +02:00
|
|
|
|
2018-10-31 10:24:07 +01:00
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-27 06:15:55 +02:00
|
|
|
|
2018-10-31 10:24:07 +01:00
|
|
|
$this->assertFinished($txt, true);
|
2019-03-26 22:04:31 +01:00
|
|
|
$this->assertConfig($data, true, true, true, true);
|
2018-08-27 06:15:55 +02:00
|
|
|
}
|
|
|
|
|
2018-10-08 02:15:27 +02:00
|
|
|
/**
|
2019-03-14 00:24:08 +01:00
|
|
|
* Test the automatic installation with a wrong database connection
|
2018-10-08 02:15:27 +02:00
|
|
|
*/
|
2018-08-27 06:15:55 +02:00
|
|
|
public function testNoDatabaseConnection()
|
|
|
|
{
|
2018-10-31 10:16:15 +01:00
|
|
|
$this->mockConnect(false, 1);
|
2018-10-22 20:59:51 +02:00
|
|
|
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
2019-06-07 00:36:10 +02:00
|
|
|
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
|
2018-11-01 10:30:44 +01:00
|
|
|
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2019-04-13 21:59:05 +02:00
|
|
|
$console->setOption('url', 'http://friendica.local');
|
2018-08-27 06:15:55 +02:00
|
|
|
|
2018-10-31 10:24:07 +01:00
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-27 06:15:55 +02:00
|
|
|
|
2018-10-31 10:24:07 +01:00
|
|
|
$this->assertStuckDB($txt);
|
2019-03-14 00:24:08 +01:00
|
|
|
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
|
|
|
|
|
2019-04-13 21:59:05 +02:00
|
|
|
$this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local', 'ssl_policy' => 0, 'urlpath' => '']], false, true, false, true);
|
2018-08-27 06:15:55 +02: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 01:44:09 -05:00
|
|
|
Installs Friendica with data based on the local.config.php file or environment variables
|
2018-08-27 06:15:55 +02:00
|
|
|
|
|
|
|
Notes
|
|
|
|
Not checking .htaccess/URL-Rewrite during CLI installation.
|
|
|
|
|
|
|
|
Options
|
2018-10-05 19:51:14 +02:00
|
|
|
-h|--help|-? Show help information
|
|
|
|
-v Show more debug information.
|
|
|
|
-a All setup checks are required (except .htaccess)
|
2018-11-25 01:44:09 -05: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)
|
2019-04-13 22:47:47 +02: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)
|
|
|
|
-U|--url <url> The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL)
|
|
|
|
-B|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
|
2019-04-14 14:05:48 +02:00
|
|
|
-b|--basepath <base_path> The basepath of Friendica (env FRIENDICA_BASE_PATH)
|
2019-04-13 22:47:47 +02:00
|
|
|
-t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
|
|
|
|
-L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
|
2018-08-27 06:15:55 +02: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
|
2019-04-13 21:59:05 +02:00
|
|
|
FRIENDICA_URL The full base URL of Friendica - f.e. 'https://friendica.local/sub'
|
2019-03-26 22:04:31 +01:00
|
|
|
FRIENDICA_PHP_PATH The path of the PHP binary - leave empty for auto detection
|
|
|
|
FRIENDICA_BASE_PATH The basepath of Friendica - leave empty for auto detection
|
2018-08-27 06:15:55 +02:00
|
|
|
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 01:44:09 -05:00
|
|
|
bin/console autoinstall -f 'input.config.php
|
|
|
|
Installs Friendica with the prepared 'input.config.php' file
|
2018-08-27 06:15:55 +02:00
|
|
|
|
|
|
|
bin/console autoinstall --savedb
|
2018-11-25 01:44:09 -05:00
|
|
|
Installs Friendica with environment variables and saves them to the 'config/local.config.php' file
|
2018-08-27 06:15:55 +02: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 11:57:51 +01:00
|
|
|
$console = new AutomaticInstallation($this->consoleArgv);
|
2018-10-31 10:16:15 +01:00
|
|
|
$console->setOption('help', true);
|
|
|
|
|
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-27 06:15:55 +02:00
|
|
|
|
2019-03-14 10:00:05 +01:00
|
|
|
$this->assertEquals($theHelp, $txt);
|
2018-08-27 06:15:55 +02:00
|
|
|
}
|
|
|
|
}
|