3 namespace Friendica\Test\src\Content\Text;
5 use Friendica\Content\Text\BBCode;
6 use Friendica\Core\L10n\L10n;
7 use Friendica\Test\MockedTest;
8 use Friendica\Test\Util\AppMockTrait;
9 use Friendica\Test\Util\VFSTrait;
11 class BBCodeTest extends MockedTest
16 protected function setUp()
20 $this->mockApp($this->root);
21 $this->app->videowidth = 425;
22 $this->app->videoheight = 350;
23 $this->configMock->shouldReceive('get')
24 ->with('system', 'remove_multiplicated_lines')
26 $this->configMock->shouldReceive('get')
27 ->with('system', 'no_oembed')
29 $this->configMock->shouldReceive('get')
30 ->with('system', 'allowed_link_protocols')
32 $this->configMock->shouldReceive('get')
33 ->with('system', 'itemcache_duration')
35 $this->configMock->shouldReceive('get')
36 ->with('system', 'url')
37 ->andReturn('friendica.local');
38 $this->configMock->shouldReceive('get')
39 ->with('system', 'no_smilies')
42 $l10nMock = \Mockery::mock(L10n::class);
43 $l10nMock->shouldReceive('t')->withAnyArgs()->andReturnUsing(function ($args) { return $args; });
44 \Friendica\Core\L10n::init($l10nMock);
48 public function dataLinks()
51 /** @see https://github.com/friendica/friendica/issues/2487 */
53 'data' => 'https://de.wikipedia.org/wiki/Juha_Sipilä',
57 'data' => 'https://de.wikipedia.org/wiki/Dnepr_(Motorradmarke)',
61 'data' => 'https://friendica.wäckerlin.ch/friendica',
65 'data' => 'https://mastodon.social/@morevnaproject',
68 /** @see https://github.com/friendica/friendica/issues/5795 */
70 'data' => 'https://social.nasqueron.org/@liw/100798039015010628',
73 /** @see https://github.com/friendica/friendica/issues/6095 */
75 'data' => 'https://en.wikipedia.org/wiki/Solid_(web_decentralization_project)',
79 'data' => 'example.com/path',
83 'data' => 'ftp://example.com',
86 'wrong-domain-without-path' => [
87 'data' => 'http://example',
90 'wrong-domain-with-path' => [
91 'data' => 'http://example/path',
94 'bug-6857-domain-start' => [
95 'data' => "http://\nexample.com",
98 'bug-6857-domain-end' => [
99 'data' => "http://example\n.com",
100 'assertHTML' => false
103 'data' => "http://example.\ncom",
104 'assertHTML' => false
107 'data' => "http://example.com\ntest",
108 'assertHTML' => false
111 'data' => "http://example.com<ul>",
112 'assertHTML' => false
115 'data' => html_entity_decode('http://example.com ', ENT_QUOTES, 'UTF-8'),
116 'assertHTML' => false
118 'bug-7271-query-string-brackets' => [
119 'data' => 'https://example.com/search?q=square+brackets+[url]',
122 'bug-7271-path-brackets' => [
123 'data' => 'http://example.com/path/to/file[3].html',
130 * Test convert different links inside a text
131 * @dataProvider dataLinks
133 * @param string $data The data to text
134 * @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)
135 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
137 public function testAutoLinking($data, $assertHTML)
139 $output = BBCode::convert($data);
140 $assert = '<a href="' . $data . '" target="_blank">' . $data . '</a>';
142 $this->assertEquals($assert, $output);
144 $this->assertNotEquals($assert, $output);
148 public function dataBBCodes()
151 'bug-7271-condensed-space' => [
152 'expectedHtml' => '<ul class="listdecimal" style="list-style-type: decimal;"><li> <a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
153 'text' => '[ol][*] http://example.com/[/ol]',
155 'bug-7271-condensed-nospace' => [
156 'expectedHtml' => '<ul class="listdecimal" style="list-style-type: decimal;"><li><a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
157 'text' => '[ol][*]http://example.com/[/ol]',
159 'bug-7271-indented-space' => [
160 'expectedHtml' => '<ul class="listbullet" style="list-style-type: circle;"><li> <a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
162 [*] http://example.com/
165 'bug-7271-indented-nospace' => [
166 'expectedHtml' => '<ul class="listbullet" style="list-style-type: circle;"><li><a href="http://example.com/" target="_blank">http://example.com/</a></li></ul>',
168 [*]http://example.com/
175 * Test convert bbcodes to HTML
176 * @dataProvider dataBBCodes
178 * @param string $expectedHtml Expected HTML output
179 * @param string $text BBCode text
180 * @param int $simpleHtml BBCode::convert method $simple_html parameter value, optional.
181 * @param bool $forPlaintext BBCode::convert method $for_plaintext parameter value, optional.
182 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
184 public function testConvert($expectedHtml, $text, $simpleHtml = 0, $forPlaintext = false)
186 $actual = BBCode::convert($text, false, $simpleHtml, $forPlaintext);
188 $this->assertEquals($expectedHtml, $actual);