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
120 * Test convert different links inside a text
121 * @dataProvider dataLinks
123 * @param string $data The data to text
124 * @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)
125 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
127 public function testAutoLinking($data, $assertHTML)
129 $output = BBCode::convert($data);
130 $assert = '<a href="' . $data . '" target="_blank">' . $data . '</a>';
132 $this->assertEquals($assert, $output);
134 $this->assertNotEquals($assert, $output);
138 public function dataBBCodes()
141 'bug-7271-condensed-space' => [
142 'expectedHtml' => '<ul class="listdecimal" style="list-style-type: decimal;"><li> <a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
143 'text' => '[ol][*] http://example.com/[/ol]',
145 'bug-7271-condensed-nospace' => [
146 'expectedHtml' => '<ul class="listdecimal" style="list-style-type: decimal;"><li><a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
147 'text' => '[ol][*]http://example.com/[/ol]',
149 'bug-7271-indented-space' => [
150 'expectedHtml' => '<ul class="listbullet" style="list-style-type: circle;"><li> <a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
152 [*] http://example.com/
155 'bug-7271-indented-nospace' => [
156 'expectedHtml' => '<ul class="listbullet" style="list-style-type: circle;"><li><a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
158 [*]http://example.com/
165 * Test convert bbcodes to HTML
166 * @dataProvider dataBBCodes
168 * @param string $expectedHtml Expected HTML output
169 * @param string $text BBCode text
170 * @param int $simpleHtml BBCode::convert method $simple_html parameter value, optional.
171 * @param bool $forPlaintext BBCode::convert method $for_plaintext parameter value, optional.
172 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
174 public function testConvert($expectedHtml, $text, $simpleHtml = 0, $forPlaintext = false)
176 $actual = BBCode::convert($text, false, $simpleHtml, $forPlaintext);
178 $this->assertEquals($expectedHtml, $actual);