mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-17 04:15:15 +02:00
Refactor L10n for testing
- Moving L10n to L10n\L10n - Adding constructor information - Adding to factory - simplify/speedup tests
This commit is contained in:
parent
966043712f
commit
eb024a3718
13 changed files with 596 additions and 450 deletions
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Util;
|
||||
|
||||
use Friendica\Core\L10n;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
trait L10nMockTrait
|
||||
{
|
||||
/**
|
||||
* @var MockInterface The interface for L10n mocks
|
||||
*/
|
||||
private $l10nMock;
|
||||
|
||||
/**
|
||||
* Mocking the 'L10n::t()' method
|
||||
*
|
||||
* @param null|string $input Either an input (string) or null for EVERY input is possible
|
||||
* @param null|int $times How often will it get called
|
||||
* @param null|string $return Either an return (string) or null for return the input
|
||||
*/
|
||||
public function mockL10nT($input = null, $times = null, $return = null)
|
||||
{
|
||||
if (!isset($this->l10nMock)) {
|
||||
$this->l10nMock = \Mockery::mock('alias:' . L10n::class);
|
||||
}
|
||||
|
||||
$with = isset($input) ? $input : \Mockery::any();
|
||||
|
||||
$return = isset($return) ? $return : $with;
|
||||
|
||||
if ($return instanceof \Mockery\Matcher\Any) {
|
||||
$this->l10nMock
|
||||
->shouldReceive('t')
|
||||
->with($with)
|
||||
->times($times)
|
||||
->andReturnUsing(function($arg) { return $arg; });
|
||||
} else {
|
||||
$this->l10nMock
|
||||
->shouldReceive('t')
|
||||
->with($with)
|
||||
->times($times)
|
||||
->andReturn($return);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ namespace Friendica\Test;
|
|||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Config\Cache\PConfigCache;
|
||||
use Friendica\Core\L10n\L10n;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
|
@ -55,7 +56,10 @@ class ApiTest extends DatabaseTest
|
|||
$logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
|
||||
$baseUrl = new BaseURL($config, $_SERVER);
|
||||
$router = new App\Router();
|
||||
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, false);
|
||||
$l10n = new L10n(L10n::detectLanguage($config->get('system', 'language', 'en')),
|
||||
self::$dba,
|
||||
$logger);
|
||||
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, $l10n, false);
|
||||
|
||||
parent::setUp();
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@ namespace Friendica\Test\src\Console;
|
|||
use Friendica\Console\AutomaticInstallation;
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Core\Installer;
|
||||
use Friendica\Core\L10n\L10n;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Test\Util\DBAMockTrait;
|
||||
use Friendica\Test\Util\DBStructureMockTrait;
|
||||
use Friendica\Test\Util\L10nMockTrait;
|
||||
use Friendica\Test\Util\RendererMockTrait;
|
||||
use Friendica\Util\BaseURL;
|
||||
use Friendica\Util\Logger\VoidLogger;
|
||||
|
@ -20,7 +20,6 @@ use org\bovigo\vfs\vfsStreamFile;
|
|||
*/
|
||||
class AutomaticInstallationConsoleTest extends ConsoleTest
|
||||
{
|
||||
use L10nMockTrait;
|
||||
use DBAMockTrait;
|
||||
use DBStructureMockTrait;
|
||||
use RendererMockTrait;
|
||||
|
@ -50,7 +49,9 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
|
|||
->removeChild('local.config.php');
|
||||
}
|
||||
|
||||
$this->mockL10nT();
|
||||
$l10nMock = \Mockery::mock(L10n::class);
|
||||
$l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
\Friendica\Core\L10n::init($l10nMock);
|
||||
|
||||
$this->configCache = new ConfigCache();
|
||||
$this->configCache->set('system', 'basepath', $this->root->url());
|
||||
|
@ -72,7 +73,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
|
|||
return $this->configCache->get($cat, $key);
|
||||
});
|
||||
$this->configMock->shouldReceive('load')->andReturnUsing(function ($config, $overwrite = false) {
|
||||
return $this->configCache->load($config, $overwrite);
|
||||
$this->configCache->load($config, $overwrite);
|
||||
});
|
||||
|
||||
$this->mode->shouldReceive('isInstall')->andReturn(true);
|
||||
|
|
|
@ -1,69 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: benlo
|
||||
* Date: 25/03/19
|
||||
* Time: 21:36
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Content;
|
||||
|
||||
use Friendica\Content\Smilies;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\AppMockTrait;
|
||||
use Friendica\Test\Util\L10nMockTrait;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
|
||||
class SmiliesTest extends MockedTest
|
||||
{
|
||||
use VFSTrait;
|
||||
use AppMockTrait;
|
||||
use L10nMockTrait;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setUpVfsDir();
|
||||
$this->mockApp($this->root);
|
||||
$this->app->videowidth = 425;
|
||||
$this->app->videoheight = 350;
|
||||
$this->configMock->shouldReceive('get')
|
||||
->with('system', 'no_smilies')
|
||||
->andReturn(false);
|
||||
$this->configMock->shouldReceive('get')
|
||||
->with(false, 'system', 'no_smilies')
|
||||
->andReturn(false);
|
||||
}
|
||||
|
||||
public function dataLinks()
|
||||
{
|
||||
return [
|
||||
/** @see https://github.com/friendica/friendica/pull/6933 */
|
||||
'bug-6933-1' => [
|
||||
'data' => '<code>/</code>',
|
||||
'smilies' => ['texts' => [], 'icons' => []],
|
||||
'expected' => '<code>/</code>',
|
||||
],
|
||||
'bug-6933-2' => [
|
||||
'data' => '<code>code</code>',
|
||||
'smilies' => ['texts' => [], 'icons' => []],
|
||||
'expected' => '<code>code</code>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test replace smilies in different texts
|
||||
* @dataProvider dataLinks
|
||||
*
|
||||
* @param string $text Test string
|
||||
* @param array $smilies List of smilies to replace
|
||||
* @param string $expected Expected result
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function testReplaceFromArray($text, $smilies, $expected)
|
||||
{
|
||||
$output = Smilies::replaceFromArray($text, $smilies);
|
||||
$this->assertEquals($expected, $output);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: benlo
|
||||
* Date: 25/03/19
|
||||
* Time: 21:36
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Content;
|
||||
|
||||
use Friendica\Content\Smilies;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\AppMockTrait;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
|
||||
class SmiliesTest extends MockedTest
|
||||
{
|
||||
use VFSTrait;
|
||||
use AppMockTrait;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setUpVfsDir();
|
||||
$this->mockApp($this->root);
|
||||
$this->app->videowidth = 425;
|
||||
$this->app->videoheight = 350;
|
||||
$this->configMock->shouldReceive('get')
|
||||
->with('system', 'no_smilies')
|
||||
->andReturn(false);
|
||||
$this->configMock->shouldReceive('get')
|
||||
->with(false, 'system', 'no_smilies')
|
||||
->andReturn(false);
|
||||
}
|
||||
|
||||
public function dataLinks()
|
||||
{
|
||||
return [
|
||||
/** @see https://github.com/friendica/friendica/pull/6933 */
|
||||
'bug-6933-1' => [
|
||||
'data' => '<code>/</code>',
|
||||
'smilies' => ['texts' => [], 'icons' => []],
|
||||
'expected' => '<code>/</code>',
|
||||
],
|
||||
'bug-6933-2' => [
|
||||
'data' => '<code>code</code>',
|
||||
'smilies' => ['texts' => [], 'icons' => []],
|
||||
'expected' => '<code>code</code>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test replace smilies in different texts
|
||||
* @dataProvider dataLinks
|
||||
*
|
||||
* @param string $text Test string
|
||||
* @param array $smilies List of smilies to replace
|
||||
* @param string $expected Expected result
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function testReplaceFromArray($text, $smilies, $expected)
|
||||
{
|
||||
$output = Smilies::replaceFromArray($text, $smilies);
|
||||
$this->assertEquals($expected, $output);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,20 +3,15 @@
|
|||
namespace Friendica\Test\src\Content\Text;
|
||||
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\L10n\L10n;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\AppMockTrait;
|
||||
use Friendica\Test\Util\L10nMockTrait;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class BBCodeTest extends MockedTest
|
||||
{
|
||||
use VFSTrait;
|
||||
use AppMockTrait;
|
||||
use L10nMockTrait;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
|
@ -43,7 +38,11 @@ class BBCodeTest extends MockedTest
|
|||
$this->configMock->shouldReceive('get')
|
||||
->with('system', 'no_smilies')
|
||||
->andReturn(false);
|
||||
$this->mockL10nT();
|
||||
|
||||
$l10nMock = \Mockery::mock(L10n::class);
|
||||
$l10nMock->shouldReceive('t')->withAnyArgs()->andReturnUsing(function ($args) { return $args; });
|
||||
\Friendica\Core\L10n::init($l10nMock);
|
||||
|
||||
}
|
||||
|
||||
public function dataLinks()
|
||||
|
|
|
@ -7,24 +7,32 @@ use Friendica\Core\Config\Cache\ConfigCache;
|
|||
use Friendica\Network\CurlResult;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\L10nMockTrait;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Friendica\Util\Network;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class InstallerTest extends MockedTest
|
||||
{
|
||||
use VFSTrait;
|
||||
use L10nMockTrait;
|
||||
|
||||
/**
|
||||
* @var \Friendica\Core\L10n\L10n|MockInterface
|
||||
*/
|
||||
private $l10nMock;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->setUpVfsDir();
|
||||
|
||||
$this->l10nMock = \Mockery::mock(\Friendica\Core\L10n\L10n::class);
|
||||
L10n::init($this->l10nMock);
|
||||
}
|
||||
|
||||
private function mockL10nT(string $text, $times = null)
|
||||
{
|
||||
$this->l10nMock->shouldReceive('t')->with($text, [])->andReturn($text)->times($times);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,7 +113,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckKeys()
|
||||
{
|
||||
$this->mockL10nT();
|
||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
$this->setFunctions(['openssl_pkey_new' => false]);
|
||||
$install = new Installer();
|
||||
|
@ -229,7 +237,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckLocalIni()
|
||||
{
|
||||
$this->mockL10nT();
|
||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
$this->assertTrue($this->root->hasChild('config/local.config.php'));
|
||||
|
||||
|
@ -246,10 +254,12 @@ class InstallerTest extends MockedTest
|
|||
|
||||
/**
|
||||
* @small
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testCheckHtAccessFail()
|
||||
{
|
||||
$this->mockL10nT();
|
||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
// Mocking the CURL Response
|
||||
$curlResult = \Mockery::mock(CurlResult::class);
|
||||
|
@ -285,10 +295,12 @@ class InstallerTest extends MockedTest
|
|||
|
||||
/**
|
||||
* @small
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testCheckHtAccessWork()
|
||||
{
|
||||
$this->mockL10nT();
|
||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
// Mocking the failed CURL Response
|
||||
$curlResultF = \Mockery::mock(CurlResult::class);
|
||||
|
@ -326,10 +338,12 @@ class InstallerTest extends MockedTest
|
|||
|
||||
/**
|
||||
* @small
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testImagick()
|
||||
{
|
||||
$this->mockL10nT();
|
||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
$imageMock = \Mockery::mock('alias:'. Image::class);
|
||||
$imageMock
|
||||
|
@ -353,10 +367,12 @@ class InstallerTest extends MockedTest
|
|||
|
||||
/**
|
||||
* @small
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testImagickNotFound()
|
||||
{
|
||||
$this->mockL10nT();
|
||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
$imageMock = \Mockery::mock('alias:' . Image::class);
|
||||
$imageMock
|
||||
|
@ -399,7 +415,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testSetUpCache()
|
||||
{
|
||||
$this->mockL10nT();
|
||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
$install = new Installer();
|
||||
$configCache = \Mockery::mock(ConfigCache::class);
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Friendica\Test\src\Database;
|
|||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Config\Cache\PConfigCache;
|
||||
use Friendica\Core\L10n\L10n;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Factory;
|
||||
use Friendica\Test\DatabaseTest;
|
||||
|
@ -20,7 +21,10 @@ class DBATest extends DatabaseTest
|
|||
$logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
|
||||
$baseUrl = new BaseURL($config, $_SERVER);
|
||||
$router = new App\Router();
|
||||
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, false);
|
||||
$l10n = new L10n(L10n::detectLanguage($config->get('system', 'language', 'en')),
|
||||
self::$dba,
|
||||
$logger);
|
||||
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, $l10n, false);
|
||||
|
||||
parent::setUp();
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Friendica\Test\src\Database;
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config\Cache\PConfigCache;
|
||||
use Friendica\Core\L10n\L10n;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\Factory;
|
||||
use Friendica\Model\Config\Config;
|
||||
|
@ -24,8 +25,10 @@ class DBStructureTest extends DatabaseTest
|
|||
$logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
|
||||
$baseUrl = new BaseURL($config, $_SERVER);
|
||||
$router = new App\Router();
|
||||
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, false);
|
||||
|
||||
$l10n = new L10n(L10n::detectLanguage($config->get('system', 'language', 'en')),
|
||||
self::$dba,
|
||||
$logger);
|
||||
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, $l10n, false);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue