]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Console/AutomaticInstallationConsoleTest.php
Merge pull request #9963 from mexon/mat/support-cid-scheme
[friendica.git] / tests / src / Console / AutomaticInstallationConsoleTest.php
index 596c9a7d36768e46d21927bc610498916f9d3d58..fdf887fe6b6975e92110cc327a2c4548bc39723e 100644 (file)
@@ -1,25 +1,48 @@
 <?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Test\src\Console;
 
+use Dice\Dice;
+use Friendica\App;
 use Friendica\Console\AutomaticInstallation;
-use Friendica\Core\Config\Cache\ConfigCache;
+use Friendica\Core\Config\Cache;
 use Friendica\Core\Installer;
-use Friendica\Core\L10n\L10n;
+use Friendica\Core\L10n;
 use Friendica\Core\Logger;
+use Friendica\Database\Database;
+use Friendica\DI;
 use Friendica\Test\Util\DBAMockTrait;
 use Friendica\Test\Util\DBStructureMockTrait;
 use Friendica\Test\Util\RendererMockTrait;
-use Friendica\Util\BaseURL;
+use Friendica\Test\Util\VFSTrait;
 use Friendica\Util\Logger\VoidLogger;
+use Mockery;
+use Mockery\MockInterface;
 use org\bovigo\vfs\vfsStream;
 use org\bovigo\vfs\vfsStreamFile;
 
-/**
- * @requires PHP 7.0
- */
 class AutomaticInstallationConsoleTest extends ConsoleTest
 {
+       use VFSTrait;
        use DBAMockTrait;
        use DBStructureMockTrait;
        use RendererMockTrait;
@@ -34,32 +57,53 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
        private $assertFileDb;
 
        /**
-        * @var ConfigCache The configuration cache to check after each test
+        * @var Cache The configuration cache to check after each test
         */
        private $configCache;
 
+       /**
+        * @var App\Mode
+        */
+       private $appMode;
+
+       /**
+        * @var Database
+        */
+       private $dba;
+
+       /**
+        * @var Dice|MockInterface
+        */
+       private $dice;
+
        public function setUp()
        {
-               $this->markTestSkipped('Needs class \'Installer\' as constructing argument for console tests');
+               static::markTestSkipped('Needs class \'Installer\' as constructing argument for console tests');
 
                parent::setUp();
 
+               $this->setUpVfsDir();;
+
                if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
                        $this->root->getChild('config')
                                ->removeChild('local.config.php');
                }
+               $this->dice = Mockery::mock(Dice::class)->makePartial();
 
-               $l10nMock = \Mockery::mock(L10n::class);
+               $l10nMock = Mockery::mock(L10n::class);
                $l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
-               \Friendica\Core\L10n::init($l10nMock);
 
-               $this->configCache = new ConfigCache();
+               $this->dice->shouldReceive('create')
+                          ->with(L10n::class)
+                          ->andReturn($l10nMock);
+
+               DI::init($this->dice);
+
+               $this->configCache = new Cache();
                $this->configCache->set('system', 'basepath', $this->root->url());
                $this->configCache->set('config', 'php_path', trim(shell_exec('which php')));
                $this->configCache->set('system', 'theme', 'smarty3');
 
-               $this->mockApp($this->root, true);
-
                $this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) {
                        if ($key !== 'basepath') {
                                return $this->configCache->set($cat, $key, $value);
@@ -221,7 +265,7 @@ Installation is finished
 
 
 FIN;
-               $this->assertEquals($finished, $txt);
+               self::assertEquals($finished, $txt);
        }
 
        private function assertStuckDB($txt)
@@ -252,7 +296,7 @@ Could not connect to database.:
 
 FIN;
 
-               $this->assertEquals($finished, $txt);
+               self::assertEquals($finished, $txt);
        }
 
        private function assertStuckURL($txt)
@@ -276,7 +320,7 @@ The Friendica URL has to be set during CLI installation.
 
 FIN;
 
-               $this->assertEquals($finished, $txt);
+               self::assertEquals($finished, $txt);
        }
 
        /**
@@ -290,13 +334,13 @@ FIN;
        public function assertConfigEntry($cat, $key, $assertion = null, $default_value = null)
        {
                if (!empty($assertion[$cat][$key])) {
-                       $this->assertEquals($assertion[$cat][$key], $this->configCache->get($cat, $key));
+                       self::assertEquals($assertion[$cat][$key], $this->configCache->get($cat, $key));
                } elseif (!empty($assertion) && !is_array($assertion)) {
-                       $this->assertEquals($assertion, $this->configCache->get($cat, $key));
+                       self::assertEquals($assertion, $this->configCache->get($cat, $key));
                } elseif (!empty($default_value)) {
-                       $this->assertEquals($default_value, $this->configCache->get($cat, $key));
+                       self::assertEquals($default_value, $this->configCache->get($cat, $key));
                } else {
-                       $this->assertEmpty($this->configCache->get($cat, $key), $this->configCache->get($cat, $key));
+                       self::assertEmpty($this->configCache->get($cat, $key), $this->configCache->get($cat, $key));
                }
        }
 
@@ -315,21 +359,21 @@ FIN;
                        $assertion['database']['hostname'] .= (!empty($assertion['database']['port']) ? ':' . $assertion['database']['port'] : '');
                }
 
-               $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')));
-               $this->assertConfigEntry('config', 'hostname', $assertion);
-
-               $this->assertConfigEntry('system', 'default_timezone', $assertion, ($default) ? Installer::DEFAULT_TZ : null);
-               $this->assertConfigEntry('system', 'language', $assertion, ($default) ? Installer::DEFAULT_LANG : null);
-               $this->assertConfigEntry('system', 'url', $assertion);
-               $this->assertConfigEntry('system', 'urlpath', $assertion);
-               $this->assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? BaseURL::DEFAULT_SSL_SCHEME : null);
-               $this->assertConfigEntry('system', 'basepath', ($realBasepath) ? $this->root->url() : $assertion);
+               self::assertConfigEntry('database', 'hostname', ($saveDb) ? $assertion : null, (!$saveDb || $defaultDb) ? Installer::DEFAULT_HOST : null);
+               self::assertConfigEntry('database', 'username', ($saveDb) ? $assertion : null);
+               self::assertConfigEntry('database', 'password', ($saveDb) ? $assertion : null);
+               self::assertConfigEntry('database', 'database', ($saveDb) ? $assertion : null);
+
+               self::assertConfigEntry('config', 'admin_email', $assertion);
+               self::assertConfigEntry('config', 'php_path', trim(shell_exec('which php')));
+               self::assertConfigEntry('config', 'hostname', $assertion);
+
+               self::assertConfigEntry('system', 'default_timezone', $assertion, ($default) ? Installer::DEFAULT_TZ : null);
+               self::assertConfigEntry('system', 'language', $assertion, ($default) ? Installer::DEFAULT_LANG : null);
+               self::assertConfigEntry('system', 'url', $assertion);
+               self::assertConfigEntry('system', 'urlpath', $assertion);
+               self::assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? App\BaseURL::DEFAULT_SSL_SCHEME : null);
+               self::assertConfigEntry('system', 'basepath', ($realBasepath) ? $this->root->url() : $assertion);
        }
 
        /**
@@ -342,7 +386,7 @@ FIN;
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertStuckURL($txt);
+               self::assertStuckURL($txt);
        }
 
        /**
@@ -357,17 +401,17 @@ FIN;
                $this->mockUpdate([$this->root->url(), false, true, true], null, 1);
 
                $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
-               $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
+               $this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1);
 
                $console = new AutomaticInstallation($this->consoleArgv);
                $console->setOption('url', 'http://friendica.local');
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertFinished($txt, true, false);
-               $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
+               self::assertFinished($txt, true, false);
+               self::assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
 
-               $this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local', 'ssl_policy' => 0, 'urlPath' => '']], false, true, true, true);
+               self::assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local', 'ssl_policy' => 0, 'urlPath' => '']], false, true, true, true);
        }
 
        /**
@@ -393,7 +437,7 @@ FIN;
 
 // Local configuration
 
-// If you're unsure about what any of the config keys below do, please check the config/defaults.config.php for detailed
+// If you're unsure about what any of the config keys below do, please check the static/defaults.config.php for detailed
 // documentation of their data type and behavior.
 
 return [
@@ -403,6 +447,7 @@ return [
                'password' => '{$conf('database', 'password')}',
                'database' => '{$conf('database', 'database')}',
                'charset' => 'utf8mb4',
+               'pdo_emulate_prepares' => false,
        ],
 
        // ****************************************************************
@@ -438,12 +483,12 @@ CONF;
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertFinished($txt, false, true);
+               self::assertFinished($txt, false, true);
 
-               $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
-               $this->assertEquals($config, file_get_contents($this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')->url()));
+               self::assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
+               self::assertEquals($config, file_get_contents($this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')->url()));
 
-               $this->assertConfig($data, true, false, false);
+               self::assertConfig($data, true, false, false);
        }
 
        /**
@@ -459,29 +504,29 @@ CONF;
                $this->mockUpdate([$this->root->url(), false, true, true], null, 1);
 
                $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
-               $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
-
-               $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']));
-
-               $this->assertTrue(putenv('FRIENDICA_HOSTNAME='   . $data['config']['hostname']));
-               $this->assertTrue(putenv('FRIENDICA_BASE_PATH='  . $data['system']['basepath']));
-               $this->assertTrue(putenv('FRIENDICA_URL='        . $data['system']['url']));
-               $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']));
+               $this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1);
+
+               self::assertTrue(putenv('MYSQL_HOST='     . $data['database']['hostname']));
+               self::assertTrue(putenv('MYSQL_PORT='     . $data['database']['port']));
+               self::assertTrue(putenv('MYSQL_DATABASE=' . $data['database']['database']));
+               self::assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
+               self::assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
+
+               self::assertTrue(putenv('FRIENDICA_HOSTNAME='   . $data['config']['hostname']));
+               self::assertTrue(putenv('FRIENDICA_BASE_PATH='  . $data['system']['basepath']));
+               self::assertTrue(putenv('FRIENDICA_URL='        . $data['system']['url']));
+               self::assertTrue(putenv('FRIENDICA_PHP_PATH='   . $data['config']['php_path']));
+               self::assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
+               self::assertTrue(putenv('FRIENDICA_TZ='         . $data['system']['default_timezone']));
+               self::assertTrue(putenv('FRIENDICA_LANG='       . $data['system']['language']));
 
                $console = new AutomaticInstallation($this->consoleArgv);
                $console->setOption('savedb', true);
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertFinished($txt, true);
-               $this->assertConfig($data, true, true, false, true);
+               self::assertFinished($txt, true);
+               self::assertConfig($data, true, true, false, true);
        }
 
        /**
@@ -497,28 +542,28 @@ CONF;
                $this->mockUpdate([$this->root->url(), false, true, true], null, 1);
 
                $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
-               $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
-
-               $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']));
-
-               $this->assertTrue(putenv('FRIENDICA_HOSTNAME='   . $data['config']['hostname']));
-               $this->assertTrue(putenv('FRIENDICA_BASE_PATH='  . $data['system']['basepath']));
-               $this->assertTrue(putenv('FRIENDICA_URL='        . $data['system']['url']));
-               $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']));
+               $this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1);
+
+               self::assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname']));
+               self::assertTrue(putenv('MYSQL_PORT=' . $data['database']['port']));
+               self::assertTrue(putenv('MYSQL_DATABASE=' . $data['database']['database']));
+               self::assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
+               self::assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
+
+               self::assertTrue(putenv('FRIENDICA_HOSTNAME='   . $data['config']['hostname']));
+               self::assertTrue(putenv('FRIENDICA_BASE_PATH='  . $data['system']['basepath']));
+               self::assertTrue(putenv('FRIENDICA_URL='        . $data['system']['url']));
+               self::assertTrue(putenv('FRIENDICA_PHP_PATH='   . $data['config']['php_path']));
+               self::assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
+               self::assertTrue(putenv('FRIENDICA_TZ='         . $data['system']['default_timezone']));
+               self::assertTrue(putenv('FRIENDICA_LANG='       . $data['system']['language']));
 
                $console = new AutomaticInstallation($this->consoleArgv);
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertFinished($txt, true);
-               $this->assertConfig($data, false, true, false, true);
+               self::assertFinished($txt, true);
+               self::assertConfig($data, false, true, false, true);
        }
 
        /**
@@ -533,7 +578,7 @@ CONF;
                $this->mockUpdate([$this->root->url(), false, true, true], null, 1);
 
                $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
-               $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
+               $this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1);
 
                $console = new AutomaticInstallation($this->consoleArgv);
 
@@ -556,8 +601,8 @@ CONF;
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertFinished($txt, true);
-               $this->assertConfig($data, true, true, true, true);
+               self::assertFinished($txt, true);
+               self::assertConfig($data, true, true, true, true);
        }
 
        /**
@@ -568,17 +613,17 @@ CONF;
                $this->mockConnect(false, 1);
 
                $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
-               $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
+               $this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1);
 
                $console = new AutomaticInstallation($this->consoleArgv);
                $console->setOption('url', 'http://friendica.local');
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertStuckDB($txt);
-               $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
+               self::assertStuckDB($txt);
+               self::assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
 
-               $this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local', 'ssl_policy' => 0, 'urlpath' => '']], false, true, false, true);
+               self::assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local', 'ssl_policy' => 0, 'urlpath' => '']], false, true, false, true);
        }
 
        public function testGetHelp()
@@ -642,6 +687,6 @@ HELP;
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertEquals($theHelp, $txt);
+               self::assertEquals($theHelp, $txt);
        }
 }