mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-08 00:04:27 +02:00
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
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue