1
0
Fork 0

Merge pull request #6061 from nupplaphil/autoinstall_test_fix

AutoInstall Test fix
This commit is contained in:
Hypolite Petovan 2018-11-01 07:41:19 -04:00 committed by GitHub
commit 0ccdc2ec0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 120 deletions

View file

@ -62,14 +62,6 @@ trait AppMockTrait
$this->app
->shouldReceive('getCurrentTheme')
->andReturn('Smarty3');
$this->app
->shouldReceive('getTemplateLeftDelimiter')
->with('smarty3')
->andReturn('{{');
$this->app
->shouldReceive('getTemplateRightDelimiter')
->with('smarty3')
->andReturn('}}');
$this->app
->shouldReceive('saveTimestamp')
->andReturn(true);
@ -77,14 +69,6 @@ trait AppMockTrait
->shouldReceive('getBaseUrl')
->andReturn('http://friendica.local');
// Mocking the Theme
// Necessary for macro engine with template files
$themeMock = \Mockery::mock('alias:Friendica\Core\Theme');
$themeMock
->shouldReceive('install')
->with('testtheme')
->andReturn(true);
BaseObject::setApp($this->app);
}
}

View file

@ -0,0 +1,46 @@
<?php
/**
* Created by PhpStorm.
* User: philipp
* Date: 01.11.18
* Time: 10:08
*/
namespace Friendica\Test\Util;
use Mockery\MockInterface;
trait RendererMockTrait
{
/**
* @var MockInterface The Interface for mocking a renderer
*/
private $rendererMock;
public function mockGetMarkupTemplate($templateName, $return = '', $times = null)
{
if (!isset($this->rendererMock)) {
$this->rendererMock = \Mockery::mock('alias:Friendica\Core\Renderer');
}
$this->rendererMock
->shouldReceive('getMarkupTemplate')
->with($templateName)
->times($times)
->andReturn($return);
}
public function mockReplaceMacros($template, $args = [], $return = '', $times = null)
{
if (!isset($this->rendererMock)) {
$this->rendererMock = \Mockery::mock('alias:Friendica\Core\Renderer');
}
$this->rendererMock
->shouldReceive('replaceMacros')
->with($template, $args)
->times($times)
->andReturn($return);
}
}

View file

@ -1,56 +0,0 @@
<?php return <<<INI
; If you're unsure about what any of the config keys below do, please check the config/defaults.ini.php for detailed
; documentation of their data type and behavior.
[database]
hostname = ""
username = ""
password = ""
database = ""
charset = utf8mb4
; ****************************************************************
; Some config values below can be overruled from the admin settings
; ****************************************************************
[config]
php_path = "/usr/bin/php"
admin_email = "admin@friendica.local"
sitename = Friendica Social Network
register_policy = REGISTER_OPEN
register_text =
max_import_size = 200000
[system]
urlpath = "/friendica"
default_timezone = "Europe/Berlin"
language = "de"
allowed_themes = vier,quattro,duepuntozero,smoothly,frio
theme = vier
allowed_link_protocols[0] = ftp
allowed_link_protocols[1] = ftps
allowed_link_protocols[2] = mailto
allowed_link_protocols[3] = cid
allowed_link_protocols[4] = gopher
maximagesize = 800000
no_regfullname = true
block_local_dir = false
directory = https://dir.friendica.social
auth_cookie_lifetime = 7
INI;
// Keep this line

View file

@ -5,6 +5,7 @@ namespace Friendica\Test\src\Core\Console;
use Friendica\Core\Console\AutomaticInstallation;
use Friendica\Test\Util\DBAMockTrait;
use Friendica\Test\Util\DBStructureMockTrait;
use Friendica\Test\Util\RendererMockTrait;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamFile;
@ -17,6 +18,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
{
use DBAMockTrait;
use DBStructureMockTrait;
use RendererMockTrait;
private $db_host;
private $db_port;
@ -49,39 +51,23 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
$this->db_pass = getenv('MYSQL_PASSWORD');
$this->mockConfigGet('config', 'php_path', false);
$assertFile = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'ini' . DIRECTORY_SEPARATOR .
'assert.ini.php';
$this->assertFile = vfsStream::newFile('assert.ini.php')
->at($this->root->getChild('test'))
->setContent($this->replaceEnvironmentSettings($assertFile, false));
$this->assertFileDb = vfsStream::newFile('assert_db.ini.php')
->at($this->root->getChild('test'))
->setContent($this->replaceEnvironmentSettings($assertFile, true));
}
/**
* Replacing environment specific variables in the assertion file
*
* @param string $file The file to compare in later tests
* @param bool $withDb If true, db settings are replaced too
* @return string The file content
*/
private function replaceEnvironmentSettings($file, $withDb)
private function createArgumentsForMacro($withDb)
{
$fileContent = file_get_contents($file);
$fileContent = str_replace("/usr/bin/php", trim(shell_exec('which php')), $fileContent);
if ($withDb) {
$fileContent = str_replace("hostname = \"\"", "hostname = \"" . $this->db_host . (!empty($this->db_port) ? ":" . $this->db_port : "") . "\"", $fileContent);
$fileContent = str_replace("username = \"\"", "username = \"" . $this->db_user . "\"", $fileContent);
$fileContent = str_replace("password = \"\"", "password = \"" . $this->db_pass . "\"", $fileContent);
$fileContent = str_replace("database = \"\"", "database = \"" . $this->db_data . "\"", $fileContent);
}
return $fileContent;
$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' => 'Europe/Berlin',
'$language' => 'de',
'$urlpath' => '/friendica',
'$adminmail' => 'admin@friendica.local'
];
return $args;
}
private function assertFinished($txt, $withconfig = false, $copyfile = false)
@ -244,6 +230,9 @@ CONF;
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([false, true, true], null, 1);
$this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1);
$this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(true), '', 1);
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
$this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
$this->assertTrue(putenv('FRIENDICA_LANG=de'));
@ -255,12 +244,6 @@ CONF;
$txt = $this->dumpExecute($console);
$this->assertFinished($txt, true);
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
$this->assertFileEquals(
$this->assertFileDb->url(),
$this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
}
/**
@ -273,6 +256,9 @@ CONF;
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([false, true, true], null, 1);
$this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1);
$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'));
@ -283,12 +269,6 @@ CONF;
$txt = $this->dumpExecute($console);
$this->assertFinished($txt, true);
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
$this->assertFileEquals(
$this->assertFile->url(),
$this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
}
/**
@ -301,6 +281,9 @@ CONF;
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([false, true, true], null, 1);
$this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1);
$this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(true), '', 1);
$console = new AutomaticInstallation($this->consoleArgv);
$console->setOption('dbhost', $this->db_host);
@ -322,12 +305,6 @@ CONF;
$txt = $this->dumpExecute($console);
$this->assertFinished($txt, true);
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
$this->assertFileEquals(
$this->assertFileDb->url(),
$this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
}
/**
@ -338,6 +315,14 @@ CONF;
{
$this->mockConnect(false, 1);
$this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1);
$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'));
$console = new AutomaticInstallation($this->consoleArgv);
$txt = $this->dumpExecute($console);