3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\src\Protocol\ActivityPub;
24 use PHPUnit\Framework\TestCase;
26 class ProcessorTest extends TestCase
28 public function dataNormalizeMentionLinks(): array
32 'expected' => '@[url=https://example.com]Example[/url]',
33 'body' => '[url=https://example.com]@Example[/url]',
36 'expected' => '#[url=https://example.com]Example[/url]',
37 'body' => '[url=https://example.com]#Example[/url]',
40 'expected' => '![url=https://example.com]Example[/url]',
41 'body' => '[url=https://example.com]!Example[/url]',
43 'wrong-hash-char' => [
44 'expected' => '[url=https://example.com]%Example[/url]',
45 'body' => '[url=https://example.com]%Example[/url]',
48 'expected' => '@[url=https://example.com]Example[/url] #[url=https://example.com]Example[/url] ![url=https://example.com]Example[/url]',
49 'body' => '[url=https://example.com]@Example[/url] [url=https://example.com]#Example[/url] [url=https://example.com]!Example[/url]',
51 'already-correct-format' => [
52 'expected' => '@[url=https://example.com]Example[/url] #[url=https://example.com]Example[/url] ![url=https://example.com]Example[/url]',
53 'body' => '@[url=https://example.com]Example[/url] #[url=https://example.com]Example[/url] ![url=https://example.com]Example[/url]',
56 'expected' => '@[url=https://example.com]Example[/url] #[url=https://example.com]Example[/url] ![url=https://example.com]Example[/url] @[url=https://example.com]Example[/url] #[url=https://example.com]Example[/url] ![url=https://example.com]Example[/url]',
57 'body' => '[url=https://example.com]@Example[/url] [url=https://example.com]#Example[/url] [url=https://example.com]!Example[/url] @[url=https://example.com]Example[/url] #[url=https://example.com]Example[/url] ![url=https://example.com]Example[/url]',
63 * @dataProvider dataNormalizeMentionLinks
65 * @param string $expected
68 public function testNormalizeMentionLinks(string $expected, string $body)
70 $this->assertEquals($expected, ProcessorMock::normalizeMentionLinks($body));
73 public function dataAddMentionLinks(): array
77 'expected' => '@[url=https://social.wake.st/users/liaizon]liaizon@social.wake.st[/url] @[url=https://friendica.mrpetovan.com/profile/hypolite]hypolite@friendica.mrpetovan.com[/url] yes<br /><br />',
78 'body' => '@liaizon@social.wake.st @hypolite@friendica.mrpetovan.com yes<br /><br />',
82 'href' => 'https://social.wake.st/users/liaizon',
83 'name' => '@liaizon@social.wake.st'
87 'href' => 'https://friendica.mrpetovan.com/profile/hypolite',
88 'name' => '@hypolite@friendica.mrpetovan.com'
93 'expected' => '@[url=https://mastodon.technology/@sergey_m]sergey_m[/url]',
94 'body' => '@[url=https://mastodon.technology/@sergey_m]sergey_m[/url]',
98 'href' => 'https://mastodon.technology/@sergey_m',
107 * @dataProvider dataAddMentionLinks
109 * @param string $expected
110 * @param string $body
113 public function testAddMentionLinks(string $expected, string $body, array $tags)
115 $this->assertEquals($expected, ProcessorMock::addMentionLinks($body, $tags));