extract($username);
$autolink = Autolink::create()->autolink($username);
$expectedAutolink = '@dansup';
$expectedEntity = [
'hashtags' => [],
'urls' => [],
'mentions' => [
'dansup',
],
'replyto' => 'dansup',
'hashtags_with_indices' => [],
'urls_with_indices' => [],
'mentions_with_indices' => [
[
'screen_name' => 'dansup',
'indices' => [
0,
7,
],
],
],
];
$this->assertEquals($expectedAutolink, $autolink);
$this->assertEquals($expectedEntity, $entities);
}
#[Test]
public function username_with_period()
{
$username = '@dansup.two';
$autolink = Autolink::create()->autolink($username);
$entities = Extractor::create()->extract($username);
$expectedAutolink = '@dansup.two';
$expectedEntity = [
'hashtags' => [],
'urls' => [],
'mentions' => [
'dansup.two',
],
'replyto' => 'dansup.two',
'hashtags_with_indices' => [],
'urls_with_indices' => [],
'mentions_with_indices' => [
[
'screen_name' => 'dansup.two',
'indices' => [
0,
11,
],
],
],
];
$this->assertEquals($expectedAutolink, $autolink);
$this->assertEquals($expectedEntity, $entities);
}
#[Test]
public function username_with_dash()
{
$username = '@dansup-too';
$autolink = Autolink::create()->autolink($username);
$entities = Extractor::create()->extract($username);
$expectedAutolink = '@dansup-too';
$expectedEntity = [
'hashtags' => [],
'urls' => [],
'mentions' => [
'dansup-too',
],
'replyto' => 'dansup-too',
'hashtags_with_indices' => [],
'urls_with_indices' => [],
'mentions_with_indices' => [
[
'screen_name' => 'dansup-too',
'indices' => [
0,
11,
],
],
],
];
$this->assertEquals($expectedAutolink, $autolink);
$this->assertEquals($expectedEntity, $entities);
}
#[Test]
public function username_with_underscore()
{
$username = '@dansup_too';
$autolink = Autolink::create()->autolink($username);
$entities = Extractor::create()->extract($username);
$expectedAutolink = '@dansup_too';
$expectedEntity = [
'hashtags' => [],
'urls' => [],
'mentions' => [
'dansup_too',
],
'replyto' => 'dansup_too',
'hashtags_with_indices' => [],
'urls_with_indices' => [],
'mentions_with_indices' => [
[
'screen_name' => 'dansup_too',
'indices' => [
0,
11,
],
],
],
];
$this->assertEquals($expectedAutolink, $autolink);
$this->assertEquals($expectedEntity, $entities);
}
#[Test]
public function multiple_mentions()
{
$text = 'hello @dansup and @pixelfed.team from @username_underscore';
$autolink = Autolink::create()->autolink($text);
$entities = Extractor::create()->extract($text);
$expectedAutolink = 'hello @dansup and @pixelfed.team from @username_underscore';
$expectedEntity = [
'hashtags' => [],
'urls' => [],
'mentions' => [
'dansup',
'pixelfed.team',
'username_underscore',
],
'replyto' => null,
'hashtags_with_indices' => [],
'urls_with_indices' => [],
'mentions_with_indices' => [
[
'screen_name' => 'dansup',
'indices' => [
6,
13,
],
],
[
'screen_name' => 'pixelfed.team',
'indices' => [
18,
32,
],
],
[
'screen_name' => 'username_underscore',
'indices' => [
38,
58,
],
],
],
];
$this->assertEquals($expectedAutolink, $autolink);
$this->assertEquals($expectedEntity, $entities);
}
#[Test]
public function german_umlats_autolink()
{
$mentions = '@März and @königin and @Glück';
$autolink = Autolink::create()->autolink($mentions);
$expectedAutolink = '@März and @königin and @Glück';
$this->assertEquals($expectedAutolink, $autolink);
}
#[Test]
public function german_umlats_extractor()
{
$mentions = '@März and @königin and @Glück';
$entities = Extractor::create()->extract($mentions);
$expectedEntity = [
'hashtags' => [],
'urls' => [],
'mentions' => [
'märz',
'königin',
'glück',
],
'replyto' => null,
'hashtags_with_indices' => [],
'urls_with_indices' => [],
'mentions_with_indices' => [
[
'screen_name' => 'März',
'indices' => [
0,
5,
],
],
[
'screen_name' => 'königin',
'indices' => [
10,
18,
],
],
[
'screen_name' => 'Glück',
'indices' => [
23,
29,
],
],
],
];
$this->assertEquals($expectedEntity, $entities);
}
#[Test]
public function german_umlats_webfinger_autolink()
{
$mentions = 'hello @märz@example.org!';
$autolink = Autolink::create()->autolink($mentions);
$expectedAutolink = 'hello @märz@example.org!';
$this->assertEquals($expectedAutolink, $autolink);
}
}