]> git.mxchange.org Git - friendica.git/commitdiff
Fix BBCode::expandTags() & Remove AppMockTrait
authorPhilipp <admin@philipp.info>
Sun, 28 Nov 2021 11:59:42 +0000 (12:59 +0100)
committerPhilipp <admin@philipp.info>
Sun, 28 Nov 2021 12:07:38 +0000 (13:07 +0100)
src/Content/Text/BBCode.php
tests/Util/AppMockTrait.php [deleted file]
tests/src/Content/SmiliesTest.php
tests/src/Content/Text/BBCodeTest.php
tests/src/Content/Text/HTMLTest.php
tests/src/Content/Text/MarkdownTest.php

index ecaf345274ab31659a67157a1f46df9c82e55a53..a1d65add5d008375749f3ba4776e523751ceed45 100644 (file)
@@ -2322,7 +2322,7 @@ class BBCode
                                                break;
                                        case '#':
                                        default:
-                                               return $match[1] . '[url=' . 'https://' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]';
+                                               return $match[1] . '[url=' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]';
                                }
                        }, $body);
        }
diff --git a/tests/Util/AppMockTrait.php b/tests/Util/AppMockTrait.php
deleted file mode 100644 (file)
index ed3a42b..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2010-2021, 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\Util;
-
-use Dice\Dice;
-use Friendica\App;
-use Friendica\Core\Config;
-use Friendica\DI;
-use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Render\FriendicaSmartyEngine;
-use Friendica\Util\Profiler;
-use Mockery\MockInterface;
-use org\bovigo\vfs\vfsStreamDirectory;
-
-/**
- * Trait to Mock the global App instance
- */
-trait AppMockTrait
-{
-       /**
-        * @var MockInterface|App The mocked Friendica\App
-        */
-       protected $app;
-
-       /**
-        * @var MockInterface|Config\Capability\IManageConfigValues The mocked Config Cache
-        */
-       protected $configMock;
-
-       /**
-        * @var MockInterface|Profiler The mocked profiler
-        */
-       protected $profilerMock;
-
-       /**
-        * @var MockInterface|App\Mode The mocked App mode
-        */
-       protected $mode;
-
-       /**
-        * @var MockInterface|Dice The dependency injection library
-        */
-       protected $dice;
-
-       /**
-        * Mock the App
-        *
-        * @param vfsStreamDirectory $root The root directory
-        * @param bool               $raw  If true, no config mocking will be done
-        *
-        * @throws InternalServerErrorException
-        */
-       public function mockApp(vfsStreamDirectory $root, $raw = false)
-       {
-               $this->dice = \Mockery::mock(Dice::class)->makePartial();
-               $this->dice = $this->dice->addRules(include __DIR__ . '/../../static/dependencies.config.php');
-
-               $this->configMock = \Mockery::mock(Config\ValueObject\Cache::class);
-               $this->dice->shouldReceive('create')
-                          ->with(Config\ValueObject\Cache::class)
-                          ->andReturn($this->configMock);
-               $this->mode = \Mockery::mock(App\Mode::class);
-               $this->dice->shouldReceive('create')
-                          ->with(App\Mode::class)
-                          ->andReturn($this->mode);
-               $configModel= \Mockery::mock(Config\Repository\Config::class);
-               // Disable the adapter
-               $configModel->shouldReceive('isConnected')->andReturn(false);
-
-               $config = new Config\Type\JitConfig($this->configMock, $configModel);
-               $this->dice->shouldReceive('create')
-                          ->with(Config\Capability\IManageConfigValues::class)
-                          ->andReturn($config);
-
-               // Mocking App and most used functions
-               $this->app = \Mockery::mock(App::class);
-               $this->dice->shouldReceive('create')
-                          ->with(App::class)
-                          ->andReturn($this->app);
-               $this->app
-                       ->shouldReceive('getBasePath')
-                       ->andReturn($root->url());
-
-               $this->profilerMock = \Mockery::mock(Profiler::class);
-               $this->profilerMock->shouldReceive('startRecording');
-               $this->profilerMock->shouldReceive('stopRecording');
-               $this->profilerMock->shouldReceive('saveTimestamp');
-               $this->dice->shouldReceive('create')
-                          ->with(Profiler::class)
-                          ->andReturn($this->profilerMock);
-
-               $this->app
-                       ->shouldReceive('getConfigCache')
-                       ->andReturn($this->configMock);
-               $this->app
-                       ->shouldReceive('getTemplateEngine')
-                       ->andReturn(new FriendicaSmartyEngine('frio', []));
-               $this->app
-                       ->shouldReceive('getCurrentTheme')
-                       ->andReturn('Smarty3');
-               $this->app->shouldReceive('getThemeInfoValue')
-                       ->with('videowidth')
-                       ->andReturn(425);
-               $this->app->shouldReceive('getThemeInfoValue')
-                       ->with('videoheight')
-                       ->andReturn(350);
-       
-               DI::init($this->dice);
-
-               if ($raw) {
-                       return;
-               }
-
-               $this->configMock
-                       ->shouldReceive('has')
-                       ->andReturn(true);
-               $this->configMock
-                       ->shouldReceive('get')
-                       ->with('database', 'hostname')
-                       ->andReturn(getenv('MYSQL_HOST'));
-               $this->configMock
-                       ->shouldReceive('get')
-                       ->with('database', 'username')
-                       ->andReturn(getenv('MYSQL_USERNAME'));
-               $this->configMock
-                       ->shouldReceive('get')
-                       ->with('database', 'password')
-                       ->andReturn(getenv('MYSQL_PASSWORD'));
-               $this->configMock
-                       ->shouldReceive('get')
-                       ->with('database', 'database')
-                       ->andReturn(getenv('MYSQL_DATABASE'));
-               $this->configMock
-                       ->shouldReceive('get')
-                       ->with('config', 'hostname')
-                       ->andReturn('localhost');
-               $this->configMock
-                       ->shouldReceive('get')
-                       ->with('system', 'theme')
-                       ->andReturn('system_theme');
-       }
-}
index 2e97b4d400101380609fee54b89b6c4b2652ab06..74d18912f9e65ba655fea6eebfaa6b6b397d1b21 100644 (file)
@@ -9,27 +9,17 @@
 namespace Friendica\Test\src\Content;
 
 use Friendica\Content\Smilies;
+use Friendica\DI;
 use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Test\MockedTest;
-use Friendica\Test\Util\AppMockTrait;
-use Friendica\Test\Util\VFSTrait;
+use Friendica\Test\FixtureTest;
 
-class SmiliesTest extends MockedTest
+class SmiliesTest extends FixtureTest
 {
-       use VFSTrait;
-       use AppMockTrait;
-
        protected function setUp(): void
        {
                parent::setUp();
-               $this->setUpVfsDir();
-               $this->mockApp($this->root);
-               $this->configMock->shouldReceive('get')
-                       ->with('system', 'no_smilies')
-                       ->andReturn(false);
-               $this->configMock->shouldReceive('get')
-                       ->with(false, 'system', 'no_smilies')
-                       ->andReturn(false);
+
+               DI::config()->set('system', 'no_smilies', false);
        }
 
        public function dataLinks()
index cb17758c73be9907e62d696f6089e953b0bb7a5b..97ea18cb02433cf04ed8f90ab415368032afded0 100644 (file)
 
 namespace Friendica\Test\src\Content\Text;
 
-use Friendica\App\BaseURL;
 use Friendica\Content\Text\BBCode;
-use Friendica\Core\L10n;
+use Friendica\DI;
 use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Test\MockedTest;
-use Friendica\Test\Util\AppMockTrait;
-use Friendica\Test\Util\VFSTrait;
-use Mockery;
+use Friendica\Test\FixtureTest;
 
-class BBCodeTest extends MockedTest
+class BBCodeTest extends FixtureTest
 {
-       use VFSTrait;
-       use AppMockTrait;
-
        protected function setUp(): void
        {
                parent::setUp();
-               $this->setUpVfsDir();
-               $this->mockApp($this->root);
-               $this->configMock->shouldReceive('get')
-                       ->with('system', 'remove_multiplicated_lines')
-                       ->andReturn(false);
-               $this->configMock->shouldReceive('get')
-                       ->with('system', 'no_oembed')
-                       ->andReturn(false);
-               $this->configMock->shouldReceive('get')
-                       ->with('system', 'allowed_link_protocols')
-                       ->andReturn(null);
-               $this->configMock->shouldReceive('get')
-                       ->with('system', 'url')
-                       ->andReturn('friendica.local');
-               $this->configMock->shouldReceive('get')
-                       ->with('system', 'no_smilies')
-                       ->andReturn(false);
-               $this->configMock->shouldReceive('get')
-                       ->with('system', 'big_emojis')
-                       ->andReturn(false);
-               $this->configMock->shouldReceive('get')
-                       ->with('system', 'allowed_oembed')
-                       ->andReturn('');
-
-               $l10nMock = Mockery::mock(L10n::class);
-               $l10nMock->shouldReceive('t')->withAnyArgs()->andReturnUsing(function ($args) { return $args; });
-               $this->dice->shouldReceive('create')
-                          ->with(L10n::class)
-                          ->andReturn($l10nMock);
+               DI::config()->set('system', 'remove_multiplicated_lines', false);
+               DI::config()->set('system', 'no_oembed', false);
+               DI::config()->set('system', 'allowed_link_protocols', []);
+               DI::config()->set('system', 'url', 'friendica.local');
+               DI::config()->set('system', 'no_smilies', false);
+               DI::config()->set('system', 'big_emojis', false);
+               DI::config()->set('system', 'allowed_oembed', '');
 
-               $baseUrlMock = Mockery::mock(BaseURL::class);
-               $baseUrlMock->shouldReceive('get')->withAnyArgs()->andReturn('friendica.local');
-               $this->dice->shouldReceive('create')
-                          ->with(BaseURL::class)
-                          ->andReturn($baseUrlMock);
-               $baseUrlMock->shouldReceive('getHostname')->withNoArgs()->andReturn('friendica.local');
-               $baseUrlMock->shouldReceive('getUrlPath')->withNoArgs()->andReturn('');
-               $baseUrlMock->shouldReceive('__toString')->withNoArgs()->andReturn('friendica.local');
+               DI::baseUrl()->save('friendica.local', DI::baseUrl()::SSL_POLICY_FULL, '');
 
                $config = \HTMLPurifier_HTML5Config::createDefault();
                $config->set('HTML.Doctype', 'HTML5');
index fb2b95740d6af77365a8b407f5d31bbdc8ce528e..8c257795445f5c00e3f3551323ad7f53281d618e 100644 (file)
@@ -24,22 +24,10 @@ namespace Friendica\Test\src\Content\Text;
 use Exception;
 use Friendica\Content\Text\HTML;
 use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Test\MockedTest;
-use Friendica\Test\Util\AppMockTrait;
-use Friendica\Test\Util\VFSTrait;
+use Friendica\Test\FixtureTest;
 
-class HTMLTest extends MockedTest
+class HTMLTest extends FixtureTest
 {
-       use VFSTrait;
-       use AppMockTrait;
-
-       protected function setUp(): void
-       {
-               parent::setUp();
-               $this->setUpVfsDir();
-               $this->mockApp($this->root);
-       }
-
        public function dataHTML()
        {
                $inputFiles = glob(__DIR__ . '/../../../datasets/content/text/html/*.html');
index 5fae494d6fb82639d7d74f01a6522a34a89fe518..f718aa47c69b4db06c9e6e7a7ee6ac803401d4bc 100644 (file)
@@ -23,22 +23,10 @@ namespace Friendica\Test\src\Content\Text;
 
 use Exception;
 use Friendica\Content\Text\Markdown;
-use Friendica\Test\MockedTest;
-use Friendica\Test\Util\AppMockTrait;
-use Friendica\Test\Util\VFSTrait;
+use Friendica\Test\FixtureTest;
 
-class MarkdownTest extends MockedTest
+class MarkdownTest extends FixtureTest
 {
-       use VFSTrait;
-       use AppMockTrait;
-
-       protected function setUp(): void
-       {
-               parent::setUp();
-               $this->setUpVfsDir();
-               $this->mockApp($this->root);
-       }
-
        public function dataMarkdown()
        {
                $inputFiles = glob(__DIR__ . '/../../../datasets/content/text/markdown/*.md');