3 namespace Friendica\Test\src\Content\Text;
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;
12 * @runTestsInSeparateProcesses
13 * @preserveGlobalState disabled
15 class BBCodeTest extends MockedTest
21 protected function setUp()
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')
31 $this->configMock->shouldReceive('get')
32 ->with('system', 'no_oembed')
34 $this->configMock->shouldReceive('get')
35 ->with('system', 'allowed_link_protocols')
37 $this->configMock->shouldReceive('get')
38 ->with('system', 'itemcache_duration')
40 $this->configMock->shouldReceive('get')
41 ->with('system', 'url')
42 ->andReturn('friendica.local');
43 $this->configMock->shouldReceive('get')
44 ->with('system', 'no_smilies')
49 public function dataLinks()
52 /** @see https://github.com/friendica/friendica/issues/2487 */
54 'data' => 'https://de.wikipedia.org/wiki/Juha_Sipilä',
58 'data' => 'https://de.wikipedia.org/wiki/Dnepr_(Motorradmarke)',
62 'data' => 'https://friendica.wäckerlin.ch/friendica',
66 'data' => 'https://mastodon.social/@morevnaproject',
69 /** @see https://github.com/friendica/friendica/issues/5795 */
71 'data' => 'https://social.nasqueron.org/@liw/100798039015010628',
74 /** @see https://github.com/friendica/friendica/issues/6095 */
76 'data' => 'https://en.wikipedia.org/wiki/Solid_(web_decentralization_project)',
80 'data' => 'example.com/path',
84 'data' => 'ftp://example.com',
87 'wrong-domain-without-path' => [
88 'data' => 'http://example',
91 'wrong-domain-with-path' => [
92 'data' => 'http://example/path',
95 'bug-6857-domain-start' => [
96 'data' => "http://\nexample.com",
99 'bug-6857-domain-end' => [
100 'data' => "http://example\n.com",
101 'assertHTML' => false
104 'data' => "http://example.\ncom",
105 'assertHTML' => false
108 'data' => "http://example.com\ntest",
109 'assertHTML' => false
112 'data' => "http://example.com<ul>",
113 'assertHTML' => false
116 'data' => html_entity_decode('http://example.com ', ENT_QUOTES, 'UTF-8'),
117 'assertHTML' => false
119 'bug-7271-query-string-brackets' => [
120 'data' => 'https://example.com/search?q=square+brackets+[url]',
123 'bug-7271-path-brackets' => [
124 'data' => 'http://example.com/path/to/file[3].html',
131 * Test convert different links inside a text
132 * @dataProvider dataLinks
134 * @param string $data The data to text
135 * @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)
136 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
138 public function testAutoLinking($data, $assertHTML)
140 $output = BBCode::convert($data);
141 $assert = '<a href="' . $data . '" target="_blank">' . $data . '</a>';
143 $this->assertEquals($assert, $output);
145 $this->assertNotEquals($assert, $output);
149 public function dataBBCodes()
152 'bug-7271-condensed-space' => [
153 'expectedHtml' => '<ul class="listdecimal" style="list-style-type: decimal;"><li> <a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
154 'text' => '[ol][*] http://example.com/[/ol]',
156 'bug-7271-condensed-nospace' => [
157 'expectedHtml' => '<ul class="listdecimal" style="list-style-type: decimal;"><li><a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
158 'text' => '[ol][*]http://example.com/[/ol]',
160 'bug-7271-indented-space' => [
161 'expectedHtml' => '<ul class="listbullet" style="list-style-type: circle;"><li> <a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
163 [*] http://example.com/
166 'bug-7271-indented-nospace' => [
167 'expectedHtml' => '<ul class="listbullet" style="list-style-type: circle;"><li><a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
169 [*]http://example.com/
176 * Test convert bbcodes to HTML
177 * @dataProvider dataBBCodes
179 * @param string $expectedHtml Expected HTML output
180 * @param string $text BBCode text
181 * @param int $simpleHtml BBCode::convert method $simple_html parameter value, optional.
182 * @param bool $forPlaintext BBCode::convert method $for_plaintext parameter value, optional.
183 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
185 public function testConvert($expectedHtml, $text, $simpleHtml = 0, $forPlaintext = false)
187 $actual = BBCode::convert($text, false, $simpleHtml, $forPlaintext);
189 $this->assertEquals($expectedHtml, $actual);