mirror of
https://github.com/friendica/friendica
synced 2025-03-12 23:25:07 +01:00
Fix smilies tests
This commit is contained in:
parent
d5f5ebbd8a
commit
94b47ae4d1
1 changed files with 15 additions and 18 deletions
|
@ -9,6 +9,7 @@ namespace Friendica\Test\src\Content;
|
||||||
|
|
||||||
use Friendica\Content\Smilies;
|
use Friendica\Content\Smilies;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
|
use Friendica\Core\Hooks\HookEventBridge;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Test\FixtureTestCase;
|
use Friendica\Test\FixtureTestCase;
|
||||||
|
@ -21,11 +22,18 @@ class SmiliesTest extends FixtureTestCase
|
||||||
|
|
||||||
DI::config()->set('system', 'no_smilies', false);
|
DI::config()->set('system', 'no_smilies', false);
|
||||||
|
|
||||||
|
/** @var \Friendica\Event\EventDispatcher */
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
foreach (HookEventBridge::getStaticSubscribedEvents() as $eventName => $methodName) {
|
||||||
|
$eventDispatcher->addListener($eventName, [HookEventBridge::class, $methodName]);
|
||||||
|
}
|
||||||
|
|
||||||
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
||||||
Hook::loadHooks();
|
Hook::loadHooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataLinks()
|
public function dataLinks(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
/** @see https://github.com/friendica/friendica/pull/6933 */
|
/** @see https://github.com/friendica/friendica/pull/6933 */
|
||||||
|
@ -53,7 +61,7 @@ class SmiliesTest extends FixtureTestCase
|
||||||
*
|
*
|
||||||
* @throws InternalServerErrorException
|
* @throws InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public function testReplaceFromArray(string $text, array $smilies, string $expected)
|
public function testReplaceFromArray(string $text, array $smilies, string $expected): void
|
||||||
{
|
{
|
||||||
$output = Smilies::replaceFromArray($text, $smilies);
|
$output = Smilies::replaceFromArray($text, $smilies);
|
||||||
self::assertEquals($expected, $output);
|
self::assertEquals($expected, $output);
|
||||||
|
@ -120,17 +128,12 @@ class SmiliesTest extends FixtureTestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataIsEmojiPost
|
* @dataProvider dataIsEmojiPost
|
||||||
*
|
|
||||||
* @param bool $expected
|
|
||||||
* @param string $body
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function testIsEmojiPost(bool $expected, string $body)
|
public function testIsEmojiPost(bool $expected, string $body): void
|
||||||
{
|
{
|
||||||
$this->assertEquals($expected, Smilies::isEmojiPost($body));
|
$this->assertEquals($expected, Smilies::isEmojiPost($body));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function dataReplace(): array
|
public function dataReplace(): array
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
@ -138,7 +141,7 @@ class SmiliesTest extends FixtureTestCase
|
||||||
'expected' => 'alt=":-p"',
|
'expected' => 'alt=":-p"',
|
||||||
'body' => ':-p',
|
'body' => ':-p',
|
||||||
],
|
],
|
||||||
'simple-1' => [
|
'simple-2' => [
|
||||||
'expected' => 'alt=":-p"',
|
'expected' => 'alt=":-p"',
|
||||||
'body' => ' :-p ',
|
'body' => ' :-p ',
|
||||||
],
|
],
|
||||||
|
@ -191,6 +194,7 @@ class SmiliesTest extends FixtureTestCase
|
||||||
'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
|
'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ([':-[', ':-D', 'o.O'] as $emoji) {
|
foreach ([':-[', ':-D', 'o.O'] as $emoji) {
|
||||||
foreach (['A', '_', ':', '-'] as $prefix) {
|
foreach (['A', '_', ':', '-'] as $prefix) {
|
||||||
foreach (['', ' ', 'A', ':', '-'] as $suffix) {
|
foreach (['', ' ', 'A', ':', '-'] as $suffix) {
|
||||||
|
@ -208,11 +212,8 @@ class SmiliesTest extends FixtureTestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataReplace
|
* @dataProvider dataReplace
|
||||||
*
|
|
||||||
* @param string $expected
|
|
||||||
* @param string $body
|
|
||||||
*/
|
*/
|
||||||
public function testReplace(string $expected, string $body)
|
public function testReplace(string $expected, string $body): void
|
||||||
{
|
{
|
||||||
$result = Smilies::replace($body);
|
$result = Smilies::replace($body);
|
||||||
$this->assertStringContainsString($expected, $result);
|
$this->assertStringContainsString($expected, $result);
|
||||||
|
@ -281,12 +282,8 @@ class SmiliesTest extends FixtureTestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataExtractUsedSmilies
|
* @dataProvider dataExtractUsedSmilies
|
||||||
*
|
|
||||||
* @param array $expected
|
|
||||||
* @param string $body
|
|
||||||
* @param stirng $normalized
|
|
||||||
*/
|
*/
|
||||||
public function testExtractUsedSmilies(array $expected, string $body, string $normalized)
|
public function testExtractUsedSmilies(array $expected, string $body, string $normalized): void
|
||||||
{
|
{
|
||||||
$extracted = Smilies::extractUsedSmilies($body, $converted);
|
$extracted = Smilies::extractUsedSmilies($body, $converted);
|
||||||
$expected = array_fill_keys($expected, true);
|
$expected = array_fill_keys($expected, true);
|
||||||
|
|
Loading…
Add table
Reference in a new issue