Issue 13819: Ensure to not use OEmbed if not wanted
[friendica.git/.git] / tests / src / Content / Text / BBCodeTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2024, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Content\Text;
23
24 use Friendica\Content\Text\BBCode;
25 use Friendica\DI;
26 use Friendica\Network\HTTPException\InternalServerErrorException;
27 use Friendica\Test\FixtureTest;
28
29 class BBCodeTest extends FixtureTest
30 {
31         /** @var \HTMLPurifier */
32         public $HTMLPurifier;
33
34         protected function setUp(): void
35         {
36                 parent::setUp();
37                 DI::config()->set('system', 'remove_multiplicated_lines', false);
38                 DI::config()->set('system', 'allowed_link_protocols', []);
39                 DI::config()->set('system', 'url', 'https://friendica.local');
40                 DI::config()->set('system', 'no_smilies', false);
41                 DI::config()->set('system', 'big_emojis', false);
42                 DI::config()->set('system', 'allowed_oembed', '');
43
44                 $config = \HTMLPurifier_HTML5Config::createDefault();
45                 $config->set('HTML.Doctype', 'HTML5');
46                 $config->set('Attr.AllowedRel', [
47                         'noreferrer' => true,
48                         'noopener' => true,
49                 ]);
50                 $config->set('Attr.AllowedFrameTargets', [
51                         '_blank' => true,
52                 ]);
53
54                 $this->HTMLPurifier = new \HTMLPurifier($config);
55         }
56
57         public function dataLinks()
58         {
59                 return [
60                         /** @see https://github.com/friendica/friendica/issues/2487 */
61                         'bug-2487-1' => [
62                                 'data' => 'https://de.wikipedia.org/wiki/Juha_Sipilä',
63                                 'assertHTML' => true,
64                         ],
65                         'bug-2487-2' => [
66                                 'data' => 'https://de.wikipedia.org/wiki/Dnepr_(Motorradmarke)',
67                                 'assertHTML' => true,
68                         ],
69                         'bug-2487-3' => [
70                                 'data' => 'https://friendica.wäckerlin.ch/friendica',
71                                 'assertHTML' => true,
72                         ],
73                         'bug-2487-4' => [
74                                 'data' => 'https://mastodon.social/@morevnaproject',
75                                 'assertHTML' => true,
76                         ],
77                         /** @see https://github.com/friendica/friendica/issues/5795 */
78                         'bug-5795' => [
79                                 'data' => 'https://social.nasqueron.org/@liw/100798039015010628',
80                                 'assertHTML' => true,
81                         ],
82                         /** @see https://github.com/friendica/friendica/issues/6095 */
83                         'bug-6095' => [
84                                 'data' => 'https://en.wikipedia.org/wiki/Solid_(web_decentralization_project)',
85                                 'assertHTML' => true,
86                         ],
87                         'no-protocol' => [
88                                 'data' => 'example.com/path',
89                                 'assertHTML' => false
90                         ],
91                         'wrong-protocol' => [
92                                 'data' => 'ftp://example.com',
93                                 'assertHTML' => false
94                         ],
95                         'wrong-domain-without-path' => [
96                                 'data' => 'http://example',
97                                 'assertHTML' => false
98                         ],
99                         'wrong-domain-with-path' => [
100                                 'data' => 'http://example/path',
101                                 'assertHTML' => false
102                         ],
103                         'bug-6857-domain-start' => [
104                                 'data' => "http://\nexample.com",
105                                 'assertHTML' => false
106                         ],
107                         'bug-6857-domain-end' => [
108                                 'data' => "http://example\n.com",
109                                 'assertHTML' => false
110                         ],
111                         'bug-6857-tld' => [
112                                 'data' => "http://example.\ncom",
113                                 'assertHTML' => false
114                         ],
115                         'bug-6857-end' => [
116                                 'data' => "http://example.com\ntest",
117                                 'assertHTML' => false
118                         ],
119                         'bug-6901' => [
120                                 'data' => "http://example.com<ul>",
121                                 'assertHTML' => false
122                         ],
123                         'bug-7150' => [
124                                 'data' => html_entity_decode('http://example.com&nbsp;', ENT_QUOTES, 'UTF-8'),
125                                 'assertHTML' => false
126                         ],
127                         'bug-7271-query-string-brackets' => [
128                                 'data' => 'https://example.com/search?q=square+brackets+[url]',
129                                 'assertHTML' => true
130                         ],
131                         'bug-7271-path-brackets' => [
132                                 'data' => 'http://example.com/path/to/file[3].html',
133                                 'assertHTML' => true
134                         ],
135                 ];
136         }
137
138         /**
139          * Test convert different links inside a text
140          *
141          * @dataProvider dataLinks
142          *
143          * @param string $data       The data to text
144          * @param bool   $assertHTML True, if the link is a HTML link (<a href...>...</a>)
145          *
146          * @throws InternalServerErrorException
147          */
148         public function testAutoLinking(string $data, bool $assertHTML)
149         {
150                 $output = BBCode::convert($data);
151                 $assert = $this->HTMLPurifier->purify('<a href="' . $data . '" target="_blank" rel="noopener noreferrer">' . $data . '</a>');
152                 if ($assertHTML) {
153                         self::assertEquals($assert, $output);
154                 } else {
155                         self::assertNotEquals($assert, $output);
156                 }
157         }
158
159         public function dataBBCodes()
160         {
161                 return [
162                         'bug-7271-condensed-space' => [
163                                 'expectedHtml' => '<ol><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ol>',
164                                 'text' => '[ol][li] http://example.com/[/ol]',
165                         ],
166                         'bug-7271-condensed-nospace' => [
167                                 'expectedHtml' => '<ol><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ol>',
168                                 'text' => '[ol][li]http://example.com/[/ol]',
169                         ],
170                         'bug-7271-indented-space' => [
171                                 'expectedHtml' => '<ul><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
172                                 'text' => '[ul]
173 [li] http://example.com/
174 [/ul]',
175                         ],
176                         'bug-7271-indented-nospace' => [
177                                 'expectedHtml' => '<ul><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
178                                 'text' => '[ul]
179 [li]http://example.com/
180 [/ul]',
181                         ],
182                         'bug-2199-named-size' => [
183                                 'expectedHtml' => '<span style="font-size:xx-large;line-height:normal;">Test text</span>',
184                                 'text' => '[size=xx-large]Test text[/size]',
185                         ],
186                         'bug-2199-numeric-size' => [
187                                 'expectedHtml' => '<span style="font-size:24px;line-height:normal;">Test text</span>',
188                                 'text' => '[size=24]Test text[/size]',
189                         ],
190                         'bug-2199-diaspora-no-named-size' => [
191                                 'expectedHtml' => 'Test text',
192                                 'text' => '[size=xx-large]Test text[/size]',
193                                 'try_oembed' => false,
194                                 // Triggers the diaspora compatible output
195                                 'simpleHtml' => BBCode::DIASPORA,
196                         ],
197                         'bug-2199-diaspora-no-numeric-size' => [
198                                 'expectedHtml' => 'Test text',
199                                 'text' => '[size=24]Test text[/size]',
200                                 'try_oembed' => false,
201                                 // Triggers the diaspora compatible output
202                                 'simpleHtml' => BBCode::DIASPORA,
203                         ],
204                         'bug-7665-audio-tag' => [
205                                 'expectedHtml' => '<audio src="http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3" controls><a href="http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3">http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3</a></audio>',
206                                 'text' => '[audio]http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3[/audio]',
207                                 'try_oembed' => true,
208                         ],
209                         'bug-7808-code-lt' => [
210                                 'expectedHtml' => '<code>&lt;</code>',
211                                 'text' => '[code]<[/code]',
212                         ],
213                         'bug-7808-code-gt' => [
214                                 'expectedHtml' => '<code>&gt;</code>',
215                                 'text' => '[code]>[/code]',
216                         ],
217                         'bug-7808-code-amp' => [
218                                 'expectedHtml' => '<code>&amp;</code>',
219                                 'text' => '[code]&[/code]',
220                         ],
221                         'task-8800-pre-spaces-notag' => [
222                                 'expectedHtml' => '[test] Space',
223                                 'text' => '[test] Space',
224                         ],
225                         'task-8800-pre-spaces' => [
226                                 'expectedHtml' => '    Spaces',
227                                 'text' => '[pre]    Spaces[/pre]',
228                         ],
229                         'bug-9611-purify-xss-nobb' => [
230                                 'expectedHTML' => '<span>dare to move your mouse here</span>',
231                                 'text' => '[nobb]<span onmouseover="alert(0)">dare to move your mouse here</span>[/nobb]'
232                         ],
233                         'bug-9611-purify-xss-noparse' => [
234                                 'expectedHTML' => '<span>dare to move your mouse here</span>',
235                                 'text' => '[noparse]<span onmouseover="alert(0)">dare to move your mouse here</span>[/noparse]'
236                         ],
237                         'bug-9611-purify-xss-attributes' => [
238                                 'expectedHTML' => '<span>dare to move your mouse here</span>',
239                                 'text' => '[color="onmouseover=alert(0) style="]dare to move your mouse here[/color]'
240                         ],
241                         'bug-9611-purify-attributes-correct' => [
242                                 'expectedHTML' => '<span style="color:#FFFFFF;">dare to move your mouse here</span>',
243                                 'text' => '[color=FFFFFF]dare to move your mouse here[/color]'
244                         ],
245                         'bug-9639-span-classes' => [
246                                 'expectedHTML' => '<span class="arbitrary classes">Test</span>',
247                                 'text' => '[class=arbitrary classes]Test[/class]',
248                         ],
249                         'bug-10772-duplicated-links' => [
250                                 'expectedHTML' => 'Jetzt wird mir klar, warum Kapitalisten jedes Mal durchdrehen wenn Marx und das Kapital ins Gespräch kommt. Soziopathen.<br>Karl Marx - Die ursprüngliche Akkumulation<br><a href="https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation" target="_blank" rel="noopener noreferrer">https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation</a><br>#Podcast #Kapitalismus',
251                                 'text' => "Jetzt wird mir klar, warum Kapitalisten jedes Mal durchdrehen wenn Marx und das Kapital ins Gespräch kommt. Soziopathen.
252 Karl Marx - Die ursprüngliche Akkumulation
253 [url=https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation]https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation[/url]
254 #[url=https://horche.demkontinuum.de/search?tag=Podcast]Podcast[/url] #[url=https://horche.demkontinuum.de/search?tag=Kapitalismus]Kapitalismus[/url]
255 [attachment type='link' url='https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation' title='Ep. 107: Karl Marx #8 - Die urspr&uuml;ngliche Akkumulation' publisher_name='Wohlstand f&uuml;r Alle' preview='https://images.podigee-cdn.net/0x,s6LXshYO7uhG23H431B30t4hxj1bQuzlTsUlze0F_-H8=/https://cdn.podigee.com/uploads/u8126/bd5fe4f4-38b7-4f3f-b269-6a0080144635.jpg']Wie der Kapitalismus funktioniert und inwieweit Menschen darin ausgebeutet werden, haben wir bereits besprochen. Immer wieder verweisen wir auch darauf, dass der Kapitalismus nicht immer schon existierte, sondern historisiert werden muss.[/attachment]",
256                                 'try_oembed' => false,
257                                 'simpleHtml' => BBCode::TWITTER,
258                         ],
259                         'task-10886-deprecate-class' => [
260                                 'expectedHTML' => '<span class="mastodon emoji"><img src="https://fedi.underscore.world/emoji/custom/custom/heart_nb.png" alt=":heart_nb:" title=":heart_nb:"></span>',
261                                 'text' => '[emoji=https://fedi.underscore.world/emoji/custom/custom/heart_nb.png]:heart_nb:[/emoji]',
262                         ],
263                         'task-12900-multiple-paragraphs' => [
264                                 'expectedHTML' => '<h4>Header</h4><ul><li>One</li><li>Two</li></ul><p>This is a paragraph<br>with a line feed.</p><p>Second Chapter</p>',
265                                 'text' => "[h4]Header[/h4][ul][li]One[li]Two[/ul]\n\nThis is a paragraph\nwith a line feed.\n\nSecond Chapter",
266                         ],
267                         'task-12900-header-with-paragraphs' => [
268                                 'expectedHTML' => '<h4>Header</h4><p>Some Chapter</p>',
269                                 'text' => '[h4]Header[/h4]Some Chapter',
270                         ],
271                         'bug-12842-ul-newlines' => [
272                                 'expectedHTML' => '<p>This is:</p><ul><li>some</li><li>amazing</li><li>list</li></ul>',
273                                 'text' => "This is:\r\n[ul]\r\n[li]some\r\n[li]amazing\r\n[li]list\r\n[/ul]",
274                         ],
275                         'bug-12842-ol-newlines' => [
276                                 'expectedHTML' => '<p>This is:</p><ol><li>some</li><li>amazing</li><li>list</li></ol>',
277                                 'text' => "This is:\r\n[ol]\r\n[li]some\r\n[li]amazing\r\n[li]list\r\n[/ol]",
278                         ],
279                         'task-12917-tabs-between-linebreaks' => [
280                                 'expectedHTML' => '<p>Paragraph</p><p>New Paragraph</p>',
281                                 'text' => "Paragraph\n\t\nNew Paragraph",
282                         ],
283                 ];
284         }
285
286         /**
287          * Test convert bbcodes to HTML
288          *
289          * @dataProvider dataBBCodes
290          *
291          * @param string $expectedHtml Expected HTML output
292          * @param string $text         BBCode text
293          * @param bool   $try_oembed   Whether to convert multimedia BBCode tag
294          * @param int    $simpleHtml   BBCode::convert method $simple_html parameter value, optional.
295          * @param bool   $forPlaintext BBCode::convert method $for_plaintext parameter value, optional.
296          *
297          * @throws InternalServerErrorException
298          */
299         public function testConvert(string $expectedHtml, string $text, bool $try_oembed = true, int $simpleHtml = BBCode::INTERNAL, bool $forPlaintext = false)
300         {
301                 // This assumes system.remove_multiplicated_lines = false
302                 $actual = BBCode::convert($text, $try_oembed, $simpleHtml, $forPlaintext);
303
304                 self::assertEquals($expectedHtml, $actual);
305         }
306
307         public function dataBBCodesToMarkdown()
308         {
309                 return [
310                         'bug-7808-gt' => [
311                                 'expected' => '&gt;`>`',
312                                 'text' => '>[code]>[/code]',
313                         ],
314                         'bug-7808-lt' => [
315                                 'expected' => '&lt;`<`',
316                                 'text' => '<[code]<[/code]',
317                         ],
318                         'bug-7808-amp' => [
319                                 'expected' => '&amp;`&`',
320                                 'text' => '&[code]&[/code]',
321                         ],
322                         'bug-12701-quotes' => [
323                                 'expected' => '[![abc"fgh](https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png)](https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581)',
324                                 'text' => '[url=https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581][img=https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png]abc"fgh[/img][/url]'
325                         ],
326                         'bug-12701-no-quotes' => [
327                                 'expected' => '[![abcfgh](https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png "abcfgh")](https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581)',
328                                 'text' => '[url=https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581][img=https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png]abcfgh[/img][/url]'
329                         ],
330                 ];
331         }
332
333         /**
334          * Test convert bbcodes to Markdown
335          *
336          * @dataProvider dataBBCodesToMarkdown
337          *
338          * @param string $expected Expected Markdown output
339          * @param string $text     BBCode text
340          * @param bool   $for_diaspora
341          *
342          * @throws InternalServerErrorException
343          */
344         public function testToMarkdown(string $expected, string $text, $for_diaspora = true)
345         {
346                 $actual = BBCode::toMarkdown($text, $for_diaspora);
347
348                 self::assertEquals($expected, $actual);
349         }
350
351         public function dataExpandTags()
352         {
353                 return [
354                         'bug-10692-non-word' => [
355                                 '[url=https://github.com/friendica/friendica/blob/2021.09-rc/src/Util/Logger/StreamLogger.php#L160]https://github.com/friendica/friendica/blob/2021.09-rc/src/Util/Logger/StreamLogger.php#L160[/url]',
356                                 '[url=https://github.com/friendica/friendica/blob/2021.09-rc/src/Util/Logger/StreamLogger.php#L160]https://github.com/friendica/friendica/blob/2021.09-rc/src/Util/Logger/StreamLogger.php#L160[/url]',
357                         ],
358                         'bug-10692-start-line' => [
359                                 '#[url=https://friendica.local/search?tag=L160]L160[/url]',
360                                 '#L160',
361                         ]
362                 ];
363         }
364
365         /**
366          * @dataProvider dataExpandTags
367          *
368          * @param string $expected Expected BBCode output
369          * @param string $text     Input text
370          */
371         public function testExpandTags(string $expected, string $text)
372         {
373                 $actual = BBCode::expandTags($text);
374
375                 self::assertEquals($expected, $actual);
376         }
377
378         public function dataGetAbstract(): array
379         {
380                 return [
381                         'no-abstract' => [
382                                 'expected' => '',
383                                 'text' => 'Venture the only home we\'ve ever known laws of physics tendrils of gossamer clouds a still more glorious dawn awaits Sea of Tranquility. With pretty stories for which there\'s little good evidence the ash of stellar alchemy corpus callosum preserve and cherish that pale blue dot descended from astronomers preserve and cherish that pale blue dot. A mote of dust suspended in a sunbeam paroxysm of global death two ghostly white figures in coveralls and helmets are softly dancing descended from astronomers star stuff harvesting star light gathered by gravity and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
384                                 'addon' => '',
385                         ],
386                         'no-abstract-addon' => [
387                                 'expected' => '',
388                                 'text' => 'Tingling of the spine tendrils of gossamer clouds Flatland trillion rich in heavy atoms of brilliant syntheses. Extraordinary claims require extraordinary evidence a very small stage in a vast cosmic arena made in the interiors of collapsing stars kindling the energy hidden in matter vastness is bearable only through love kindling the energy hidden in matter? Dispassionate extraterrestrial observer preserve and cherish that pale blue dot vastness is bearable only through love emerged into consciousness encyclopaedia galactica a still more glorious dawn awaits and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
389                                 'addon' => 'dfrn',
390                         ],
391                         'abstract' => [
392                                 'expected' => 'Abstract at the beginning of the text',
393                                 'text' => '[abstract]Abstract at the beginning of the text[/abstract]A very small stage in a vast cosmic arena the ash of stellar alchemy rich in heavy atoms a still more glorious dawn awaits are creatures of the cosmos Orion\'s sword. Brain is the seed of intelligence dream of the mind\'s eye inconspicuous motes of rock and gas extraordinary claims require extraordinary evidence vastness is bearable only through love quasar? Made in the interiors of collapsing stars the carbon in our apple pies cosmic ocean citizens of distant epochs paroxysm of global death dispassionate extraterrestrial observer and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
394                                 'addon' => '',
395                         ],
396                         'abstract-addon-not-present' => [
397                                 'expected' => 'Abstract at the beginning of the text',
398                                 'text' => '[abstract]Abstract at the beginning of the text[/abstract]With pretty stories for which there\'s little good evidence rogue not a sunrise but a galaxyrise tingling of the spine birth cosmic fugue. Cosmos hundreds of thousands Apollonius of Perga network of wormholes rich in mystery globular star cluster. Another world vastness is bearable only through love encyclopaedia galactica something incredible is waiting to be known invent the universe hearts of the stars. Extraordinary claims require extraordinary evidence the sky calls to us the only home we\'ve ever known the sky calls to us the sky calls to us extraordinary claims require extraordinary evidence and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
399                                 'addon' => '',
400                         ],
401                         'abstract-addon-present' => [
402                                 'expected' => 'Abstract DFRN in the middle of the text',
403                                 'text' => '[abstract]Abstract at the beginning of the text[/abstract][abstract=dfrn]Abstract DFRN in the middle of the text[/abstract]Kindling the energy hidden in matter hydrogen atoms at the edge of forever vanquish the impossible ship of the imagination take root and flourish. Tingling of the spine white dwarf as a patch of light the sky calls to us Drake Equation citizens of distant epochs. Concept of the number one dispassionate extraterrestrial observer citizens of distant epochs descended from astronomers extraordinary claims require extraordinary evidence something incredible is waiting to be known and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
404                                 'addon' => 'dfrn',
405                         ],
406                         'abstract-multiple-addon-present' => [
407                                 'expected' => 'Abstract DFRN at the end of the text',
408                                 'text' => '[abstract]Abstract at the beginning of the text[/abstract][abstract=ap]Abstract AP in the middle of the text[/abstract]Cambrian explosion rich in heavy atoms take root and flourish radio telescope light years cosmic fugue. Dispassionate extraterrestrial observer white dwarf the sky calls to us another world courage of our questions two ghostly white figures in coveralls and helmets are softly dancing. Extraordinary claims require extraordinary evidence concept of the number one not a sunrise but a galaxyrise are creatures of the cosmos two ghostly white figures in coveralls and helmets are softly dancing white dwarf and billions upon billions upon billions upon billions upon billions upon billions upon billions.[abstract=dfrn]Abstract DFRN at the end of the text[/abstract]',
409                                 'addon' => 'dfrn',
410                         ],
411                         'bug-11445-code-abstract' => [
412                                 'expected' => '',
413                                 'text' => '[code][abstract]This should not be converted[/abstract][/code]',
414                                 'addon' => '',
415                         ],
416                         'bug-11445-noparse-abstract' => [
417                                 'expected' => '',
418                                 'text' => '[noparse][abstract]This should not be converted[/abstract][/noparse]',
419                                 'addon' => '',
420                         ],
421                         'bug-11445-nobb-abstract' => [
422                                 'expected' => '',
423                                 'text' => '[nobb][abstract]This should not be converted[/abstract][/nobb]',
424                                 'addon' => '',
425                         ],
426                         'bug-11445-pre-abstract' => [
427                                 'expected' => '',
428                                 'text' => '[pre][abstract]This should not be converted[/abstract][/pre]',
429                                 'addon' => '',
430                         ],
431                 ];
432         }
433
434         /**
435          * @dataProvider dataGetAbstract
436          *
437          * @param string $expected Expected abstract text
438          * @param string $text     Input text
439          * @param string $addon    Optional addon we're searching the abstract for
440          */
441         public function testGetAbstract(string $expected, string $text, string $addon)
442         {
443                 $actual = BBCode::getAbstract($text, $addon);
444
445                 self::assertEquals($expected, $actual);
446         }
447
448
449         public function dataStripAbstract(): array
450         {
451                 return [
452                         'no-abstract' => [
453                                 'expected' => 'Venture the only home we\'ve ever known laws of physics tendrils of gossamer clouds a still more glorious dawn awaits Sea of Tranquility. With pretty stories for which there\'s little good evidence the ash of stellar alchemy corpus callosum preserve and cherish that pale blue dot descended from astronomers preserve and cherish that pale blue dot. A mote of dust suspended in a sunbeam paroxysm of global death two ghostly white figures in coveralls and helmets are softly dancing descended from astronomers star stuff harvesting star light gathered by gravity and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
454                                 'text' => 'Venture the only home we\'ve ever known laws of physics tendrils of gossamer clouds a still more glorious dawn awaits Sea of Tranquility. With pretty stories for which there\'s little good evidence the ash of stellar alchemy corpus callosum preserve and cherish that pale blue dot descended from astronomers preserve and cherish that pale blue dot. A mote of dust suspended in a sunbeam paroxysm of global death two ghostly white figures in coveralls and helmets are softly dancing descended from astronomers star stuff harvesting star light gathered by gravity and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
455                         ],
456                         'abstract' => [
457                                 'expected' => ' A very small stage in a vast cosmic arena the ash of stellar alchemy rich in heavy atoms a still more glorious dawn awaits are creatures of the cosmos Orion\'s sword. Brain is the seed of intelligence dream of the mind\'s eye inconspicuous motes of rock and gas extraordinary claims require extraordinary evidence vastness is bearable only through love quasar? Made in the interiors of collapsing stars the carbon in our apple pies cosmic ocean citizens of distant epochs paroxysm of global death dispassionate extraterrestrial observer and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
458                                 'text' => '[abstract]Abstract at the beginning of the text[/abstract]A very small stage in a vast cosmic arena the ash of stellar alchemy rich in heavy atoms a still more glorious dawn awaits are creatures of the cosmos Orion\'s sword. Brain is the seed of intelligence dream of the mind\'s eye inconspicuous motes of rock and gas extraordinary claims require extraordinary evidence vastness is bearable only through love quasar? Made in the interiors of collapsing stars the carbon in our apple pies cosmic ocean citizens of distant epochs paroxysm of global death dispassionate extraterrestrial observer and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
459                         ],
460                         'abstract-addon' => [
461                                 'expected' => ' Kindling the energy hidden in matter hydrogen atoms at the edge of forever vanquish the impossible ship of the imagination take root and flourish. Tingling of the spine white dwarf as a patch of light the sky calls to us Drake Equation citizens of distant epochs. Concept of the number one dispassionate extraterrestrial observer citizens of distant epochs descended from astronomers extraordinary claims require extraordinary evidence something incredible is waiting to be known and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
462                                 'text' => '[abstract]Abstract at the beginning of the text[/abstract][abstract=dfrn]Abstract DFRN in the middle of the text[/abstract]Kindling the energy hidden in matter hydrogen atoms at the edge of forever vanquish the impossible ship of the imagination take root and flourish. Tingling of the spine white dwarf as a patch of light the sky calls to us Drake Equation citizens of distant epochs. Concept of the number one dispassionate extraterrestrial observer citizens of distant epochs descended from astronomers extraordinary claims require extraordinary evidence something incredible is waiting to be known and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
463                         ],
464                         'abstract-multiple-addon-present' => [
465                                 'expected' => ' Cambrian explosion rich in heavy atoms take root and flourish radio telescope light years cosmic fugue. Dispassionate extraterrestrial observer white dwarf the sky calls to us another world courage of our questions two ghostly white figures in coveralls and helmets are softly dancing. Extraordinary claims require extraordinary evidence concept of the number one not a sunrise but a galaxyrise are creatures of the cosmos two ghostly white figures in coveralls and helmets are softly dancing white dwarf and billions upon billions upon billions upon billions upon billions upon billions upon billions. ',
466                                 'text' => '[abstract]Abstract at the beginning of the text[/abstract][abstract=ap]Abstract AP in the middle of the text[/abstract]Cambrian explosion rich in heavy atoms take root and flourish radio telescope light years cosmic fugue. Dispassionate extraterrestrial observer white dwarf the sky calls to us another world courage of our questions two ghostly white figures in coveralls and helmets are softly dancing. Extraordinary claims require extraordinary evidence concept of the number one not a sunrise but a galaxyrise are creatures of the cosmos two ghostly white figures in coveralls and helmets are softly dancing white dwarf and billions upon billions upon billions upon billions upon billions upon billions upon billions.[abstract=dfrn]Abstract DFRN at the end of the text[/abstract]',
467                         ],
468                         'bug-11445-code-abstract' => [
469                                 'expected' => '[code][abstract]This should not be converted[/abstract][/code]',
470                                 'text' => '[code][abstract]This should not be converted[/abstract][/code]',
471                         ],
472                         'bug-11445-noparse-abstract' => [
473                                 'expected' => '[noparse][abstract]This should not be converted[/abstract][/noparse]',
474                                 'text' => '[noparse][abstract]This should not be converted[/abstract][/noparse]',
475                         ],
476                         'bug-11445-nobb-abstract' => [
477                                 'expected' => '[nobb][abstract]This should not be converted[/abstract][/nobb]',
478                                 'text' => '[nobb][abstract]This should not be converted[/abstract][/nobb]',
479                         ],
480                         'bug-11445-pre-abstract' => [
481                                 'expected' => '[pre][abstract]This should not be converted[/abstract][/pre]',
482                                 'text' => '[pre][abstract]This should not be converted[/abstract][/pre]',
483                         ],
484                 ];
485         }
486
487         /**
488          * @dataProvider dataStripAbstract
489          *
490          * @param string $expected Expected text without abstracts
491          * @param string $text     Input text
492          */
493         public function testStripAbstract(string $expected, string $text)
494         {
495                 $actual = BBCode::stripAbstract($text);
496
497                 self::assertEquals($expected, $actual);
498         }
499
500         public function dataFetchShareAttributes(): array
501         {
502                 return [
503                         'no-tag' => [
504                                 'expected' => [],
505                                 'text' => 'Venture the only home we\'ve ever known laws of physics tendrils of gossamer clouds a still more glorious dawn awaits Sea of Tranquility. With pretty stories for which there\'s little good evidence the ash of stellar alchemy corpus callosum preserve and cherish that pale blue dot descended from astronomers preserve and cherish that pale blue dot. A mote of dust suspended in a sunbeam paroxysm of global death two ghostly white figures in coveralls and helmets are softly dancing descended from astronomers star stuff harvesting star light gathered by gravity and billions upon billions upon billions upon billions upon billions upon billions upon billions.',
506                         ],
507                         'just-open' => [
508                                 'expected' => [],
509                                 'text' => '[share]',
510                         ],
511                         'empty-tag' => [
512                                 'expected' => [
513                                         'author' => '',
514                                         'profile' => '',
515                                         'avatar' => '',
516                                         'link' => '',
517                                         'posted' => '',
518                                         'guid' => '',
519                                         'message_id' => '',
520                                         'comment' => '',
521                                         'shared' => '',
522                                 ],
523                                 'text' => '[share][/share]',
524                         ],
525                         'comment-shared' => [
526                                 'expected' => [
527                                         'author' => '',
528                                         'profile' => '',
529                                         'avatar' => '',
530                                         'link' => '',
531                                         'posted' => '',
532                                         'guid' => '',
533                                         'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
534                                         'comment' => 'comment',
535                                         'shared' => '',
536                                 ],
537                                 'text' => ' comment
538                                 [share]https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243[/share]',
539                         ],
540                         'all-attributes' => [
541                                 'expected' => [
542                                         'author' => 'Hypolite Petovan',
543                                         'profile' => 'https://friendica.mrpetovan.com/profile/hypolite',
544                                         'avatar' => 'https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png',
545                                         'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
546                                         'posted' => '2022-06-16 12:34:10',
547                                         'guid' => '735a2029-1062-ab23-42e4-f9c631220243',
548                                         'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
549                                         'comment' => '',
550                                         'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
551 Disney: So a morally grey “choose your side” story, right?
552 Lucas: For the right price, yes.',
553                                 ],
554                                 'text' => "[share
555                                         author='Hypolite Petovan'
556                                         profile='https://friendica.mrpetovan.com/profile/hypolite'
557                                         avatar='https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png'
558                                         link='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243'
559                                         posted='2022-06-16 12:34:10'
560                                         guid='735a2029-1062-ab23-42e4-f9c631220243'
561                                         message_id='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243'
562                                 ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
563 Disney: So a morally grey “choose your side” story, right?
564 Lucas: For the right price, yes.[/share]",
565                         ],
566                         'optional-attributes' => [
567                                 'expected' => [
568                                         'author' => 'Hypolite Petovan',
569                                         'profile' => 'https://friendica.mrpetovan.com/profile/hypolite',
570                                         'avatar' => 'https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png',
571                                         'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
572                                         'posted' => '2022-06-16 12:34:10',
573                                         'guid' => '',
574                                         'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
575                                         'comment' => '',
576                                         'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
577 Disney: So a morally grey “choose your side” story, right?
578 Lucas: For the right price, yes.',
579                                 ],
580                                 'text' => "[share
581                                         author='Hypolite Petovan'
582                                         profile='https://friendica.mrpetovan.com/profile/hypolite'
583                                         avatar='https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png'
584                                         link='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243'
585                                         posted='2022-06-16 12:34:10'
586                                         message_id='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243'
587                                 ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
588 Disney: So a morally grey “choose your side” story, right?
589 Lucas: For the right price, yes.[/share]",
590                         ],
591                         'double-quotes' => [
592                                 'expected' => [
593                                         'author' => 'Hypolite Petovan',
594                                         'profile' => 'https://friendica.mrpetovan.com/profile/hypolite',
595                                         'avatar' => 'https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png',
596                                         'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
597                                         'posted' => '2022-06-16 12:34:10',
598                                         'guid' => '',
599                                         'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
600                                         'comment' => '',
601                                         'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
602 Disney: So a morally grey “choose your side” story, right?
603 Lucas: For the right price, yes.',
604                                 ],
605                                 'text' => '[share
606                                         author="Hypolite Petovan"
607                                         profile="https://friendica.mrpetovan.com/profile/hypolite"
608                                         avatar="https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png"
609                                         link="https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243"
610                                         message_id="https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243"
611                                         posted="2022-06-16 12:34:10"
612                                 ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
613 Disney: So a morally grey “choose your side” story, right?
614 Lucas: For the right price, yes.[/share]',
615                         ],
616                 ];
617         }
618
619         /**
620          * @dataProvider dataFetchShareAttributes
621          *
622          * @param array $expected Expected attribute array
623          * @param string $text    Input text
624          */
625         public function testFetchShareAttributes(array $expected, string $text)
626         {
627                 $actual = BBCode::fetchShareAttributes($text);
628
629                 self::assertEquals($expected, $actual);
630         }
631 }