From acd5060ec20587dfa88446424912fb6f483167d1 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 11 Mar 2019 22:46:00 +0100 Subject: [PATCH] Fixed ConsoleTest --- tests/Util/AppMockTrait.php | 10 ++++ .../AutomaticInstallationConsoleTest.php | 50 ++++++++++++++++++- tests/src/Core/Console/ConsoleTest.php | 1 + 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/tests/Util/AppMockTrait.php b/tests/Util/AppMockTrait.php index 817570dd58..f8d1540346 100644 --- a/tests/Util/AppMockTrait.php +++ b/tests/Util/AppMockTrait.php @@ -30,6 +30,11 @@ trait AppMockTrait */ protected $profilerMock; + /** + * @var MockInterface|App\Mode The mocked App mode + */ + protected $mode; + /** * Mock the App * @@ -38,6 +43,7 @@ trait AppMockTrait public function mockApp($root) { $this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class); + $this->mode = \Mockery::mock(App\Mode::class); $configAdapterMock = \Mockery::mock(Config\Adapter\IConfigAdapter::class); // Disable the adapter $configAdapterMock->shouldReceive('isConnected')->andReturn(false); @@ -52,6 +58,10 @@ trait AppMockTrait ->shouldReceive('getBasePath') ->andReturn($root->url()); + $this->app + ->shouldReceive('getMode') + ->andReturn($this->mode); + $this->configMock ->shouldReceive('has') ->andReturn(true); diff --git a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php index 73b6835fb5..f806e6d7bb 100644 --- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php @@ -3,6 +3,7 @@ namespace Friendica\Test\src\Core\Console; use Friendica\Core\Console\AutomaticInstallation; +use Friendica\Core\Installer; use Friendica\Test\Util\DBAMockTrait; use Friendica\Test\Util\DBStructureMockTrait; use Friendica\Test\Util\L10nMockTrait; @@ -55,6 +56,19 @@ class AutomaticInstallationConsoleTest extends ConsoleTest $this->configMock ->shouldReceive('get') ->with('config', 'php_path') + ->andReturn(null); + + $this->configMock->shouldReceive('set') + ->with('config', 'php_path', \Mockery::any())->once(); + $this->configMock->shouldReceive('set') + ->with('config', 'hostname', '')->once(); + $this->configMock->shouldReceive('set') + ->with('system', 'basepath', \Mockery::any())->once(); + $this->configMock->shouldReceive('set') + ->with('system', 'urlpath' , '')->once(); + $this->configMock->shouldReceive('set') + ->with('system', 'ssl_policy', SSL_POLICY_NONE)->once(); + $this->mode->shouldReceive('isInstall') ->andReturn(false); $this->mockL10nT(); @@ -75,9 +89,11 @@ class AutomaticInstallationConsoleTest extends ConsoleTest '$dbuser' => (($withDb) ? $this->db_user : ''), '$dbpass' => (($withDb) ? $this->db_pass : ''), '$dbdata' => (($withDb) ? $this->db_data : ''), - '$timezone' => 'Europe/Berlin', - '$language' => 'de', + '$timezone' => Installer::DEFAULT_TZ, + '$language' => Installer::DEFAULT_LANG, '$urlpath' => '/friendica', + '$basepath' => '/test', + '$hostname' => 'friendica.local', '$adminmail' => 'admin@friendica.local' ]; @@ -176,6 +192,36 @@ FIN; $this->assertEquals($finished, $txt); } + /** + * Test the automatic installation without any parameter + */ + public function testEmpty() + { + $this->mockConnect(true, 1); + $this->mockConnected(true, 1); + $this->mockExistsTable('user', false, 1); + $this->mockUpdate([$this->root->url(), false, true, true], null, 1); + + $this->configMock->shouldReceive('set') + ->with('database', 'hostname', Installer::DEFAULT_HOST)->once(); + $this->configMock->shouldReceive('set') + ->with('database', 'username', '')->once(); + $this->configMock->shouldReceive('set') + ->with('database', 'password', '')->once(); + $this->configMock->shouldReceive('set') + ->with('database', 'database', '')->once(); + + $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); + $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + + $console = new AutomaticInstallation($this->consoleArgv); + + $txt = $this->dumpExecute($console); + + $this->assertFinished($txt, false, true); + + } + /** * @medium */ diff --git a/tests/src/Core/Console/ConsoleTest.php b/tests/src/Core/Console/ConsoleTest.php index 4f7acc9c42..bd821614f2 100644 --- a/tests/src/Core/Console/ConsoleTest.php +++ b/tests/src/Core/Console/ConsoleTest.php @@ -30,6 +30,7 @@ abstract class ConsoleTest extends MockedTest $this->setUpVfsDir(); $this->mockApp($this->root); + } /**