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