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');
46 public function dataLinks()
49 /** @see https://github.com/friendica/friendica/issues/2487 */
51 'data' => 'https://de.wikipedia.org/wiki/Juha_Sipilä',
55 'data' => 'https://de.wikipedia.org/wiki/Dnepr_(Motorradmarke)',
59 'data' => 'https://friendica.wäckerlin.ch/friendica',
63 'data' => 'https://mastodon.social/@morevnaproject',
66 /** @see https://github.com/friendica/friendica/issues/5795 */
68 'data' => 'https://social.nasqueron.org/@liw/100798039015010628',
71 /** @see https://github.com/friendica/friendica/issues/6095 */
73 'data' => 'https://en.wikipedia.org/wiki/Solid_(web_decentralization_project)',
77 'data' => 'example.com/path',
81 'data' => 'ftp://example.com',
84 'wrong-domain-without-path' => [
85 'data' => 'http://example',
88 'wrong-domain-with-path' => [
89 'data' => 'http://example/path',
92 'bug-6857-domain-start' => [
93 'data' => "http://\nexample.com",
96 'bug-6857-domain-end' => [
97 'data' => "http://example\n.com",
101 'data' => "http://example.\ncom",
102 'assertHTML' => false
105 'data' => "http://example.com\ntest",
106 'assertHTML' => false
109 'data' => "http://example.com<ul>",
110 'assertHTML' => false
113 'data' => html_entity_decode('http://example.com ', ENT_QUOTES, 'UTF-8'),
114 'assertHTML' => false
116 'bug-7271-query-string-brackets' => [
117 'data' => 'https://example.com/search?q=square+brackets+[url]',
120 'bug-7271-path-brackets' => [
121 'data' => 'http://example.com/path/to/file[3].html',
128 * Test convert different links inside a text
129 * @dataProvider dataLinks
131 * @param string $data The data to text
132 * @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)
133 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
135 public function testAutoLinking($data, $assertHTML)
137 $output = BBCode::convert($data);
138 $assert = '<a href="' . $data . '" target="_blank">' . $data . '</a>';
140 $this->assertEquals($assert, $output);
142 $this->assertNotEquals($assert, $output);
146 public function dataBBCodes()
149 'bug-7271-condensed-space' => [
150 'expectedHtml' => '<ul class="listdecimal" style="list-style-type: decimal;"><li> <a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
151 'text' => '[ol][*] http://example.com/[/ol]',
153 'bug-7271-condensed-nospace' => [
154 'expectedHtml' => '<ul class="listdecimal" style="list-style-type: decimal;"><li><a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
155 'text' => '[ol][*]http://example.com/[/ol]',
157 'bug-7271-indented-space' => [
158 'expectedHtml' => '<ul class="listbullet" style="list-style-type: circle;"><li> <a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
160 [*] http://example.com/
163 'bug-7271-indented-nospace' => [
164 'expectedHtml' => '<ul class="listbullet" style="list-style-type: circle;"><li><a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
166 [*]http://example.com/
173 * Test convert bbcodes to HTML
174 * @dataProvider dataBBCodes
176 * @param string $expectedHtml Expected HTML output
177 * @param string $text BBCode text
178 * @param int $simpleHtml BBCode::convert method $simple_html parameter value, optional.
179 * @param bool $forPlaintext BBCode::convert method $for_plaintext parameter value, optional.
180 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
182 public function testConvert($expectedHtml, $text, $simpleHtml = 0, $forPlaintext = false)
184 $actual = BBCode::convert($text, false, $simpleHtml, $forPlaintext);
186 $this->assertEquals($expectedHtml, $actual);