]> git.mxchange.org Git - friendica.git/blob - tests/src/Content/Text/BBCodeTest.php
f155eeee3d99a57cff3bcdf0034094f2981377aa
[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                 ];\r
90         }\r
91 \r
92         /**\r
93          * Test convert different links inside a text\r
94          * @dataProvider dataLinks\r
95          *\r
96          * @param string $data The data to text\r
97          * @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)\r
98          * @throws \Friendica\Network\HTTPException\InternalServerErrorException\r
99          */\r
100         public function testAutoLinking($data, $assertHTML)\r
101         {\r
102                 $output = BBCode::convert($data);\r
103                 if ($assertHTML) {\r
104                         $assert = '<a href="' . $data . '" target="_blank">' . $data . '</a>';\r
105                 } else {\r
106                         $assert = $data;\r
107                 }\r
108 \r
109                 $this->assertEquals($assert, $output);\r
110         }\r
111 }