. * * Created by PhpStorm. * User: benlo * Date: 25/03/19 * Time: 21:36 */ namespace Friendica\Test\src\Content; use Friendica\Content\Smilies; use Friendica\DI; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Test\FixtureTest; class SmiliesTest extends FixtureTest { protected function setUp(): void { parent::setUp(); DI::config()->set('system', 'no_smilies', false); } public function dataLinks() { return [ /** @see https://github.com/friendica/friendica/pull/6933 */ 'bug-6933-1' => [ 'data' => '/', 'smilies' => ['texts' => [], 'icons' => []], 'expected' => '/', ], 'bug-6933-2' => [ 'data' => 'code', 'smilies' => ['texts' => [], 'icons' => []], 'expected' => 'code', ], ]; } /** * Test replace smilies in different texts * * @dataProvider dataLinks * * @param string $text Test string * @param array $smilies List of smilies to replace * @param string $expected Expected result * * @throws InternalServerErrorException */ public function testReplaceFromArray(string $text, array $smilies, string $expected) { $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)); } }