2018-11-29 05:47:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Lexer;
|
|
|
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use App\Util\Lexer\Autolink;
|
|
|
|
use App\Util\Lexer\Extractor;
|
|
|
|
|
|
|
|
class StatusLexerTest extends TestCase
|
|
|
|
{
|
|
|
|
public $status;
|
|
|
|
public $entities;
|
|
|
|
public $autolink;
|
|
|
|
|
2019-02-27 20:04:40 +00:00
|
|
|
public function setUp(): void
|
2018-11-29 05:47:39 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->status = "@pixelfed hi, really like the website! #píxelfed";
|
|
|
|
$this->entities = Extractor::create()->extract($this->status);
|
|
|
|
$this->autolink = Autolink::create()->autolink($this->status);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLexerExtractor()
|
|
|
|
{
|
|
|
|
$expected = [
|
|
|
|
"hashtags" => [
|
|
|
|
"píxelfed",
|
|
|
|
],
|
|
|
|
"urls" => [],
|
|
|
|
"mentions" => [
|
|
|
|
"pixelfed",
|
|
|
|
],
|
|
|
|
"replyto" => "pixelfed",
|
|
|
|
"hashtags_with_indices" => [
|
|
|
|
[
|
|
|
|
"hashtag" => "píxelfed",
|
|
|
|
"indices" => [
|
|
|
|
39,
|
|
|
|
48,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
"urls_with_indices" => [],
|
|
|
|
"mentions_with_indices" => [
|
|
|
|
[
|
|
|
|
"screen_name" => "pixelfed",
|
|
|
|
"indices" => [
|
|
|
|
0,
|
|
|
|
9,
|
|
|
|
],
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->assertEquals($this->entities, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAutolink()
|
|
|
|
{
|
2019-05-28 02:57:08 +00:00
|
|
|
$expected = '<a class="u-url mention" href="https://pixelfed.dev/pixelfed" rel="external nofollow noopener" target="_blank">@pixelfed</a> hi, really like the website! <a href="https://pixelfed.dev/discover/tags/píxelfed?src=hash" title="#píxelfed" class="u-url hashtag" rel="external nofollow noopener">#píxelfed</a>';
|
2018-11-29 05:47:39 +00:00
|
|
|
$this->assertEquals($this->autolink, $expected);
|
|
|
|
}
|
2019-05-21 01:43:38 +00:00
|
|
|
|
|
|
|
/** @test **/
|
|
|
|
public function remoteMention()
|
|
|
|
{
|
|
|
|
$expected = [
|
|
|
|
"hashtags" => [
|
|
|
|
"dansup",
|
|
|
|
],
|
|
|
|
"urls" => [],
|
|
|
|
"mentions" => [
|
|
|
|
"@dansup@mstdn.io",
|
|
|
|
"test",
|
|
|
|
],
|
|
|
|
"replyto" => null,
|
|
|
|
"hashtags_with_indices" => [
|
|
|
|
[
|
|
|
|
"hashtag" => "dansup",
|
|
|
|
"indices" => [
|
|
|
|
0,
|
|
|
|
7,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
"urls_with_indices" => [],
|
|
|
|
"mentions_with_indices" => [
|
|
|
|
[
|
|
|
|
"screen_name" => "@dansup@mstdn.io",
|
|
|
|
"indices" => [
|
|
|
|
8,
|
|
|
|
24,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"screen_name" => "test",
|
|
|
|
"indices" => [
|
|
|
|
25,
|
|
|
|
30,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$actual = Extractor::create()->extract('#dansup @dansup@mstdn.io @test');
|
|
|
|
$this->assertEquals($actual, $expected);
|
|
|
|
}
|
2018-11-29 05:47:39 +00:00
|
|
|
}
|