]> git.mxchange.org Git - friendica.git/blob - tests/src/Content/PageInfoTest.php
Deprecate page_info functions to new PageInfo class
[friendica.git] / tests / src / Content / PageInfoTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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\Content;
23
24 use Friendica\Test\MockedTest;
25
26 class PageInfoTest extends MockedTest
27 {
28         public function dataGetRelevantUrlFromBody()
29         {
30                 return [
31                         'end-of-content' => [
32                                 'expected' => 'http://example.com/end-of-content',
33                                 'body' => 'Content[url]http://example.com/end-of-content[/url]',
34                         ],
35                         'tag-no-attr' => [
36                                 'expected' => 'http://example.com/tag-no-attr',
37                                 'body' => '[url]http://example.com/tag-no-attr[/url]',
38                         ],
39                         'tag-attr' => [
40                                 'expected' => 'http://example.com/tag-attr',
41                                 'body' => '[url=http://example.com/tag-attr]Example.com[/url]',
42                         ],
43                         'mention' => [
44                                 'expected' => null,
45                                 'body' => '@[url=http://example.com/mention]Mention[/url]',
46                         ],
47                         'mention-exclusive' => [
48                                 'expected' => null,
49                                 'body' => '@[url=http://example.com/mention-exclusive]Mention Exclusive[/url]',
50                         ],
51                         'hashtag' => [
52                                 'expected' => null,
53                                 'body' => '#[url=http://example.com/hashtag]hashtag[/url]',
54                         ],
55                         'naked-url-unexpected' => [
56                                 'expected' => null,
57                                 'body' => 'http://example.com/naked-url-unexpected',
58                         ],
59                         'naked-url-expected' => [
60                                 'expected' => 'http://example.com/naked-url-expected',
61                                 'body' => 'http://example.com/naked-url-expected',
62                                 'searchNakedUrls' => true,
63                         ],
64                         'naked-url-end-of-content-unexpected' => [
65                                 'expected' => null,
66                                 'body' => 'Contenthttp://example.com/naked-url-end-of-content-unexpected',
67                                 'searchNakedUrls' => true,
68                         ],
69                         'naked-url-end-of-content-expected' => [
70                                 'expected' => 'http://example.com/naked-url-end-of-content-expected',
71                                 'body' => 'Content http://example.com/naked-url-end-of-content-expected',
72                                 'searchNakedUrls' => true,
73                         ],
74                         'bug-8781-schemeless-link' => [
75                                 'expected' => null,
76                                 'body' => '[url]/posts/2576978090fd0138ee4c005056264835[/url]',
77                         ],
78                 ];
79         }
80
81         /**
82          * @dataProvider dataGetRelevantUrlFromBody
83          *
84          * @param string|null $expected
85          * @param string      $body
86          * @param bool        $searchNakedUrls
87          */
88         public function testGetRelevantUrlFromBody($expected, string $body, bool $searchNakedUrls = false)
89         {
90                 $this->assertSame($expected, PageInfoMock::getRelevantUrlFromBody($body, $searchNakedUrls));
91         }
92
93         public function dataStripTrailingUrlFromBody()
94         {
95                 return [
96                         'naked-url-append' => [
97                                 'expected' => 'content',
98                                 'body' => 'contenthttps://example.com',
99                                 'url' => 'https://example.com',
100                         ],
101                         'naked-url-not-at-the-end' => [
102                                 'expected' => 'https://example.comcontent',
103                                 'body' => 'https://example.comcontent',
104                                 'url' => 'https://example.com',
105                         ],
106                         'bug-8781-labeled-link' => [
107                                 'expected' => 'link label',
108                                 'body' => '[url=https://example.com]link label[/url]',
109                                 'url' => 'https://example.com',
110                         ],
111                 ];
112         }
113
114         /**
115          * @dataProvider dataStripTrailingUrlFromBody
116          *
117          * @param string $expected
118          * @param string $body
119          * @param string $url
120          */
121         public function testStripTrailingUrlFromBody(string $expected, string $body, string $url)
122         {
123                 $this->assertSame($expected, PageInfoMock::stripTrailingUrlFromBody($body, $url));
124         }
125 }