Merge remote-tracking branch 'upstream/2021.12-rc' into api-fixes

This commit is contained in:
Michael 2021-11-28 13:44:02 +00:00
commit 61f1a4d14d
11 changed files with 71 additions and 263 deletions

View File

@ -1,5 +1,5 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2021.12-dev (Siberian Iris) -- Friendica 2021.12-rc (Siberian Iris)
-- DB_UPDATE_VERSION 1445 -- DB_UPDATE_VERSION 1445
-- ------------------------------------------ -- ------------------------------------------

View File

@ -2322,7 +2322,7 @@ class BBCode
break; break;
case '#': case '#':
default: 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); }, $body);
} }

View File

@ -67,6 +67,8 @@ class BaseApi extends BaseModule
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = []) public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
{ {
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->app = $app;
} }
protected function delete() protected function delete()

31
tests/Util/AppDouble.php Normal file
View File

@ -0,0 +1,31 @@
<?php
namespace Friendica\Test\Util;
use Friendica\App;
/**
* Making the App class overridable for specific situations
*
* @see App
*/
class AppDouble extends App
{
/** @var bool Marks/Overwrites if the user is currently logged in */
protected $isLoggedIn = false;
/**
* Manually overwrite the "isLoggedIn" behavior
*
* @param bool $isLoggedIn
*/
public function setIsLoggedIn(bool $isLoggedIn)
{
$this->isLoggedIn = $isLoggedIn;
}
public function isLoggedIn()
{
return $this->isLoggedIn;
}
}

View File

@ -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');
}
}

View File

@ -9,27 +9,17 @@
namespace Friendica\Test\src\Content; namespace Friendica\Test\src\Content;
use Friendica\Content\Smilies; use Friendica\Content\Smilies;
use Friendica\DI;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Test\MockedTest; use Friendica\Test\FixtureTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\VFSTrait;
class SmiliesTest extends MockedTest class SmiliesTest extends FixtureTest
{ {
use VFSTrait;
use AppMockTrait;
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->setUpVfsDir();
$this->mockApp($this->root); DI::config()->set('system', 'no_smilies', false);
$this->configMock->shouldReceive('get')
->with('system', 'no_smilies')
->andReturn(false);
$this->configMock->shouldReceive('get')
->with(false, 'system', 'no_smilies')
->andReturn(false);
} }
public function dataLinks() public function dataLinks()

View File

@ -21,61 +21,25 @@
namespace Friendica\Test\src\Content\Text; namespace Friendica\Test\src\Content\Text;
use Friendica\App\BaseURL;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Core\L10n; use Friendica\DI;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Test\MockedTest; use Friendica\Test\FixtureTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\VFSTrait;
use Mockery;
class BBCodeTest extends MockedTest class BBCodeTest extends FixtureTest
{ {
use VFSTrait;
use AppMockTrait;
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->setUpVfsDir(); DI::config()->set('system', 'remove_multiplicated_lines', false);
$this->mockApp($this->root); DI::config()->set('system', 'no_oembed', false);
$this->configMock->shouldReceive('get') DI::config()->set('system', 'allowed_link_protocols', []);
->with('system', 'remove_multiplicated_lines') DI::config()->set('system', 'url', 'friendica.local');
->andReturn(false); DI::config()->set('system', 'no_smilies', false);
$this->configMock->shouldReceive('get') DI::config()->set('system', 'big_emojis', false);
->with('system', 'no_oembed') DI::config()->set('system', 'allowed_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); DI::baseUrl()->save('friendica.local', DI::baseUrl()::SSL_POLICY_FULL, '');
$l10nMock->shouldReceive('t')->withAnyArgs()->andReturnUsing(function ($args) { return $args; });
$this->dice->shouldReceive('create')
->with(L10n::class)
->andReturn($l10nMock);
$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');
$config = \HTMLPurifier_HTML5Config::createDefault(); $config = \HTMLPurifier_HTML5Config::createDefault();
$config->set('HTML.Doctype', 'HTML5'); $config->set('HTML.Doctype', 'HTML5');

View File

@ -24,22 +24,10 @@ namespace Friendica\Test\src\Content\Text;
use Exception; use Exception;
use Friendica\Content\Text\HTML; use Friendica\Content\Text\HTML;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Test\MockedTest; use Friendica\Test\FixtureTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\VFSTrait;
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() public function dataHTML()
{ {
$inputFiles = glob(__DIR__ . '/../../../datasets/content/text/html/*.html'); $inputFiles = glob(__DIR__ . '/../../../datasets/content/text/html/*.html');

View File

@ -23,22 +23,10 @@ namespace Friendica\Test\src\Content\Text;
use Exception; use Exception;
use Friendica\Content\Text\Markdown; use Friendica\Content\Text\Markdown;
use Friendica\Test\MockedTest; use Friendica\Test\FixtureTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\VFSTrait;
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() public function dataMarkdown()
{ {
$inputFiles = glob(__DIR__ . '/../../../datasets/content/text/markdown/*.md'); $inputFiles = glob(__DIR__ . '/../../../datasets/content/text/markdown/*.md');

View File

@ -21,12 +21,14 @@
namespace Friendica\Test\src\Module\Api; namespace Friendica\Test\src\Module\Api;
use Friendica\App;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\DI; use Friendica\DI;
use Friendica\Security\Authentication; use Friendica\Security\Authentication;
use Friendica\Test\FixtureTest; use Friendica\Test\FixtureTest;
use Friendica\Test\Util\AppDouble;
use Friendica\Test\Util\AuthenticationDouble; use Friendica\Test\Util\AuthenticationDouble;
abstract class ApiTest extends FixtureTest abstract class ApiTest extends FixtureTest
@ -51,9 +53,13 @@ abstract class ApiTest extends FixtureTest
parent::setUp(); // TODO: Change the autogenerated stub parent::setUp(); // TODO: Change the autogenerated stub
$this->dice = $this->dice $this->dice = $this->dice
->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true]); ->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true])
->addRule(App::class, ['instanceOf' => AppDouble::class, 'shared' => true]);
DI::init($this->dice); DI::init($this->dice);
// Manual override to bypass API authentication
DI::app()->setIsLoggedIn(true);
$this->installAuthTest(); $this->installAuthTest();
} }

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 2021.12-rc\n" "Project-Id-Version: 2021.12-rc\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-11-28 13:40+0000\n" "POT-Creation-Date: 2021-11-28 13:43+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -126,9 +126,9 @@ msgstr ""
#: mod/unfollow.php:50 mod/unfollow.php:82 mod/wall_attach.php:68 #: mod/unfollow.php:50 mod/unfollow.php:82 mod/wall_attach.php:68
#: mod/wall_attach.php:71 mod/wall_upload.php:90 mod/wall_upload.php:93 #: mod/wall_attach.php:71 mod/wall_upload.php:90 mod/wall_upload.php:93
#: mod/wallmessage.php:36 mod/wallmessage.php:55 mod/wallmessage.php:89 #: mod/wallmessage.php:36 mod/wallmessage.php:55 mod/wallmessage.php:89
#: mod/wallmessage.php:109 src/Module/Attach.php:55 src/Module/BaseApi.php:77 #: mod/wallmessage.php:109 src/Module/Attach.php:55 src/Module/BaseApi.php:79
#: src/Module/BaseApi.php:86 src/Module/BaseApi.php:95 #: src/Module/BaseApi.php:88 src/Module/BaseApi.php:97
#: src/Module/BaseApi.php:104 src/Module/BaseNotifications.php:97 #: src/Module/BaseApi.php:106 src/Module/BaseNotifications.php:97
#: src/Module/Contact/Advanced.php:60 src/Module/Delegation.php:118 #: src/Module/Contact/Advanced.php:60 src/Module/Delegation.php:118
#: src/Module/FollowConfirm.php:18 src/Module/FriendSuggest.php:56 #: src/Module/FollowConfirm.php:18 src/Module/FriendSuggest.php:56
#: src/Module/Group.php:42 src/Module/Group.php:85 src/Module/Invite.php:41 #: src/Module/Group.php:42 src/Module/Group.php:85 src/Module/Invite.php:41
@ -6932,26 +6932,26 @@ msgstr ""
msgid "User registrations waiting for confirmation" msgid "User registrations waiting for confirmation"
msgstr "" msgstr ""
#: src/Module/BaseApi.php:278 src/Module/BaseApi.php:294 #: src/Module/BaseApi.php:280 src/Module/BaseApi.php:296
#: src/Module/BaseApi.php:310 #: src/Module/BaseApi.php:312
msgid "Too Many Requests" msgid "Too Many Requests"
msgstr "" msgstr ""
#: src/Module/BaseApi.php:279 #: src/Module/BaseApi.php:281
#, php-format #, php-format
msgid "Daily posting limit of %d post reached. The post was rejected." msgid "Daily posting limit of %d post reached. The post was rejected."
msgid_plural "Daily posting limit of %d posts reached. The post was rejected." msgid_plural "Daily posting limit of %d posts reached. The post was rejected."
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: src/Module/BaseApi.php:295 #: src/Module/BaseApi.php:297
#, php-format #, php-format
msgid "Weekly posting limit of %d post reached. The post was rejected." msgid "Weekly posting limit of %d post reached. The post was rejected."
msgid_plural "Weekly posting limit of %d posts reached. The post was rejected." msgid_plural "Weekly posting limit of %d posts reached. The post was rejected."
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: src/Module/BaseApi.php:311 #: src/Module/BaseApi.php:313
#, php-format #, php-format
msgid "Monthly posting limit of %d post reached. The post was rejected." msgid "Monthly posting limit of %d post reached. The post was rejected."
msgstr "" msgstr ""