]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Console/AutomaticInstallationConsoleTest.php
Merge pull request #12231 from HankG/fix-unfavourite-endpoint
[friendica.git] / tests / src / Console / AutomaticInstallationConsoleTest.php
index acf5dac7bdc01d192f3f45ce80cfc35696ba7b59..a76ae1c06313e1d62f4b9da6b262deac157f0713 100644 (file)
@@ -1,30 +1,46 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @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\ValueObject\Cache;
 use Friendica\Core\Installer;
+use Friendica\Core\L10n;
 use Friendica\Core\Logger;
-use Friendica\Test\Util\DBAMockTrait;
-use Friendica\Test\Util\DBStructureMockTrait;
-use Friendica\Test\Util\L10nMockTrait;
+use Friendica\Database\Database;
+use Friendica\DI;
 use Friendica\Test\Util\RendererMockTrait;
-use Friendica\Util\BaseURL;
-use Friendica\Util\Logger\VoidLogger;
+use Friendica\Test\Util\VFSTrait;
+use Mockery;
+use Mockery\MockInterface;
 use org\bovigo\vfs\vfsStream;
 use org\bovigo\vfs\vfsStreamFile;
+use Psr\Log\NullLogger;
 
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @requires PHP 7.0
- */
 class AutomaticInstallationConsoleTest extends ConsoleTest
 {
-       use L10nMockTrait;
-       use DBAMockTrait;
-       use DBStructureMockTrait;
+       use VFSTrait;
        use RendererMockTrait;
 
        /**
@@ -37,28 +53,53 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
        private $assertFileDb;
 
        /**
-        * @var ConfigCache The configuration cache to check after each test
+        * @var \Friendica\Core\Config\ValueObject\Cache The configuration cache to check after each test
         */
        private $configCache;
 
-       public function setUp()
+       /**
+        * @var App\Mode
+        */
+       private $appMode;
+
+       /**
+        * @var Database
+        */
+       private $dba;
+
+       /**
+        * @var Dice|MockInterface
+        */
+       private $dice;
+
+       public function setUp() : void
        {
+               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->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
 
-               $this->mockL10nT();
+               $this->dice->shouldReceive('create')
+                          ->with(L10n::class)
+                          ->andReturn($l10nMock);
 
-               $this->configCache = new ConfigCache();
+               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);
@@ -72,11 +113,11 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
                        return $this->configCache->get($cat, $key);
                });
                $this->configMock->shouldReceive('load')->andReturnUsing(function ($config, $overwrite = false) {
-                       return $this->configCache->load($config, $overwrite);
+                       $this->configCache->load($config, $overwrite);
                });
 
                $this->mode->shouldReceive('isInstall')->andReturn(true);
-               Logger::init(new VoidLogger());
+               Logger::init(new NullLogger());
        }
 
        /**
@@ -220,7 +261,7 @@ Installation is finished
 
 
 FIN;
-               $this->assertEquals($finished, $txt);
+               self::assertEquals($finished, $txt);
        }
 
        private function assertStuckDB($txt)
@@ -251,7 +292,7 @@ Could not connect to database.:
 
 FIN;
 
-               $this->assertEquals($finished, $txt);
+               self::assertEquals($finished, $txt);
        }
 
        private function assertStuckURL($txt)
@@ -275,7 +316,7 @@ The Friendica URL has to be set during CLI installation.
 
 FIN;
 
-               $this->assertEquals($finished, $txt);
+               self::assertEquals($finished, $txt);
        }
 
        /**
@@ -289,13 +330,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));
                }
        }
 
@@ -314,21 +355,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);
        }
 
        /**
@@ -341,7 +382,7 @@ FIN;
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertStuckURL($txt);
+               self::assertStuckURL($txt);
        }
 
        /**
@@ -356,17 +397,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);
        }
 
        /**
@@ -392,7 +433,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 [
@@ -402,6 +443,7 @@ return [
                'password' => '{$conf('database', 'password')}',
                'database' => '{$conf('database', 'database')}',
                'charset' => 'utf8mb4',
+               'pdo_emulate_prepares' => false,
        ],
 
        // ****************************************************************
@@ -437,12 +479,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);
        }
 
        /**
@@ -458,29 +500,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);
        }
 
        /**
@@ -496,28 +538,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);
        }
 
        /**
@@ -532,7 +574,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);
 
@@ -555,8 +597,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);
        }
 
        /**
@@ -567,17 +609,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()
@@ -641,6 +683,6 @@ HELP;
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertEquals($theHelp, $txt);
+               self::assertEquals($theHelp, $txt);
        }
 }