]> git.mxchange.org Git - friendica.git/commitdiff
Bufixing environment specific assertion problem
authorPhilipp Holzer <admin@philipp.info>
Wed, 31 Oct 2018 10:03:15 +0000 (11:03 +0100)
committerPhilipp Holzer <admin@philipp.info>
Wed, 31 Oct 2018 10:03:15 +0000 (11:03 +0100)
tests/Util/VFSTrait.php
tests/datasets/ini/assert_db.ini.php [deleted file]
tests/src/Core/Console/AutomaticInstallationConsoleTest.php

index 34763b13851167fb9af83384cb7e79a31edd3b48..972119134ab502336837afe74dbadfbd31196621 100644 (file)
@@ -20,7 +20,8 @@ trait VFSTrait
                // the used directories inside the App class
                $structure = [
                        'config' => [],
-                       'bin' => []
+                       'bin' => [],
+                       'test' => []
                ];
 
                // create a virtual directory and copy all needed files and folders to it
diff --git a/tests/datasets/ini/assert_db.ini.php b/tests/datasets/ini/assert_db.ini.php
deleted file mode 100644 (file)
index f42c9dd..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php return <<<INI
-
-; If you're unsure about what any of the config keys below do, please check the config/defaults.ini.php for detailed
-; documentation of their data type and behavior.
-
-[database]
-hostname = "localhost:3306"
-username = "friendica"
-password = "friendica"
-database = "friendica"
-charset = utf8mb4
-
-; ****************************************************************
-; Some config values below can be overruled from the admin settings
-; ****************************************************************
-
-[config]
-php_path = "/usr/bin/php"
-
-admin_email = "admin@friendica.local"
-
-sitename = Friendica Social Network
-
-register_policy = REGISTER_OPEN
-register_text =
-
-max_import_size = 200000
-
-[system]
-urlpath = "/friendica"
-
-default_timezone = "Europe/Berlin"
-
-language = "de"
-
-allowed_themes = vier,quattro,duepuntozero,smoothly,frio
-theme = vier
-
-allowed_link_protocols[0] = ftp
-allowed_link_protocols[1] = ftps
-allowed_link_protocols[2] = mailto
-allowed_link_protocols[3] = cid
-allowed_link_protocols[4] = gopher
-
-maximagesize = 800000
-
-no_regfullname = true
-
-block_local_dir = false
-
-directory = https://dir.friendica.social
-
-auth_cookie_lifetime = 7
-
-INI;
-// Keep this line
\ No newline at end of file
index 1c371f9ba0c202b0e21c0066a409c1ad065a78de..6fc803f8428add2f1e76b4e17ebad16e0b8c2419 100644 (file)
@@ -6,6 +6,7 @@ use Friendica\Core\Console\AutomaticInstallation;
 use Friendica\Test\Util\DBAMockTrait;
 use Friendica\Test\Util\DBStructureMockTrait;
 use org\bovigo\vfs\vfsStream;
+use org\bovigo\vfs\vfsStreamFile;
 
 /**
  * @runTestsInSeparateProcesses
@@ -23,7 +24,13 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
        private $db_user;
        private $db_pass;
 
+       /**
+        * @var vfsStreamFile Assert file without DB credentials
+        */
        private $assertFile;
+       /**
+        * @var vfsStreamFile Assert file with DB credentials
+        */
        private $assertFileDb;
 
        public function setUp()
@@ -43,18 +50,38 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
 
                $this->mockConfigGet('config', 'php_path', false);
 
-               $this->assertFile  = dirname(__DIR__) . DIRECTORY_SEPARATOR .
+               $assertFile  = dirname(__DIR__) . DIRECTORY_SEPARATOR .
                        '..' . DIRECTORY_SEPARATOR .
                        '..' . DIRECTORY_SEPARATOR .
                        'datasets' . DIRECTORY_SEPARATOR .
                        'ini' . DIRECTORY_SEPARATOR .
                        'assert.ini.php';
-               $this->assertFileDb  = dirname(__DIR__) . DIRECTORY_SEPARATOR .
-                       '..' . DIRECTORY_SEPARATOR .
-                       '..' . DIRECTORY_SEPARATOR .
-                       'datasets' . DIRECTORY_SEPARATOR .
-                       'ini' . DIRECTORY_SEPARATOR .
-                       'assert_db.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)
+       {
+               $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;
        }
 
        private function assertFinished($txt, $withconfig = false, $copyfile = false)
@@ -232,7 +259,7 @@ CONF;
                $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
 
                $this->assertFileEquals(
-                       $this->assertFileDb,
+                       $this->assertFileDb->url(),
                        $this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
        }
 
@@ -260,7 +287,7 @@ CONF;
                $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
 
                $this->assertFileEquals(
-                       $this->assertFile,
+                       $this->assertFile->url(),
                        $this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
        }
 
@@ -299,7 +326,7 @@ CONF;
                $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
 
                $this->assertFileEquals(
-                       $this->assertFileDb,
+                       $this->assertFileDb->url(),
                        $this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
        }