Fix substituting smilies and smilies containing whitespaces
This commit is contained in:
parent
5c3227ac4c
commit
37188c76b8
6 changed files with 154 additions and 91 deletions
36
tests/Util/SmileyWhitespaceAddon.php
Normal file
36
tests/Util/SmileyWhitespaceAddon.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Friendica\Content\Smilies;
|
||||
|
||||
function add_test_unicode_smilies(array &$b)
|
||||
{
|
||||
// String-substitution smilies
|
||||
// - no whitespaces
|
||||
Smilies::add($b, '⽕', '🔥');
|
||||
// - with whitespaces
|
||||
Smilies::add($b, ':hugging face:', '🤗');
|
||||
// - with multiple whitespaces
|
||||
Smilies::add($b, ':face with hand over mouth:', '🤭');
|
||||
// Image-based smilies
|
||||
// - with whitespaces
|
||||
Smilies::add($b, ':smiley heart 333:', '<img class="smiley" src="/images/smiley-heart.gif" alt="smiley-heart" title="smiley-heart" />');
|
||||
}
|
|
@ -371,7 +371,7 @@ return [
|
|||
[
|
||||
'uri-id' => 100,
|
||||
'title' => 'item_title',
|
||||
'body' => ':like ~friendica no [code]:dislike[/code] :-p :-[ <3',
|
||||
'body' => ':like ~friendica no [code]:dislike[/code] :-p :-[ :hugging face: <3 :smiley heart 333: ⽕',
|
||||
'plink' => 'https://friendica.local/post/100',
|
||||
],
|
||||
],
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
namespace Friendica\Test\src\Content;
|
||||
|
||||
use Friendica\Content\Smilies;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Test\FixtureTest;
|
||||
|
@ -37,6 +38,9 @@ class SmiliesTest extends FixtureTest
|
|||
parent::setUp();
|
||||
|
||||
DI::config()->set('system', 'no_smilies', false);
|
||||
|
||||
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
||||
Hook::loadHooks();
|
||||
}
|
||||
|
||||
public function dataLinks()
|
||||
|
@ -184,6 +188,26 @@ class SmiliesTest extends FixtureTest
|
|||
'expected' => '(3<33)',
|
||||
'body' => '(3<33)',
|
||||
],
|
||||
'space' => [
|
||||
'expected' => 'alt="smiley-heart"',
|
||||
'body' => ':smiley heart 333:',
|
||||
],
|
||||
'substitution-1' => [
|
||||
'expected' => '🔥',
|
||||
'body' => '⽕',
|
||||
],
|
||||
'substitution-2' => [
|
||||
'expected' => '🤗',
|
||||
'body' => ':hugging face:',
|
||||
],
|
||||
'substitution-3' => [
|
||||
'expected' => '🤭',
|
||||
'body' => ':face with hand over mouth:',
|
||||
],
|
||||
'mixed' => [
|
||||
'expected' => '🔥 🤭 invalid:hugging face: 🤗',
|
||||
'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
|
||||
],
|
||||
];
|
||||
foreach ([':-[', ':-D', 'o.O'] as $emoji) {
|
||||
foreach (['A', '_', ':', '-'] as $prefix) {
|
||||
|
@ -245,6 +269,31 @@ class SmiliesTest extends FixtureTest
|
|||
'body' => '~friendica',
|
||||
'normalized' => ':friendica:'
|
||||
],
|
||||
'space' => [
|
||||
'expected' => ['smileyheart333'],
|
||||
'body' => ':smiley heart 333:',
|
||||
'normalized' => ':smileyheart333:'
|
||||
],
|
||||
'substitution-1' => [
|
||||
'expected' => [],
|
||||
'body' => '⽕',
|
||||
'normalized' => '🔥',
|
||||
],
|
||||
'substitution-2' => [
|
||||
'expected' => [],
|
||||
'body' => ':hugging face:',
|
||||
'normalized' => '🤗',
|
||||
],
|
||||
'substitution-3' => [
|
||||
'expected' => [],
|
||||
'body' => ':face with hand over mouth:',
|
||||
'normalized' => '🤭',
|
||||
],
|
||||
'mixed' => [
|
||||
'expected' => [],
|
||||
'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
|
||||
'normalized' => '🔥 🤭 invalid:hugging face: 🤗',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,9 @@
|
|||
|
||||
namespace Friendica\Test\src\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Test\FixtureTest;
|
||||
|
||||
class StatusTest extends FixtureTest
|
||||
|
@ -35,6 +36,9 @@ class StatusTest extends FixtureTest
|
|||
|
||||
DI::config()->set('system', 'no_smilies', false);
|
||||
$this->status = DI::mstdnStatus();
|
||||
|
||||
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
||||
Hook::loadHooks();
|
||||
}
|
||||
|
||||
public function testSimpleStatus()
|
||||
|
@ -50,8 +54,8 @@ class StatusTest extends FixtureTest
|
|||
$post = Post::selectFirst([], ['id' => 14]);
|
||||
$this->assertNotNull($post);
|
||||
$result = $this->status->createFromUriId($post['uri-id'])->toArray();
|
||||
$this->assertEquals(':like: :friendica: no <code>:dislike</code> :p: :embarrassed: ❤', $result['content']);
|
||||
$emojis = array_fill_keys(['like', 'friendica', 'p', 'embarrassed'], true);
|
||||
$this->assertEquals(':like: :friendica: no <code>:dislike</code> :p: :embarrassed: 🤗 ❤ :smileyheart333: 🔥', $result['content']);
|
||||
$emojis = array_fill_keys(['like', 'friendica', 'p', 'embarrassed', 'smileyheart333'], true);
|
||||
$this->assertEquals(count($emojis), count($result['emojis']));
|
||||
foreach ($result['emojis'] as $emoji) {
|
||||
$this->assertTrue(array_key_exists($emoji['shortcode'], $emojis));
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace Friendica\Test\src\Protocol\ActivityPub;
|
||||
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Protocol\ActivityPub\Transmitter;
|
||||
|
@ -33,6 +34,9 @@ class TransmitterTest extends FixtureTest
|
|||
parent::setUp();
|
||||
|
||||
DI::config()->set('system', 'no_smilies', false);
|
||||
|
||||
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
||||
Hook::loadHooks();
|
||||
}
|
||||
|
||||
public function testEmojiPost()
|
||||
|
@ -42,8 +46,8 @@ class TransmitterTest extends FixtureTest
|
|||
$note = Transmitter::createNote($post);
|
||||
$this->assertNotNull($note);
|
||||
|
||||
$this->assertEquals(':like: :friendica: no <code>:dislike</code> :p: :embarrassed: ❤', $note['content']);
|
||||
$emojis = array_fill_keys(['like', 'friendica', 'p', 'embarrassed'], true);
|
||||
$this->assertEquals(':like: :friendica: no <code>:dislike</code> :p: :embarrassed: 🤗 ❤ :smileyheart333: 🔥', $note['content']);
|
||||
$emojis = array_fill_keys(['like', 'friendica', 'p', 'embarrassed', 'smileyheart333'], true);
|
||||
$this->assertEquals(count($emojis), count($note['tag']));
|
||||
foreach ($note['tag'] as $emoji) {
|
||||
$this->assertTrue(array_key_exists($emoji['name'], $emojis));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue