Fix code style

This commit is contained in:
Art4 2025-02-17 10:01:25 +00:00
parent 4f3349f6db
commit a94bead5f6

View file

@ -38,13 +38,13 @@ class SmiliesTest extends FixtureTestCase
return [ return [
/** @see https://github.com/friendica/friendica/pull/6933 */ /** @see https://github.com/friendica/friendica/pull/6933 */
'bug-6933-1' => [ 'bug-6933-1' => [
'data' => '<code>/</code>', 'data' => '<code>/</code>',
'smilies' => ['texts' => [], 'icons' => []], 'smilies' => ['texts' => [], 'icons' => []],
'expected' => '<code>/</code>', 'expected' => '<code>/</code>',
], ],
'bug-6933-2' => [ 'bug-6933-2' => [
'data' => '<code>code</code>', 'data' => '<code>code</code>',
'smilies' => ['texts' => [], 'icons' => []], 'smilies' => ['texts' => [], 'icons' => []],
'expected' => '<code>code</code>', 'expected' => '<code>code</code>',
], ],
]; ];
@ -72,56 +72,56 @@ class SmiliesTest extends FixtureTestCase
return [ return [
'emoji' => [ 'emoji' => [
'expected' => true, 'expected' => true,
'body' => '👀', 'body' => '👀',
], ],
'emojis' => [ 'emojis' => [
'expected' => true, 'expected' => true,
'body' => '👀🤷', 'body' => '👀🤷',
], ],
'emoji+whitespace' => [ 'emoji+whitespace' => [
'expected' => true, 'expected' => true,
'body' => ' 👀 ', 'body' => ' 👀 ',
], ],
'empty' => [ 'empty' => [
'expected' => false, 'expected' => false,
'body' => '', 'body' => '',
], ],
'whitespace' => [ 'whitespace' => [
'expected' => false, 'expected' => false,
'body' => ' 'body' => '
', ',
], ],
'emoji+ASCII' => [ 'emoji+ASCII' => [
'expected' => false, 'expected' => false,
'body' => '🤷a', 'body' => '🤷a',
], ],
'HTML entity whitespace' => [ 'HTML entity whitespace' => [
'expected' => false, 'expected' => false,
'body' => '&nbsp;', 'body' => '&nbsp;',
], ],
'HTML entity else' => [ 'HTML entity else' => [
'expected' => false, 'expected' => false,
'body' => '&deg;', 'body' => '&deg;',
], ],
'emojis+HTML whitespace' => [ 'emojis+HTML whitespace' => [
'expected' => true, 'expected' => true,
'body' => '👀&nbsp;🤷', 'body' => '👀&nbsp;🤷',
], ],
'emojis+HTML else' => [ 'emojis+HTML else' => [
'expected' => false, 'expected' => false,
'body' => '👀&lt;🤷', 'body' => '👀&lt;🤷',
], ],
'zwj' => [ 'zwj' => [
'expected' => true, 'expected' => true,
'body' => '👨‍👨‍👧‍', 'body' => '👨‍👨‍👧‍',
], ],
'zwj+whitespace' => [ 'zwj+whitespace' => [
'expected' => true, 'expected' => true,
'body' => ' 👨‍👨‍👧‍ ', 'body' => ' 👨‍👨‍👧‍ ',
], ],
'zwj+HTML whitespace' => [ 'zwj+HTML whitespace' => [
'expected' => true, 'expected' => true,
'body' => '&nbsp;👨‍👨‍👧‍&nbsp;', 'body' => '&nbsp;👨‍👨‍👧‍&nbsp;',
], ],
]; ];
} }
@ -139,59 +139,59 @@ class SmiliesTest extends FixtureTestCase
$data = [ $data = [
'simple-1' => [ 'simple-1' => [
'expected' => 'alt=":-p"', 'expected' => 'alt=":-p"',
'body' => ':-p', 'body' => ':-p',
], ],
'simple-2' => [ 'simple-2' => [
'expected' => 'alt=":-p"', 'expected' => 'alt=":-p"',
'body' => ' :-p ', 'body' => ' :-p ',
], ],
'word-boundary-1' => [ 'word-boundary-1' => [
'expected' => ':-pppp', 'expected' => ':-pppp',
'body' => ':-pppp', 'body' => ':-pppp',
], ],
'word-boundary-2' => [ 'word-boundary-2' => [
'expected' => '~friendicaca', 'expected' => '~friendicaca',
'body' => '~friendicaca', 'body' => '~friendicaca',
], ],
'symbol-boundary-1' => [ 'symbol-boundary-1' => [
'expected' => 'alt=":-p"', 'expected' => 'alt=":-p"',
'body' => '(:-p)', 'body' => '(:-p)',
], ],
'hearts-1' => [ 'hearts-1' => [
'expected' => '❤ (❤) ❤', 'expected' => '❤ (❤) ❤',
'body' => '&lt;3 (&lt;3) &lt;3', 'body' => '&lt;3 (&lt;3) &lt;3',
], ],
'hearts-8' => [ 'hearts-8' => [
'expected' => '(❤❤❤❤❤❤❤❤)', 'expected' => '(❤❤❤❤❤❤❤❤)',
'body' => '(&lt;33333333)', 'body' => '(&lt;33333333)',
], ],
'no-hearts-1' => [ 'no-hearts-1' => [
'expected' => '(&lt;30)', 'expected' => '(&lt;30)',
'body' => '(&lt;30)', 'body' => '(&lt;30)',
], ],
'no-hearts-2' => [ 'no-hearts-2' => [
'expected' => '(3&lt;33)', 'expected' => '(3&lt;33)',
'body' => '(3&lt;33)', 'body' => '(3&lt;33)',
], ],
'space' => [ 'space' => [
'expected' => 'alt="smiley-heart"', 'expected' => 'alt="smiley-heart"',
'body' => ':smiley heart 333:', 'body' => ':smiley heart 333:',
], ],
'substitution-1' => [ 'substitution-1' => [
'expected' => '&#x1F525;', 'expected' => '&#x1F525;',
'body' => '⽕', 'body' => '⽕',
], ],
'substitution-2' => [ 'substitution-2' => [
'expected' => '&#x1F917;', 'expected' => '&#x1F917;',
'body' => ':hugging face:', 'body' => ':hugging face:',
], ],
'substitution-3' => [ 'substitution-3' => [
'expected' => '&#x1F92D;', 'expected' => '&#x1F92D;',
'body' => ':face with hand over mouth:', 'body' => ':face with hand over mouth:',
], ],
'mixed' => [ 'mixed' => [
'expected' => '&#x1F525; &#x1F92D; invalid:hugging face: &#x1F917;', 'expected' => '&#x1F525; &#x1F92D; invalid:hugging face: &#x1F917;',
'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:', 'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
], ],
]; ];
@ -199,10 +199,10 @@ class SmiliesTest extends FixtureTestCase
foreach (['A', '_', ':', '-'] as $prefix) { foreach (['A', '_', ':', '-'] as $prefix) {
foreach (['', ' ', 'A', ':', '-'] as $suffix) { foreach (['', ' ', 'A', ':', '-'] as $suffix) {
$no_smile = ($prefix !== '' && ctype_alnum($prefix)) || ($suffix !== '' && ctype_alnum($suffix)); $no_smile = ($prefix !== '' && ctype_alnum($prefix)) || ($suffix !== '' && ctype_alnum($suffix));
$s = $prefix . $emoji . $suffix; $s = $prefix . $emoji . $suffix;
$data[] = [ $data[] = [
'expected' => $no_smile ? $s : 'alt="' . $emoji . '"', 'expected' => $no_smile ? $s : 'alt="' . $emoji . '"',
'body' => $s, 'body' => $s,
]; ];
} }
} }
@ -223,58 +223,58 @@ class SmiliesTest extends FixtureTestCase
{ {
return [ return [
'symbols' => [ 'symbols' => [
'expected' => ['p', 'heart', 'embarrassed', 'kiss'], 'expected' => ['p', 'heart', 'embarrassed', 'kiss'],
'body' => ':-p &lt;3 ":-[:-"', 'body' => ':-p &lt;3 ":-[:-"',
'normalized' => ':p: :heart: ":embarrassed::kiss:', 'normalized' => ':p: :heart: ":embarrassed::kiss:',
], ],
'single-smiley' => [ 'single-smiley' => [
'expected' => ['like'], 'expected' => ['like'],
'body' => ':like', 'body' => ':like',
'normalized' => ':like:', 'normalized' => ':like:',
], ],
'multiple-smilies' => [ 'multiple-smilies' => [
'expected' => ['like', 'dislike'], 'expected' => ['like', 'dislike'],
'body' => ':like :dislike', 'body' => ':like :dislike',
'normalized' => ':like: :dislike:', 'normalized' => ':like: :dislike:',
], ],
'nosmile' => [ 'nosmile' => [
'expected' => [], 'expected' => [],
'body' => '[nosmile] :like :like', 'body' => '[nosmile] :like :like',
'normalized' => '[nosmile] :like :like' 'normalized' => '[nosmile] :like :like'
], ],
'in-code' => [ 'in-code' => [
'expected' => [], 'expected' => [],
'body' => '[code]:like :like :like[/code]', 'body' => '[code]:like :like :like[/code]',
'normalized' => '[code]:like :like :like[/code]' 'normalized' => '[code]:like :like :like[/code]'
], ],
'~friendica' => [ '~friendica' => [
'expected' => ['friendica'], 'expected' => ['friendica'],
'body' => '~friendica', 'body' => '~friendica',
'normalized' => ':friendica:' 'normalized' => ':friendica:'
], ],
'space' => [ 'space' => [
'expected' => ['smileyheart333'], 'expected' => ['smileyheart333'],
'body' => ':smiley heart 333:', 'body' => ':smiley heart 333:',
'normalized' => ':smileyheart333:' 'normalized' => ':smileyheart333:'
], ],
'substitution-1' => [ 'substitution-1' => [
'expected' => [], 'expected' => [],
'body' => '⽕', 'body' => '⽕',
'normalized' => '&#x1F525;', 'normalized' => '&#x1F525;',
], ],
'substitution-2' => [ 'substitution-2' => [
'expected' => [], 'expected' => [],
'body' => ':hugging face:', 'body' => ':hugging face:',
'normalized' => '&#x1F917;', 'normalized' => '&#x1F917;',
], ],
'substitution-3' => [ 'substitution-3' => [
'expected' => [], 'expected' => [],
'body' => ':face with hand over mouth:', 'body' => ':face with hand over mouth:',
'normalized' => '&#x1F92D;', 'normalized' => '&#x1F92D;',
], ],
'mixed' => [ 'mixed' => [
'expected' => [], 'expected' => [],
'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:', 'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
'normalized' => '&#x1F525; &#x1F92D; invalid:hugging face: &#x1F917;', 'normalized' => '&#x1F525; &#x1F92D; invalid:hugging face: &#x1F917;',
], ],
]; ];
@ -286,7 +286,7 @@ class SmiliesTest extends FixtureTestCase
public function testExtractUsedSmilies(array $expected, string $body, string $normalized): void 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);
$this->assertEquals($normalized, $converted); $this->assertEquals($normalized, $converted);
foreach (array_keys($extracted) as $shortcode) { foreach (array_keys($extracted) as $shortcode) {
$this->assertArrayHasKey($shortcode, $expected); $this->assertArrayHasKey($shortcode, $expected);