3 namespace Friendica\Test\src\Content\Text;
5 use Friendica\App\BaseURL;
6 use Friendica\Content\Text\BBCode;
7 use Friendica\Core\L10n\L10n;
8 use Friendica\Test\MockedTest;
9 use Friendica\Test\Util\AppMockTrait;
10 use Friendica\Test\Util\VFSTrait;
12 class BBCodeTest extends MockedTest
17 protected function setUp()
21 $this->mockApp($this->root);
22 $this->app->videowidth = 425;
23 $this->app->videoheight = 350;
24 $this->configMock->shouldReceive('get')
25 ->with('system', 'remove_multiplicated_lines')
27 $this->configMock->shouldReceive('get')
28 ->with('system', 'no_oembed')
30 $this->configMock->shouldReceive('get')
31 ->with('system', 'allowed_link_protocols')
33 $this->configMock->shouldReceive('get')
34 ->with('system', 'itemcache_duration')
36 $this->configMock->shouldReceive('get')
37 ->with('system', 'url')
38 ->andReturn('friendica.local');
39 $this->configMock->shouldReceive('get')
40 ->with('system', 'no_smilies')
43 $l10nMock = \Mockery::mock(L10n::class);
44 $l10nMock->shouldReceive('t')->withAnyArgs()->andReturnUsing(function ($args) { return $args; });
45 $this->dice->shouldReceive('create')
47 ->andReturn($l10nMock);
49 $baseUrlMock = \Mockery::mock(BaseURL::class);
50 $baseUrlMock->shouldReceive('get')->withAnyArgs()->andReturn('friendica.local');
51 $this->dice->shouldReceive('create')
52 ->with(BaseURL::class)
53 ->andReturn($baseUrlMock);
56 public function dataLinks()
59 /** @see https://github.com/friendica/friendica/issues/2487 */
61 'data' => 'https://de.wikipedia.org/wiki/Juha_Sipilä',
65 'data' => 'https://de.wikipedia.org/wiki/Dnepr_(Motorradmarke)',
69 'data' => 'https://friendica.wäckerlin.ch/friendica',
73 'data' => 'https://mastodon.social/@morevnaproject',
76 /** @see https://github.com/friendica/friendica/issues/5795 */
78 'data' => 'https://social.nasqueron.org/@liw/100798039015010628',
81 /** @see https://github.com/friendica/friendica/issues/6095 */
83 'data' => 'https://en.wikipedia.org/wiki/Solid_(web_decentralization_project)',
87 'data' => 'example.com/path',
91 'data' => 'ftp://example.com',
94 'wrong-domain-without-path' => [
95 'data' => 'http://example',
98 'wrong-domain-with-path' => [
99 'data' => 'http://example/path',
100 'assertHTML' => false
102 'bug-6857-domain-start' => [
103 'data' => "http://\nexample.com",
104 'assertHTML' => false
106 'bug-6857-domain-end' => [
107 'data' => "http://example\n.com",
108 'assertHTML' => false
111 'data' => "http://example.\ncom",
112 'assertHTML' => false
115 'data' => "http://example.com\ntest",
116 'assertHTML' => false
119 'data' => "http://example.com<ul>",
120 'assertHTML' => false
123 'data' => html_entity_decode('http://example.com ', ENT_QUOTES, 'UTF-8'),
124 'assertHTML' => false
126 'bug-7271-query-string-brackets' => [
127 'data' => 'https://example.com/search?q=square+brackets+[url]',
130 'bug-7271-path-brackets' => [
131 'data' => 'http://example.com/path/to/file[3].html',
138 * Test convert different links inside a text
139 * @dataProvider dataLinks
141 * @param string $data The data to text
142 * @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)
143 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
145 public function testAutoLinking($data, $assertHTML)
147 $output = BBCode::convert($data);
148 $assert = '<a href="' . $data . '" target="_blank">' . $data . '</a>';
150 $this->assertEquals($assert, $output);
152 $this->assertNotEquals($assert, $output);
156 public function dataBBCodes()
159 'bug-7271-condensed-space' => [
160 'expectedHtml' => '<ul class="listdecimal" style="list-style-type: decimal;"><li> <a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
161 'text' => '[ol][*] http://example.com/[/ol]',
163 'bug-7271-condensed-nospace' => [
164 'expectedHtml' => '<ul class="listdecimal" style="list-style-type: decimal;"><li><a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
165 'text' => '[ol][*]http://example.com/[/ol]',
167 'bug-7271-indented-space' => [
168 'expectedHtml' => '<ul class="listbullet" style="list-style-type: circle;"><li> <a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
170 [*] http://example.com/
173 'bug-7271-indented-nospace' => [
174 'expectedHtml' => '<ul class="listbullet" style="list-style-type: circle;"><li><a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
176 [*]http://example.com/
179 'bug-2199-named-size' => [
180 'expectedHtml' => '<span style="font-size: xx-large; line-height: initial;">Test text</span>',
181 'text' => '[size=xx-large]Test text[/size]',
184 'bug-2199-numeric-size' => [
185 'expectedHtml' => '<span style="font-size: 24px; line-height: initial;">Test text</span>',
186 'text' => '[size=24]Test text[/size]',
189 'bug-2199-diaspora-no-named-size' => [
190 'expectedHtml' => 'Test text',
191 'text' => '[size=xx-large]Test text[/size]',
192 // Triggers the diaspora compatible output
195 'bug-2199-diaspora-no-numeric-size' => [
196 'expectedHtml' => 'Test text',
197 'text' => '[size=24]Test text[/size]',
198 // Triggers the diaspora compatible output
205 * Test convert bbcodes to HTML
206 * @dataProvider dataBBCodes
208 * @param string $expectedHtml Expected HTML output
209 * @param string $text BBCode text
210 * @param int $simpleHtml BBCode::convert method $simple_html parameter value, optional.
211 * @param bool $forPlaintext BBCode::convert method $for_plaintext parameter value, optional.
212 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
214 public function testConvert($expectedHtml, $text, $simpleHtml = 0, $forPlaintext = false)
216 $actual = BBCode::convert($text, false, $simpleHtml, $forPlaintext);
218 $this->assertEquals($expectedHtml, $actual);