3 * @copyright Copyright (C) 2020, Friendica
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\Content;
24 use Friendica\Test\MockedTest;
26 class PageInfoTest extends MockedTest
28 public function dataGetRelevantUrlFromBody()
32 'expected' => 'http://example.com/end-of-content',
33 'body' => 'Content[url]http://example.com/end-of-content[/url]',
36 'expected' => 'http://example.com/tag-no-attr',
37 'body' => '[url]http://example.com/tag-no-attr[/url]',
40 'expected' => 'http://example.com/tag-attr',
41 'body' => '[url=http://example.com/tag-attr]Example.com[/url]',
45 'body' => '@[url=http://example.com/mention]Mention[/url]',
47 'mention-exclusive' => [
49 'body' => '@[url=http://example.com/mention-exclusive]Mention Exclusive[/url]',
53 'body' => '#[url=http://example.com/hashtag]hashtag[/url]',
55 'naked-url-unexpected' => [
57 'body' => 'http://example.com/naked-url-unexpected',
59 'naked-url-expected' => [
60 'expected' => 'http://example.com/naked-url-expected',
61 'body' => 'http://example.com/naked-url-expected',
62 'searchNakedUrls' => true,
64 'naked-url-end-of-content-unexpected' => [
66 'body' => 'Contenthttp://example.com/naked-url-end-of-content-unexpected',
67 'searchNakedUrls' => true,
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,
74 'bug-8781-schemeless-link' => [
76 'body' => '[url]/posts/2576978090fd0138ee4c005056264835[/url]',
82 * @dataProvider dataGetRelevantUrlFromBody
84 * @param string|null $expected
86 * @param bool $searchNakedUrls
88 public function testGetRelevantUrlFromBody($expected, string $body, bool $searchNakedUrls = false)
90 $this->assertSame($expected, PageInfoMock::getRelevantUrlFromBody($body, $searchNakedUrls));
93 public function dataStripTrailingUrlFromBody()
96 'naked-url-append' => [
97 'expected' => 'content',
98 'body' => 'contenthttps://example.com',
99 'url' => 'https://example.com',
101 'naked-url-not-at-the-end' => [
102 'expected' => 'https://example.comcontent',
103 'body' => 'https://example.comcontent',
104 'url' => 'https://example.com',
106 'bug-8781-labeled-link' => [
107 'expected' => 'link label',
108 'body' => '[url=https://example.com]link label[/url]',
109 'url' => 'https://example.com',
115 * @dataProvider dataStripTrailingUrlFromBody
117 * @param string $expected
118 * @param string $body
121 public function testStripTrailingUrlFromBody(string $expected, string $body, string $url)
123 $this->assertSame($expected, PageInfoMock::stripTrailingUrlFromBody($body, $url));