/**
* Checks if the body only contains 4 byte unicode characters.
*
- * @param string $body
+ * @param string $body Possibly-HTML post body
* @return boolean
*/
public static function isEmojiPost(string $body): bool
{
+ // Strips all whitespace
$conv = preg_replace('#\s#u', '', html_entity_decode($body));
// Emojis are always 4 byte Unicode characters
return (!empty($conv) && (strlen($conv) / mb_strlen($conv) == 4));
$output = Smilies::replaceFromArray($text, $smilies);
self::assertEquals($expected, $output);
}
+
+ public function dataIsEmojiPost(): array
+ {
+ return [
+ 'emoji' => [
+ 'expected' => true,
+ 'body' => '๐',
+ ],
+ 'emojis' => [
+ 'expected' => true,
+ 'body' => '๐๐คท',
+ ],
+ 'emoji+whitespace' => [
+ 'expected' => true,
+ 'body' => ' ๐ ',
+ ],
+ 'empty' => [
+ 'expected' => false,
+ 'body' => '',
+ ],
+ 'whitespace' => [
+ 'expected' => false,
+ 'body' => '
+ ',
+ ],
+ 'emoji+ASCII' => [
+ 'expected' => false,
+ 'body' => '๐คทa',
+ ],
+ 'HTML entity whitespace' => [
+ 'expected' => false,
+ 'body' => ' ',
+ ],
+ 'HTML entity else' => [
+ 'expected' => false,
+ 'body' => '°',
+ ],
+ 'emojis+HTML whitespace' => [
+ 'expected' => true,
+ 'body' => '๐ ๐คท',
+ ],
+ 'emojis+HTML else' => [
+ 'expected' => false,
+ 'body' => '๐<๐คท',
+ ],
+ 'zwj' => [
+ 'expected' => true,
+ 'body' => '๐จโ๐จโ๐งโ',
+ ],
+ 'zwj+whitespace' => [
+ 'expected' => true,
+ 'body' => ' ๐จโ๐จโ๐งโ ',
+ ],
+ 'zwj+HTML whitespace' => [
+ 'expected' => true,
+ 'body' => ' ๐จโ๐จโ๐งโ ',
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataIsEmojiPost
+ *
+ * @param bool $expected
+ * @param string $body
+ * @return void
+ */
+ public function testIsEmojiPost(bool $expected, string $body)
+ {
+ $this->assertEquals($expected, Smilies::isEmojiPost($body));
+ }
}