]> git.mxchange.org Git - friendica.git/blob - tests/src/Protocol/ActivityPub/ProcessorTest.php
Merge remote-tracking branch 'upstream/develop' into inbox-gsid
[friendica.git] / tests / src / Protocol / ActivityPub / ProcessorTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Protocol\ActivityPub;
23
24 use PHPUnit\Framework\TestCase;
25
26 class ProcessorTest extends TestCase
27 {
28         public function dataNormalizeMentionLinks(): array
29         {
30                 return [
31                         'one-link-@' => [
32                                 'expected' => '@[url=https://example.com]Example[/url]',
33                                 'body'     => '[url=https://example.com]@Example[/url]',
34                         ],
35                         'one-link-#' => [
36                                 'expected' => '#[url=https://example.com]Example[/url]',
37                                 'body'     => '[url=https://example.com]#Example[/url]',
38                         ],
39                         'one-link-!' => [
40                                 'expected' => '![url=https://example.com]Example[/url]',
41                                 'body'     => '[url=https://example.com]!Example[/url]',
42                         ],
43                         'wrong-hash-char' => [
44                                 'expected' => '[url=https://example.com]%Example[/url]',
45                                 'body'     => '[url=https://example.com]%Example[/url]',
46                         ],
47                         'multiple-links' => [
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]',
50                         ],
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]',
54                         ],
55                         'mixed-format' => [
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]',
58                         ],
59                 ];
60         }
61
62         /**
63          * @dataProvider dataNormalizeMentionLinks
64          *
65          * @param string $expected
66          * @param string $body
67          */
68         public function testNormalizeMentionLinks(string $expected, string $body)
69         {
70                 $this->assertEquals($expected, ProcessorMock::normalizeMentionLinks($body));
71         }
72
73         public function dataAddMentionLinks(): array
74         {
75                 return [
76                         'issue-10603' => [
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 />',
79                                 'tags'     => [
80                                         [
81                                                 'type' => 'Mention',
82                                                 'href' => 'https://social.wake.st/users/liaizon',
83                                                 'name' => '@liaizon@social.wake.st'
84                                         ],
85                                         [
86                                                 'type' => 'Mention',
87                                                 'href' => 'https://friendica.mrpetovan.com/profile/hypolite',
88                                                 'name' => '@hypolite@friendica.mrpetovan.com'
89                                         ]
90                                 ],
91                         ],
92                         'issue-10617' => [
93                                 'expected' => '@[url=https://mastodon.technology/@sergey_m]sergey_m[/url]',
94                                 'body'     => '@[url=https://mastodon.technology/@sergey_m]sergey_m[/url]',
95                                 'tags'     => [
96                                         [
97                                                 'type' => 'Mention',
98                                                 'href' => 'https://mastodon.technology/@sergey_m',
99                                                 'name' => '@sergey_m'
100                                         ],
101                                 ],
102                         ],
103                 ];
104         }
105
106         /**
107          * @dataProvider dataAddMentionLinks
108          *
109          * @param string $expected
110          * @param string $body
111          * @param array $tags
112          */
113         public function testAddMentionLinks(string $expected, string $body, array $tags)
114         {
115                 $this->assertEquals($expected, ProcessorMock::addMentionLinks($body, $tags));
116         }
117 }