From 4f01a198e18368e81fb86eaba82b7e950799e871 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Thu, 1 Nov 2018 10:30:44 +0100 Subject: [PATCH] AutoInstall Test fix - New Mock for Renderer - No need of prepared assert.ini.php anymore - Mocking Renderer during Autoinstall --- tests/Util/AppMockTrait.php | 16 ---- tests/Util/RendererMockTrait.php | 46 +++++++++++ tests/datasets/ini/assert.ini.php | 56 ------------- .../AutomaticInstallationConsoleTest.php | 81 ++++++++----------- 4 files changed, 79 insertions(+), 120 deletions(-) create mode 100644 tests/Util/RendererMockTrait.php delete mode 100644 tests/datasets/ini/assert.ini.php diff --git a/tests/Util/AppMockTrait.php b/tests/Util/AppMockTrait.php index 72c0dc429b..4fd340fbed 100644 --- a/tests/Util/AppMockTrait.php +++ b/tests/Util/AppMockTrait.php @@ -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); } } diff --git a/tests/Util/RendererMockTrait.php b/tests/Util/RendererMockTrait.php new file mode 100644 index 0000000000..1fe3bd97dc --- /dev/null +++ b/tests/Util/RendererMockTrait.php @@ -0,0 +1,46 @@ +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); + } +} diff --git a/tests/datasets/ini/assert.ini.php b/tests/datasets/ini/assert.ini.php deleted file mode 100644 index 39828affcb..0000000000 --- a/tests/datasets/ini/assert.ini.php +++ /dev/null @@ -1,56 +0,0 @@ -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); -- 2.39.5