]> git.mxchange.org Git - friendica.git/commitdiff
Fix and adapt tests
authorPhilipp <admin@philipp.info>
Sun, 12 Feb 2023 12:09:05 +0000 (13:09 +0100)
committerPhilipp <admin@philipp.info>
Sun, 12 Feb 2023 12:09:05 +0000 (13:09 +0100)
tests/Util/CreateDatabaseTrait.php
tests/Util/VFSTrait.php
tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php

index 7cb13cc225e617dce38395ce9feddd7e69ee6cc6..3d83306532a752cb884ed1acc50f98e32f79fc5d 100644 (file)
@@ -37,8 +37,15 @@ trait CreateDatabaseTrait
        use DatabaseTestTrait;
        use VFSTrait;
 
+       /** @var Database|null */
+       protected $dba = null;
+
        public function getDbInstance(): Database
        {
+               if (isset($this->dba)) {
+                       return $this->dba;
+               }
+
                $configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
                $config            = new ReadOnlyFileConfig(new Cache([
                        'database' => [
index e36cc1234cffb0850613289dec4f495e69919636..3a203588cf450b4ef179f241b1b5927b7d54dfb1 100644 (file)
@@ -49,45 +49,38 @@ trait VFSTrait
                // create a virtual directory and copy all needed files and folders to it
                $this->root = vfsStream::setup('friendica', 0777, $structure);
 
-               $this->setConfigFile('dbstructure.config.php', true);
-               $this->setConfigFile('dbview.config.php', true);
-               $this->setConfigFile('defaults.config.php', true);
-               $this->setConfigFile('settings.config.php', true);
-               $this->setConfigFile('local.config.php');
-               $this->setDataFile('node.config.php');
-       }
-
-       protected function setDataFile(string $filename)
-       {
-               $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
-                               'datasets' . DIRECTORY_SEPARATOR .
-                               'config' . DIRECTORY_SEPARATOR .
-                               $filename;
-
-               if (file_exists($file)) {
-                       vfsStream::newFile($filename)
-                               ->at($this->root->getChild('config'))
-                               ->setContent(file_get_contents($file));
-               }
+               $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'dbstructure.config.php', true);
+               $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'dbview.config.php', true);
+               $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'defaults.config.php', true);
+               $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'settings.config.php', true);
+               $this->setConfigFile(
+                       'mods' . DIRECTORY_SEPARATOR . 'local.config.vagrant.php',
+                       false, 'local.config.php'
+               );
        }
 
        /**
         * Copying a config file from the file system to the Virtual File System
         *
-        * @param string $filename The filename of the config file
-        * @param bool   $static   True, if the folder `static` instead of `config` should be used
+        * @param string $sourceFilePath The filename of the config file
+        * @param bool   $static         True, if the folder `static` instead of `config` should be used
         */
-       protected function setConfigFile(string $filename, bool $static = false)
+       protected function setConfigFile(string $sourceFilePath, bool $static = false, string $targetFileName = null)
        {
                $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
                        '..' . DIRECTORY_SEPARATOR .
-                       ($static ? 'static' : 'config') . DIRECTORY_SEPARATOR .
-                       $filename;
+                               $sourceFilePath;
 
                if (file_exists($file)) {
-                       vfsStream::newFile($filename)
+                       if (empty($targetFileName)) {
+                               $tmpArray = preg_split('/\\' . DIRECTORY_SEPARATOR . '/', $sourceFilePath);
+                               $targetFileName = array_pop($tmpArray);
+                       }
+                       vfsStream::newFile($targetFileName)
                                ->at($this->root->getChild(($static ? 'static' : 'config')))
                                ->setContent(file_get_contents($file));
+               } else {
+                       throw new \Exception(sprintf('Unexpected missing config \'%s\'', $file));
                }
        }
 
index 0d0afa64bc9059fb5109feca5c8ec687684b803a..6311175d34b007361a5232ca86f5f01e5928f591 100644 (file)
@@ -41,12 +41,12 @@ class ConfigTest extends ApiTest
                        ->run($this->httpExceptionMock);
                $json = $this->toJson($response);
 
-               self::assertEquals('localhost', $json->site->server);
-               self::assertEquals('frio', $json->site->theme);
+               self::assertEquals(DI::config()->get('config', 'hostname'), $json->site->server);
+               self::assertEquals(DI::config()->get('system', 'theme'), $json->site->theme);
                self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $json->site->logo);
                self::assertTrue($json->site->fancy);
-               self::assertEquals('en', $json->site->language);
-               self::assertEquals('UTC', $json->site->timezone);
+               self::assertEquals(DI::config()->get('system', 'language'), $json->site->language);
+               self::assertEquals(DI::config()->get('system', 'default_timezone'), $json->site->timezone);
                self::assertEquals(200000, $json->site->textlimit);
                self::assertFalse($json->site->private);
                self::assertEquals('always', $json->site->ssl);