Require whitespace around smilies and normalize federating text
This commit is contained in:
parent
2cb0027f56
commit
d45e9d6af2
9 changed files with 458 additions and 57 deletions
|
@ -112,6 +112,11 @@ return [
|
|||
'uri' => 'http://localhost/profile/mutualcontact',
|
||||
'guid' => '46',
|
||||
],
|
||||
[
|
||||
'id' => 100,
|
||||
'uri' => 'https://friendica.local/posts/100',
|
||||
'guid' => '100',
|
||||
],
|
||||
],
|
||||
'contact' => [
|
||||
[
|
||||
|
@ -363,6 +368,12 @@ return [
|
|||
'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
|
||||
'plink' => 'http://localhost/display/6',
|
||||
],
|
||||
[
|
||||
'uri-id' => 100,
|
||||
'title' => 'item_title',
|
||||
'body' => ':like ~friendica no [code]:dislike[/code] :-p :-[',
|
||||
'plink' => 'https://friendica.local/post/100',
|
||||
],
|
||||
],
|
||||
'post' => [
|
||||
[
|
||||
|
@ -744,6 +755,28 @@ return [
|
|||
'deleted' => 0,
|
||||
'wall' => 0,
|
||||
],
|
||||
// An emoji post
|
||||
[
|
||||
'id' => 14,
|
||||
'uri-id' => 100,
|
||||
'visible' => 1,
|
||||
'contact-id' => 44,
|
||||
'author-id' => 44,
|
||||
'owner-id' => 42,
|
||||
'causer-id' => 44,
|
||||
'uid' => 0,
|
||||
'vid' => 8,
|
||||
'unseen' => 0,
|
||||
'parent-uri-id' => 7,
|
||||
'thr-parent-id' => 7,
|
||||
'private' => Item::PUBLIC,
|
||||
'global' => true,
|
||||
'gravity' => Item::GRAVITY_PARENT,
|
||||
'network' => Protocol::DFRN,
|
||||
'origin' => 0,
|
||||
'deleted' => 0,
|
||||
'wall' => 0,
|
||||
],
|
||||
],
|
||||
'post-thread' => [
|
||||
[
|
||||
|
|
|
@ -143,4 +143,107 @@ class SmiliesTest extends FixtureTest
|
|||
{
|
||||
$this->assertEquals($expected, Smilies::isEmojiPost($body));
|
||||
}
|
||||
|
||||
|
||||
public function dataReplace(): array
|
||||
{
|
||||
return [
|
||||
'simple-1' => [
|
||||
'expected' => 'alt=":-p"',
|
||||
'body' => ':-p',
|
||||
],
|
||||
'simple-1' => [
|
||||
'expected' => 'alt=":-p"',
|
||||
'body' => ' :-p ',
|
||||
],
|
||||
'word-boundary-1' => [
|
||||
'expected' => ':-pppp',
|
||||
'body' => ':-pppp',
|
||||
],
|
||||
'word-boundary-2' => [
|
||||
'expected' => '~friendicaca',
|
||||
'body' => '~friendicaca',
|
||||
],
|
||||
'symbol-boundary-1' => [
|
||||
'expected' => '(:-p)',
|
||||
'body' => '(:-p)',
|
||||
],
|
||||
'hearts-1' => [
|
||||
'expected' => '❤ (❤) ❤',
|
||||
'body' => '<3 (<3) <3',
|
||||
],
|
||||
'hearts-8' => [
|
||||
'expected' => '(❤❤❤❤❤❤❤❤)',
|
||||
'body' => '(<33333333)',
|
||||
],
|
||||
'no-hearts-1' => [
|
||||
'expected' => '(<30)',
|
||||
'body' => '(<30)',
|
||||
],
|
||||
'no-hearts-2' => [
|
||||
'expected' => '(3<33)',
|
||||
'body' => '(3<33)',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataReplace
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $body
|
||||
*/
|
||||
public function testReplace(string $expected, string $body)
|
||||
{
|
||||
$result = Smilies::replace($body);
|
||||
$this->assertStringContainsString($expected, $result);
|
||||
}
|
||||
|
||||
public function dataExtractUsedSmilies(): array
|
||||
{
|
||||
return [
|
||||
'single-smiley' => [
|
||||
'expected' => ['like'],
|
||||
'body' => ':like',
|
||||
'normalized' => ':like:',
|
||||
],
|
||||
'multiple-smilies' => [
|
||||
'expected' => ['like', 'dislike'],
|
||||
'body' => ':like :dislike',
|
||||
'normalized' => ':like: :dislike:',
|
||||
],
|
||||
'nosmile' => [
|
||||
'expected' => [],
|
||||
'body' => '[nosmile] :like :like',
|
||||
'normalized' => '[nosmile] :like :like'
|
||||
],
|
||||
'in-code' => [
|
||||
'expected' => [],
|
||||
'body' => '[code]:like :like :like[/code]',
|
||||
'normalized' => '[code]:like :like :like[/code]'
|
||||
],
|
||||
'~friendica' => [
|
||||
'expected' => ['friendica'],
|
||||
'body' => '~friendica',
|
||||
'normalized' => ':friendica:'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataExtractUsedSmilies
|
||||
*
|
||||
* @param array $expected
|
||||
* @param string $body
|
||||
* @param stirng $normalized
|
||||
*/
|
||||
public function testExtractUsedSmilies(array $expected, string $body, string $normalized)
|
||||
{
|
||||
$extracted = Smilies::extractUsedSmilies($body);
|
||||
$this->assertEquals($normalized, $extracted['']);
|
||||
foreach ($expected as $shortcode) {
|
||||
$this->assertArrayHasKey($shortcode, $extracted);
|
||||
}
|
||||
$this->assertEquals(count($expected), count($extracted) - 1);
|
||||
}
|
||||
}
|
||||
|
|
45
tests/src/Factory/Api/Mastodon/EmojiTest.php
Normal file
45
tests/src/Factory/Api/Mastodon/EmojiTest.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\Content\Smilies;
|
||||
use Friendica\DI;
|
||||
use Friendica\Test\FixtureTest;
|
||||
|
||||
class EmojiTest extends FixtureTest
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
DI::config()->set('system', 'no_smilies', false);
|
||||
}
|
||||
|
||||
public function testBuiltInCollection()
|
||||
{
|
||||
$emoji = DI::mstdnEmoji();
|
||||
$collection = $emoji->createCollectionFromSmilies(Smilies::getList())->getArrayCopy(true);
|
||||
foreach ($collection as $item) {
|
||||
$this->assertTrue(preg_match('(/images/.*)', $item['url']) === 1, $item['url']);
|
||||
}
|
||||
}
|
||||
}
|
61
tests/src/Factory/Api/Mastodon/StatusTest.php
Normal file
61
tests/src/Factory/Api/Mastodon/StatusTest.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\DI;
|
||||
use Friendica\Test\FixtureTest;
|
||||
|
||||
class StatusTest extends FixtureTest
|
||||
{
|
||||
protected $status;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
DI::config()->set('system', 'no_smilies', false);
|
||||
$this->status = DI::mstdnStatus();
|
||||
}
|
||||
|
||||
public function testSimpleStatus()
|
||||
{
|
||||
$post = Post::selectFirst([], ['id' => 13]);
|
||||
$this->assertNotNull($post);
|
||||
$result = $this->status->createFromUriId($post['uri-id']);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
|
||||
public function testSimpleEmojiStatus()
|
||||
{
|
||||
$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(count($emojis), count($result['emojis']));
|
||||
foreach ($result['emojis'] as $emoji) {
|
||||
$this->assertTrue(array_key_exists($emoji['shortcode'], $emojis));
|
||||
$this->assertEquals(0, strpos($emoji['url'], 'http'));
|
||||
}
|
||||
}
|
||||
}
|
53
tests/src/Protocol/ActivityPub/TransmitterTest.php
Normal file
53
tests/src/Protocol/ActivityPub/TransmitterTest.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Protocol\ActivityPub;
|
||||
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Protocol\ActivityPub\Transmitter;
|
||||
use Friendica\Test\FixtureTest;
|
||||
|
||||
class TransmitterTest extends FixtureTest
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
DI::config()->set('system', 'no_smilies', false);
|
||||
}
|
||||
|
||||
public function testEmojiPost()
|
||||
{
|
||||
$post = Post::selectFirst([], ['id' => 14]);
|
||||
$this->assertNotNull($post);
|
||||
$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(count($emojis), count($note['tag']));
|
||||
foreach ($note['tag'] as $emoji) {
|
||||
$this->assertTrue(array_key_exists($emoji['name'], $emojis));
|
||||
$this->assertEquals('Emoji', $emoji['type']);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue