]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Core/Console/AutomaticInstallationConsoleTest.php
Merge pull request #6224 from annando/dba-delete-contact
[friendica.git] / tests / src / Core / Console / AutomaticInstallationConsoleTest.php
index bed3a578b6e40cda64c10b428dd5b21b4ecc1e21..813277ebbd730322c57734184613dad42c5fb81c 100644 (file)
@@ -5,6 +5,8 @@ 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\L10nMockTrait;
+use Friendica\Test\Util\RendererMockTrait;
 use org\bovigo\vfs\vfsStream;
 use org\bovigo\vfs\vfsStreamFile;
 
@@ -15,8 +17,10 @@ use org\bovigo\vfs\vfsStreamFile;
  */
 class AutomaticInstallationConsoleTest extends ConsoleTest
 {
+       use L10nMockTrait;
        use DBAMockTrait;
        use DBStructureMockTrait;
+       use RendererMockTrait;
 
        private $db_host;
        private $db_port;
@@ -37,51 +41,44 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
        {
                parent::setUp();
 
-               if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')) {
+               if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
                        $this->root->getChild('config')
-                               ->removeChild('local.ini.php');
+                               ->removeChild('local.config.php');
                }
 
                $this->db_host = getenv('MYSQL_HOST');
-               $this->db_port = (!empty(getenv('MYSQL_PORT'))) ? getenv('MYSQL_PORT') : null;
+               $this->db_port = !empty(getenv('MYSQL_PORT')) ? getenv('MYSQL_PORT') : null;
                $this->db_data = getenv('MYSQL_DATABASE');
                $this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
                $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));
+               $this->mockL10nT();
        }
 
        /**
-        * Replacing environment specific variables in the assertion file
+        * Creates the arguments which is asserted to be passed to 'replaceMacros()' for creating the local.config.php
         *
-        * @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
+        * @param bool $withDb if true, DB will get saved too
+        *
+        * @return array The arguments to pass to the mock for 'replaceMacros()'
         */
-       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)
@@ -168,7 +165,7 @@ Creating config file...
 Checking database...
 
 [Error] --------
-: 
+Could not connect to database.
 
 
 FIN;
@@ -187,51 +184,53 @@ FIN;
                $this->mockUpdate([false, true, true], null, 1);
 
                $config = <<<CONF
-<?php return <<<INI
-
-[database]
-hostname = 
-username = 
-password = 
-database = 
-charset = utf8mb4
-
-
-; ****************************************************************
-; The configuration below will be overruled by the admin panel.
-; Changes made below will only have an effect if the database does
-; not contain any configuration for the friendica system.
-; ****************************************************************
-
-[config]
-admin_email =
-
-sitename = Friendica Social Network
-
-register_policy = REGISTER_OPEN
-register_text =
-
-[system]
-default_timezone = UTC
-
-language = en
-INI;
-// Keep this line
+<?php
 
+// Local configuration
+
+// If you're unsure about what any of the config keys below do, please check the config/defaults.config.php for detailed
+// documentation of their data type and behavior.
+
+return [
+       'database' => [
+               'hostname' => '',
+               'username' => '',
+               'password' => '',
+               'database' => '',
+               'charset' => 'utf8mb4',
+       ],
+
+       // ****************************************************************
+       // The configuration below will be overruled by the admin panel.
+       // Changes made below will only have an effect if the database does
+       // not contain any configuration for the friendica system.
+       // ****************************************************************
+
+       'config' => [
+               'admin_email' => '',
+               'sitename' => 'Friendica Social Network',
+               'register_policy' => REGISTER_OPEN,
+               'register_text' => '',
+       ],
+       'system' => [
+               'default_timezone' => 'UTC',
+               'language' => 'en',
+       ],
+];
 CONF;
 
-               vfsStream::newFile('prepared.ini.php')
+               vfsStream::newFile('prepared.config.php')
                        ->at($this->root)
                        ->setContent($config);
 
                $console = new AutomaticInstallation($this->consoleArgv);
-               $console->setOption('f', 'prepared.ini.php');
+               $console->setOption('f', 'prepared.config.php');
 
                $txt = $this->dumpExecute($console);
 
                $this->assertFinished($txt, false, true);
 
-               $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
+               $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
        }
 
        /**
@@ -244,6 +243,9 @@ CONF;
                $this->mockExistsTable('user', false, 1);
                $this->mockUpdate([false, true, true], null, 1);
 
+               $this->mockGetMarkupTemplate('local.config.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 +257,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 +269,9 @@ CONF;
                $this->mockExistsTable('user', false, 1);
                $this->mockUpdate([false, true, true], null, 1);
 
+               $this->mockGetMarkupTemplate('local.config.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 +282,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 +294,9 @@ CONF;
                $this->mockExistsTable('user', false, 1);
                $this->mockUpdate([false, true, true], null, 1);
 
+               $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
+               $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(true), '', 1);
+
                $console = new AutomaticInstallation($this->consoleArgv);
 
                $console->setOption('dbhost', $this->db_host);
@@ -322,12 +318,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 +328,14 @@ CONF;
        {
                $this->mockConnect(false, 1);
 
+               $this->mockGetMarkupTemplate('local.config.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);
@@ -354,7 +352,7 @@ Synopsis
        bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f]
 
 Description
-    Installs Friendica with data based on the local.ini.php file or environment variables
+    Installs Friendica with data based on the local.config.php file or environment variables
 
 Notes
     Not checking .htaccess/URL-Rewrite during CLI installation.
@@ -363,7 +361,7 @@ Options
     -h|--help|-?            Show help information
     -v                      Show more debug information.
     -a                      All setup checks are required (except .htaccess)
-    -f|--file <config>      prepared config file (e.g. "config/local.ini.php" itself) which will override every other config option - except the environment variables)
+    -f|--file <config>      prepared config file (e.g. "config/local.config.php" itself) which will override every other config option - except the environment variables)
     -s|--savedb             Save the DB credentials to the file (if environment variables is used)
     -H|--dbhost <host>      The host of the mysql/mariadb database (env MYSQL_HOST)
     -p|--dbport <port>      The port of the mysql/mariadb database (env MYSQL_PORT)
@@ -389,11 +387,11 @@ Environment variables
    FRIENDICA_LANG              The langauge of Friendica
    
 Examples
-       bin/console autoinstall -f 'input.ini.php
-               Installs Friendica with the prepared 'input.ini.php' file
+       bin/console autoinstall -f 'input.config.php
+               Installs Friendica with the prepared 'input.config.php' file
 
        bin/console autoinstall --savedb
-               Installs Friendica with environment variables and saves them to the 'config/local.ini.php' file
+               Installs Friendica with environment variables and saves them to the 'config/local.config.php' file
 
        bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica
                Installs Friendica with a local mysql database with credentials