@ -2,6 +2,8 @@
namespace Friendica\Test\src\Core\Console;
use Friendica\Core\Console\AutomaticInstallation;
use Friendica\Test\Util\DBStructureMockTrait;
use org\bovigo\vfs\vfsStream;
/**
@ -11,12 +13,17 @@ use org\bovigo\vfs\vfsStream;
*/
class AutomaticInstallationConsoleTest extends ConsoleTest
{
use DBStructureMockTrait;
private $db_host;
private $db_port;
private $db_data;
private $db_user;
private $db_pass;
private $assertFile;
private $assertFileDb;
public function setUp()
{
parent::setUp();
@ -32,19 +39,20 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
$this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
$this->db_pass = getenv('MYSQL_PASSWORD');
// Mocking 'DBStructure::existsTable()' because with CI, we cannot create an empty database
// therefore we temporary override the existing database
/// @todo Mocking the DB-Calls of ConsoleTest so we don't need this specific mock anymore
$existsMock = \Mockery::mock('alias:Friendica\Database\DBStructure');
$existsMock->shouldReceive('existsTable')
->with('user')
->andReturn(false);
}
private function assertConfig($family, $key, $value)
{
$config = $this->execute(['config', $family, $key]);
$this->assertEquals($family . "." . $key . " => " . $value . "\n", $config);
$this->mockConfigGet('config', 'php_path', false);
$this->assertFile = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'ini' . DIRECTORY_SEPARATOR .
'assert.ini.php';
$this->assertFileDb = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'ini' . DIRECTORY_SEPARATOR .
'assert_db.ini.php';
}
private function assertFinished($txt, $withconfig = false, $copyfile = false)
@ -113,22 +121,25 @@ FIN;
$finished = < < < FIN
Initializing setup...
Creating config file...
Complete!
Checking basic setup ...
Checking environment ...
NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
Complete!
Creating config file...
Complete!
Checking database...
[Error] --------
MySQL Connection: Failed, please check your MySQL settings and credentials.
:
FIN;
@ -141,6 +152,11 @@ FIN;
*/
public function testWithConfig()
{
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([false, true, true], null, 1);
$config = < < < CONF
<?php return <<< INI
@ -179,7 +195,10 @@ CONF;
->at($this->root)
->setContent($config);
$txt = $this->execute(['autoinstall', '-f', 'prepared.ini.php']);
$console = new AutomaticInstallation();
$console->setOption('f', 'prepared.ini.php');
$txt = $this->dumpExecute($console);
$this->assertFinished($txt, false, true);
@ -191,23 +210,28 @@ CONF;
*/
public function testWithEnvironmentAndSave()
{
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([false, true, true], null, 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'));
$console = new AutomaticInstallation();
$console->setOption('savedb', true);
$txt = $this->execute(['autoinstall', '--savedb']);
$txt = $this->dumpExecute($console );
$this->assertFinished($txt, true);
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
$this->assertConfig('database', 'hostname', $this->db_host . (!empty($this->db_port) ? ':' . $this->db_port : ''));
$this->assertConfig('database', 'username', $this->db_user);
$this->assertConfig('database', 'database', $this->db_data);
$this->assertConfig('config', 'admin_email', 'admin@friendica.local');
$this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
// TODO language changes back to en
//$this->assertConfig('system', 'language', 'de');
$this->assertFileEquals(
$this->assertFileDb,
$this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
}
/**
@ -215,25 +239,27 @@ CONF;
*/
public function testWithEnvironmentWithoutSave()
{
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([false, true, true], null, 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'));
$txt = $this->execute(['autoinstall'] );
$console = new AutomaticInstallation( );
$this->assertFinished($txt, true);
$returnStr = $this->dumpExecute($console);
$this->assertFinished($returnStr, true);
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
$this->assertConfig('database', 'hostname', '');
$this->assertConfig('database', 'username', '');
$this->assertConfig('database', 'database', '');
$this->assertConfig('config', 'admin_email', 'admin@friendica.local');
$this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
$this->assertConfig('system', 'urlpath', '/friendica');
// TODO language changes back to en
//$this->assertConfig('system', 'language', 'de');
$this->assertFileEquals(
$this->assertFile,
$this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
}
/**
@ -241,46 +267,38 @@ CONF;
*/
public function testWithArguments()
{
$args = ['autoinstall'];
array_push($args, '--dbhost');
array_push($args, $this->db_host);
array_push($args, '--dbuser');
array_push($args, $this->db_user);
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([false, true, true], null, 1);
$console = new AutomaticInstallation();
$console->setOption('dbhost', $this->db_host);
$console->setOption('dbuser', $this->db_user);
if (!empty($this->db_pass)) {
array_push($args, '--dbpass');
array_push($args, $this->db_pass);
$console->setOption('dbpass', $this->db_pass);
}
if (!empty($this->db_port)) {
array_push($args, '--dbport');
array_push($args, $this->db_port);
$console->setOption('dbport', $this->db_port);
}
array_push($args, '--dbdata');
array_push($args, $this->db_data);
$console->setOption('dbdata', $this->db_data);
array_push($args, '--admin');
array_push($args, 'admin@friendica.local');
array_push($args, '--tz');
array_push($args, 'Europe/Berlin');
array_push($args, '--lang');
array_push($args, 'de');
$console->setOption('admin', 'admin@friendica.local');
$console->setOption('tz', 'Europe/Berlin');
$console->setOption('lang', 'de');
array_push($args, '--urlpath');
array_push($args, '/friendica');
$console->setOption('urlpath', '/friendica');
$txt = $this->execute($args );
$returnStr = $this->dumpExecute($console );
$this->assertFinished($txt , true);
$this->assertFinished($returnStr , true);
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
$this->assertConfig('database', 'hostname', $this->db_host . (!empty($this->db_port) ? ':' . $this->db_port : ''));
$this->assertConfig('database', 'username', $this->db_user);
$this->assertConfig('database', 'database', $this->db_data);
$this->assertConfig('config', 'admin_email', 'admin@friendica.local');
$this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
$this->assertConfig('system', 'urlpath', '/friendica');
// TODO language changes back to en
//$this->assertConfig('system', 'language', 'de');
$this->assertFileEquals(
$this->assertFileDb,
$this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
}
/**
@ -289,17 +307,13 @@ CONF;
*/
public function testNoDatabaseConnection()
{
// TODO DBA mocking for whole console tests make this test work again
$this->markTestSkipped('DBA is already loaded, we have to mock the whole App to make it work');
$this->mockConnect(false, 1);
$dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
$dbaMock
->shouldReceive('connected')
->andReturn(false);
$console = new AutomaticInstallation();
$txt = $this->execute(['autoinstall'] );
$returnStr = $this->dumpExecute($console);
$this->assertStuckDB($txt );
$this->assertStuckDB($returnStr );
}
public function testGetHelp()
@ -357,7 +371,10 @@ Examples
HELP;
$txt = $this->execute(['autoinstall', '-h']);
$console = new AutomaticInstallation();
$console->setOption('help', true);
$txt = $this->dumpExecute($console);
$this->assertEquals($txt, $theHelp);
}