]> git.mxchange.org Git - friendica.git/blob - tests/src/Content/Text/BBCodeTest.php
Merge pull request #6904 from MrPetovan/bug/6901-autolinker-fix-punctuation-domain
[friendica.git] / tests / src / Content / Text / BBCodeTest.php
1 <?php\r
2 \r
3 namespace Friendica\Test\src\Content\Text;\r
4 \r
5 use Friendica\Content\Text\BBCode;\r
6 use Friendica\Test\MockedTest;\r
7 use Friendica\Test\Util\AppMockTrait;\r
8 use Friendica\Test\Util\L10nMockTrait;\r
9 use Friendica\Test\Util\VFSTrait;\r
10 \r
11 /**\r
12  * @runTestsInSeparateProcesses\r
13  * @preserveGlobalState disabled\r
14  */\r
15 class BBCodeTest extends MockedTest\r
16 {\r
17         use VFSTrait;\r
18         use AppMockTrait;\r
19         use L10nMockTrait;\r
20 \r
21         protected function setUp()\r
22         {\r
23                 parent::setUp();\r
24                 $this->setUpVfsDir();\r
25                 $this->mockApp($this->root);\r
26                 $this->app->videowidth = 425;\r
27                 $this->app->videoheight = 350;\r
28                 $this->configMock->shouldReceive('get')\r
29                         ->with('system', 'remove_multiplicated_lines')\r
30                         ->andReturn(false);\r
31                 $this->configMock->shouldReceive('get')\r
32                         ->with('system', 'no_oembed')\r
33                         ->andReturn(false);\r
34                 $this->configMock->shouldReceive('get')\r
35                         ->with('system', 'allowed_link_protocols')\r
36                         ->andReturn(null);\r
37                 $this->configMock->shouldReceive('get')\r
38                         ->with('system', 'itemcache_duration')\r
39                         ->andReturn(-1);\r
40                 $this->mockL10nT();\r
41         }\r
42 \r
43         public function dataLinks()\r
44         {\r
45                 return [\r
46                         /** @see https://github.com/friendica/friendica/issues/2487 */\r
47                         'bug-2487-1' => [\r
48                                 'data' => 'https://de.wikipedia.org/wiki/Juha_Sipilä',\r
49                                 'assertHTML' => true,\r
50                         ],\r
51                         'bug-2487-2' => [\r
52                                 'data' => 'https://de.wikipedia.org/wiki/Dnepr_(Motorradmarke)',\r
53                                 'assertHTML' => true,\r
54                         ],\r
55                         'bug-2487-3' => [\r
56                                 'data' => 'https://friendica.wäckerlin.ch/friendica',\r
57                                 'assertHTML' => true,\r
58                         ],\r
59                         'bug-2487-4' => [\r
60                                 'data' => 'https://mastodon.social/@morevnaproject',\r
61                                 'assertHTML' => true,\r
62                         ],\r
63                         /** @see https://github.com/friendica/friendica/issues/5795 */\r
64                         'bug-5795' => [\r
65                                 'data' => 'https://social.nasqueron.org/@liw/100798039015010628',\r
66                                 'assertHTML' => true,\r
67                         ],\r
68                         /** @see https://github.com/friendica/friendica/issues/6095 */\r
69                         'bug-6095' => [\r
70                                 'data' => 'https://en.wikipedia.org/wiki/Solid_(web_decentralization_project)',\r
71                                 'assertHTML' => true,\r
72                         ],\r
73                         'no-protocol' => [\r
74                                 'data' => 'example.com/path',\r
75                                 'assertHTML' => false\r
76                         ],\r
77                         'wrong-protocol' => [\r
78                                 'data' => 'ftp://example.com',\r
79                                 'assertHTML' => false\r
80                         ],\r
81                         'wrong-domain-without-path' => [\r
82                                 'data' => 'http://example',\r
83                                 'assertHTML' => false\r
84                         ],\r
85                         'wrong-domain-with-path' => [\r
86                                 'data' => 'http://example/path',\r
87                                 'assertHTML' => false\r
88                         ],\r
89                         'bug-6857-domain-start' => [\r
90                                 'data' => "http://\nexample.com",\r
91                                 'assertHTML' => false\r
92                         ],\r
93                         'bug-6857-domain-end' => [\r
94                                 'data' => "http://example\n.com",\r
95                                 'assertHTML' => false\r
96                         ],\r
97                         'bug-6857-tld' => [\r
98                                 'data' => "http://example.\ncom",\r
99                                 'assertHTML' => false\r
100                         ],\r
101                         'bug-6857-end' => [\r
102                                 'data' => "http://example.com\ntest",\r
103                                 'assertHTML' => false\r
104                         ],\r
105                         'bug-6901' => [\r
106                                 'data' => "http://example.com<ul>",\r
107                                 'assertHTML' => false\r
108                         ],\r
109                 ];\r
110         }\r
111 \r
112         /**\r
113          * Test convert different links inside a text\r
114          * @dataProvider dataLinks\r
115          *\r
116          * @param string $data The data to text\r
117          * @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)\r
118          * @throws \Friendica\Network\HTTPException\InternalServerErrorException\r
119          */\r
120         public function testAutoLinking($data, $assertHTML)\r
121         {\r
122                 $output = BBCode::convert($data);\r
123                 $assert = '<a href="' . $data . '" target="_blank">' . $data . '</a>';\r
124                 if ($assertHTML) {\r
125                         $this->assertEquals($assert, $output);\r
126                 } else {\r
127                         $this->assertNotEquals($assert, $output);\r
128                 }\r
129         }\r
130 }\r