]> git.mxchange.org Git - friendica.git/blob - tests/src/Content/Text/BBCodeTest.php
Merge pull request #12917 from annando/remove-tab
[friendica.git] / tests / src / Content / Text / BBCodeTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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         protected function setUp(): void
32         {
33                 parent::setUp();
34                 DI::config()->set('system', 'remove_multiplicated_lines', false);
35                 DI::config()->set('system', 'no_oembed', false);
36                 DI::config()->set('system', 'allowed_link_protocols', []);
37                 DI::config()->set('system', 'url', 'https://friendica.local');
38                 DI::config()->set('system', 'no_smilies', false);
39                 DI::config()->set('system', 'big_emojis', false);
40                 DI::config()->set('system', 'allowed_oembed', '');
41
42                 $config = \HTMLPurifier_HTML5Config::createDefault();
43                 $config->set('HTML.Doctype', 'HTML5');
44                 $config->set('Attr.AllowedRel', [
45                         'noreferrer' => true,
46                         'noopener' => true,
47                 ]);
48                 $config->set('Attr.AllowedFrameTargets', [
49                         '_blank' => true,
50                 ]);
51
52                 $this->HTMLPurifier = new \HTMLPurifier($config);
53         }
54
55         public function dataLinks()
56         {
57                 return [
58                         /** @see https://github.com/friendica/friendica/issues/2487 */
59                         'bug-2487-1' => [
60                                 'data' => 'https://de.wikipedia.org/wiki/Juha_Sipilä',
61                                 'assertHTML' => true,
62                         ],
63                         'bug-2487-2' => [
64                                 'data' => 'https://de.wikipedia.org/wiki/Dnepr_(Motorradmarke)',
65                                 'assertHTML' => true,
66                         ],
67                         'bug-2487-3' => [
68                                 'data' => 'https://friendica.wäckerlin.ch/friendica',
69                                 'assertHTML' => true,
70                         ],
71                         'bug-2487-4' => [
72                                 'data' => 'https://mastodon.social/@morevnaproject',
73                                 'assertHTML' => true,
74                         ],
75                         /** @see https://github.com/friendica/friendica/issues/5795 */
76                         'bug-5795' => [
77                                 'data' => 'https://social.nasqueron.org/@liw/100798039015010628',
78                                 'assertHTML' => true,
79                         ],
80                         /** @see https://github.com/friendica/friendica/issues/6095 */
81                         'bug-6095' => [
82                                 'data' => 'https://en.wikipedia.org/wiki/Solid_(web_decentralization_project)',
83                                 'assertHTML' => true,
84                         ],
85                         'no-protocol' => [
86                                 'data' => 'example.com/path',
87                                 'assertHTML' => false
88                         ],
89                         'wrong-protocol' => [
90                                 'data' => 'ftp://example.com',
91                                 'assertHTML' => false
92                         ],
93                         'wrong-domain-without-path' => [
94                                 'data' => 'http://example',
95                                 'assertHTML' => false
96                         ],
97                         'wrong-domain-with-path' => [
98                                 'data' => 'http://example/path',
99                                 'assertHTML' => false
100                         ],
101                         'bug-6857-domain-start' => [
102                                 'data' => "http://\nexample.com",
103                                 'assertHTML' => false
104                         ],
105                         'bug-6857-domain-end' => [
106                                 'data' => "http://example\n.com",
107                                 'assertHTML' => false
108                         ],
109                         'bug-6857-tld' => [
110                                 'data' => "http://example.\ncom",
111                                 'assertHTML' => false
112                         ],
113                         'bug-6857-end' => [
114                                 'data' => "http://example.com\ntest",
115                                 'assertHTML' => false
116                         ],
117                         'bug-6901' => [
118                                 'data' => "http://example.com<ul>",
119                                 'assertHTML' => false
120                         ],
121                         'bug-7150' => [
122                                 'data' => html_entity_decode('http://example.com&nbsp;', ENT_QUOTES, 'UTF-8'),
123                                 'assertHTML' => false
124                         ],
125                         'bug-7271-query-string-brackets' => [
126                                 'data' => 'https://example.com/search?q=square+brackets+[url]',
127                                 'assertHTML' => true
128                         ],
129                         'bug-7271-path-brackets' => [
130                                 'data' => 'http://example.com/path/to/file[3].html',
131                                 'assertHTML' => true
132                         ],
133                 ];
134         }
135
136         /**
137          * Test convert different links inside a text
138          *
139          * @dataProvider dataLinks
140          *
141          * @param string $data       The data to text
142          * @param bool   $assertHTML True, if the link is a HTML link (<a href...>...</a>)
143          *
144          * @throws InternalServerErrorException
145          */
146         public function testAutoLinking(string $data, bool $assertHTML)
147         {
148                 $output = BBCode::convert($data);
149                 $assert = $this->HTMLPurifier->purify('<a href="' . $data . '" target="_blank" rel="noopener noreferrer">' . $data . '</a>');
150                 if ($assertHTML) {
151                         self::assertEquals($assert, $output);
152                 } else {
153                         self::assertNotEquals($assert, $output);
154                 }
155         }
156
157         public function dataBBCodes()
158         {
159                 return [
160                         'bug-7271-condensed-space' => [
161                                 'expectedHtml' => '<ol><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ol>',
162                                 'text' => '[ol][*] http://example.com/[/ol]',
163                         ],
164                         'bug-7271-condensed-nospace' => [
165                                 'expectedHtml' => '<ol><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ol>',
166                                 'text' => '[ol][*]http://example.com/[/ol]',
167                         ],
168                         'bug-7271-indented-space' => [
169                                 'expectedHtml' => '<ul><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
170                                 'text' => '[ul]
171 [*] http://example.com/
172 [/ul]',
173                         ],
174                         'bug-7271-indented-nospace' => [
175                                 'expectedHtml' => '<ul><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
176                                 'text' => '[ul]
177 [*]http://example.com/
178 [/ul]',
179                         ],
180                         'bug-2199-named-size' => [
181                                 'expectedHtml' => '<span style="font-size:xx-large;line-height:normal;">Test text</span>',
182                                 'text' => '[size=xx-large]Test text[/size]',
183                         ],
184                         'bug-2199-numeric-size' => [
185                                 'expectedHtml' => '<span style="font-size:24px;line-height:normal;">Test text</span>',
186                                 'text' => '[size=24]Test text[/size]',
187                         ],
188                         'bug-2199-diaspora-no-named-size' => [
189                                 'expectedHtml' => 'Test text',
190                                 'text' => '[size=xx-large]Test text[/size]',
191                                 'try_oembed' => false,
192                                 // Triggers the diaspora compatible output
193                                 'simpleHtml' => BBCode::DIASPORA,
194                         ],
195                         'bug-2199-diaspora-no-numeric-size' => [
196                                 'expectedHtml' => 'Test text',
197                                 'text' => '[size=24]Test text[/size]',
198                                 'try_oembed' => false,
199                                 // Triggers the diaspora compatible output
200                                 'simpleHtml' => BBCode::DIASPORA,
201                         ],
202                         'bug-7665-audio-tag' => [
203                                 '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>',
204                                 'text' => '[audio]http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3[/audio]',
205                                 'try_oembed' => true,
206                         ],
207                         'bug-7808-code-lt' => [
208                                 'expectedHtml' => '<code>&lt;</code>',
209                                 'text' => '[code]<[/code]',
210                         ],
211                         'bug-7808-code-gt' => [
212                                 'expectedHtml' => '<code>&gt;</code>',
213                                 'text' => '[code]>[/code]',
214                         ],
215                         'bug-7808-code-amp' => [
216                                 'expectedHtml' => '<code>&amp;</code>',
217                                 'text' => '[code]&[/code]',
218                         ],
219                         'task-8800-pre-spaces-notag' => [
220                                 'expectedHtml' => '[test] Space',
221                                 'text' => '[test] Space',
222                         ],
223                         'task-8800-pre-spaces' => [
224                                 'expectedHtml' => '    Spaces',
225                                 'text' => '[pre]    Spaces[/pre]',
226                         ],
227                         'bug-9611-purify-xss-nobb' => [
228                                 'expectedHTML' => '<span>dare to move your mouse here</span>',
229                                 'text' => '[nobb]<span onmouseover="alert(0)">dare to move your mouse here</span>[/nobb]'
230                         ],
231                         'bug-9611-purify-xss-noparse' => [
232                                 'expectedHTML' => '<span>dare to move your mouse here</span>',
233                                 'text' => '[noparse]<span onmouseover="alert(0)">dare to move your mouse here</span>[/noparse]'
234                         ],
235                         'bug-9611-purify-xss-attributes' => [
236                                 'expectedHTML' => '<span>dare to move your mouse here</span>',
237                                 'text' => '[color="onmouseover=alert(0) style="]dare to move your mouse here[/color]'
238                         ],
239                         'bug-9611-purify-attributes-correct' => [
240                                 'expectedHTML' => '<span style="color:#FFFFFF;">dare to move your mouse here</span>',
241                                 'text' => '[color=FFFFFF]dare to move your mouse here[/color]'
242                         ],
243                         'bug-9639-span-classes' => [
244                                 'expectedHTML' => '<span class="arbitrary classes">Test</span>',
245                                 'text' => '[class=arbitrary classes]Test[/class]',
246                         ],
247                         'bug-10772-duplicated-links' => [
248                                 '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',
249                                 'text' => "Jetzt wird mir klar, warum Kapitalisten jedes Mal durchdrehen wenn Marx und das Kapital ins Gespräch kommt. Soziopathen.
250 Karl Marx - Die ursprüngliche Akkumulation
251 [url=https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation]https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation[/url]
252 #[url=https://horche.demkontinuum.de/search?tag=Podcast]Podcast[/url] #[url=https://horche.demkontinuum.de/search?tag=Kapitalismus]Kapitalismus[/url]
253 [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]",
254                                 'try_oembed' => false,
255                                 'simpleHtml' => BBCode::TWITTER,
256                         ],
257                         'task-10886-deprecate-class' => [
258                                 'expectedHTML' => '<span class="mastodon emoji"><img src="https://fedi.underscore.world/emoji/custom/custom/heart_nb.png" alt=":heart_nb:" title=":heart_nb:"></span>',
259                                 'text' => '[emoji=https://fedi.underscore.world/emoji/custom/custom/heart_nb.png]:heart_nb:[/emoji]',
260                         ],
261                         'task-12900-multiple-paragraphs' => [
262                                 'expectedHTML' => '<h1>Header</h1><ul><li>One</li><li>Two</li></ul><p>This is a paragraph<br>with a line feed.</p><p>Second Chapter</p>',
263                                 'text' => "[h1]Header[/h1][ul][*]One[*]Two[/ul]\n\nThis is a paragraph\nwith a line feed.\n\nSecond Chapter",
264                         ],
265                         'task-12900-header-with-paragraphs' => [
266                                 'expectedHTML' => '<h1>Header</h1><p>Some Chapter</p>',
267                                 'text' => '[h1]Header[/h1]Some Chapter',
268                         ],
269                         'bug-12842-ul-newlines' => [
270                                 'expectedHTML' => '<p>This is:</p><ul><li>some</li><li>amazing</li><li>list</li></ul>',
271                                 'text' => "This is:\r\n[ul]\r\n[*]some\r\n[*]amazing\r\n[*]list\r\n[/ul]",
272                         ],
273                         'bug-12842-ol-newlines' => [
274                                 'expectedHTML' => '<p>This is:</p><ol><li>some</li><li>amazing</li><li>list</li></ol>',
275                                 'text' => "This is:\r\n[ol]\r\n[*]some\r\n[*]amazing\r\n[*]list\r\n[/ol]",
276                         ],
277                         'task-12917-tabs-between-linebreaks' => [
278                                 'expectedHTML' => '<p>Paragraph</p><p>New Paragraph</p>',
279                                 'text' => "Paragraph\n\t\nNew Paragraph",
280                         ],
281                 ];
282         }
283
284         /**
285          * Test convert bbcodes to HTML
286          *
287          * @dataProvider dataBBCodes
288          *
289          * @param string $expectedHtml Expected HTML output
290          * @param string $text         BBCode text
291          * @param bool   $try_oembed   Whether to convert multimedia BBCode tag
292          * @param int    $simpleHtml   BBCode::convert method $simple_html parameter value, optional.
293          * @param bool   $forPlaintext BBCode::convert method $for_plaintext parameter value, optional.
294          *
295          * @throws InternalServerErrorException
296          */
297         public function testConvert(string $expectedHtml, string $text, bool $try_oembed = true, int $simpleHtml = BBCode::INTERNAL, bool $forPlaintext = false)
298         {
299                 // This assumes system.remove_multiplicated_lines = false
300                 $actual = BBCode::convert($text, $try_oembed, $simpleHtml, $forPlaintext);
301
302                 self::assertEquals($expectedHtml, $actual);
303         }
304
305         public function dataBBCodesToMarkdown()
306         {
307                 return [
308                         'bug-7808-gt' => [
309                                 'expected' => '&gt;`>`',
310                                 'text' => '>[code]>[/code]',
311                         ],
312                         'bug-7808-lt' => [
313                                 'expected' => '&lt;`<`',
314                                 'text' => '<[code]<[/code]',
315                         ],
316                         'bug-7808-amp' => [
317                                 'expected' => '&amp;`&`',
318                                 'text' => '&[code]&[/code]',
319                         ],
320                 ];
321         }
322
323         /**
324          * Test convert bbcodes to Markdown
325          *
326          * @dataProvider dataBBCodesToMarkdown
327          *
328          * @param string $expected Expected Markdown output
329          * @param string $text     BBCode text
330          * @param bool   $for_diaspora
331          *
332          * @throws InternalServerErrorException
333          */
334         public function testToMarkdown(string $expected, string $text, $for_diaspora = false)
335         {
336                 $actual = BBCode::toMarkdown($text, $for_diaspora);
337
338                 self::assertEquals($expected, $actual);
339         }
340
341         public function dataExpandTags()
342         {
343                 return [
344                         'bug-10692-non-word' => [
345                                 '[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]',
346                                 '[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]',
347                         ],
348                         'bug-10692-start-line' => [
349                                 '#[url=https://friendica.local/search?tag=L160]L160[/url]',
350                                 '#L160',
351                         ]
352                 ];
353         }
354
355         /**
356          * @dataProvider dataExpandTags
357          *
358          * @param string $expected Expected BBCode output
359          * @param string $text     Input text
360          */
361         public function testExpandTags(string $expected, string $text)
362         {
363                 $actual = BBCode::expandTags($text);
364
365                 self::assertEquals($expected, $actual);
366         }
367
368         public function dataGetAbstract(): array
369         {
370                 return [
371                         'no-abstract' => [
372                                 'expected' => '',
373                                 '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.',
374                                 'addon' => '',
375                         ],
376                         'no-abstract-addon' => [
377                                 'expected' => '',
378                                 '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.',
379                                 'addon' => 'dfrn',
380                         ],
381                         'abstract' => [
382                                 'expected' => 'Abstract at the beginning of the text',
383                                 '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.',
384                                 'addon' => '',
385                         ],
386                         'abstract-addon-not-present' => [
387                                 'expected' => 'Abstract at the beginning of the text',
388                                 '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.',
389                                 'addon' => '',
390                         ],
391                         'abstract-addon-present' => [
392                                 'expected' => 'Abstract DFRN in the middle of the text',
393                                 '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.',
394                                 'addon' => 'dfrn',
395                         ],
396                         'abstract-multiple-addon-present' => [
397                                 'expected' => 'Abstract DFRN at the end of the text',
398                                 '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]',
399                                 'addon' => 'dfrn',
400                         ],
401                         'bug-11445-code-abstract' => [
402                                 'expected' => '',
403                                 'text' => '[code][abstract]This should not be converted[/abstract][/code]',
404                                 'addon' => '',
405                         ],
406                         'bug-11445-noparse-abstract' => [
407                                 'expected' => '',
408                                 'text' => '[noparse][abstract]This should not be converted[/abstract][/noparse]',
409                                 'addon' => '',
410                         ],
411                         'bug-11445-nobb-abstract' => [
412                                 'expected' => '',
413                                 'text' => '[nobb][abstract]This should not be converted[/abstract][/nobb]',
414                                 'addon' => '',
415                         ],
416                         'bug-11445-pre-abstract' => [
417                                 'expected' => '',
418                                 'text' => '[pre][abstract]This should not be converted[/abstract][/pre]',
419                                 'addon' => '',
420                         ],
421                 ];
422         }
423
424         /**
425          * @dataProvider dataGetAbstract
426          *
427          * @param string $expected Expected abstract text
428          * @param string $text     Input text
429          * @param string $addon    Optional addon we're searching the abstract for
430          */
431         public function testGetAbstract(string $expected, string $text, string $addon)
432         {
433                 $actual = BBCode::getAbstract($text, $addon);
434
435                 self::assertEquals($expected, $actual);
436         }
437
438
439         public function dataStripAbstract(): array
440         {
441                 return [
442                         'no-abstract' => [
443                                 '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.',
444                                 '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.',
445                         ],
446                         'abstract' => [
447                                 '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.',
448                                 '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.',
449                         ],
450                         'abstract-addon' => [
451                                 '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.',
452                                 '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.',
453                         ],
454                         'abstract-multiple-addon-present' => [
455                                 '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. ',
456                                 '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]',
457                         ],
458                         'bug-11445-code-abstract' => [
459                                 'expected' => '[code][abstract]This should not be converted[/abstract][/code]',
460                                 'text' => '[code][abstract]This should not be converted[/abstract][/code]',
461                         ],
462                         'bug-11445-noparse-abstract' => [
463                                 'expected' => '[noparse][abstract]This should not be converted[/abstract][/noparse]',
464                                 'text' => '[noparse][abstract]This should not be converted[/abstract][/noparse]',
465                         ],
466                         'bug-11445-nobb-abstract' => [
467                                 'expected' => '[nobb][abstract]This should not be converted[/abstract][/nobb]',
468                                 'text' => '[nobb][abstract]This should not be converted[/abstract][/nobb]',
469                         ],
470                         'bug-11445-pre-abstract' => [
471                                 'expected' => '[pre][abstract]This should not be converted[/abstract][/pre]',
472                                 'text' => '[pre][abstract]This should not be converted[/abstract][/pre]',
473                         ],
474                 ];
475         }
476
477         /**
478          * @dataProvider dataStripAbstract
479          *
480          * @param string $expected Expected text without abstracts
481          * @param string $text     Input text
482          */
483         public function testStripAbstract(string $expected, string $text)
484         {
485                 $actual = BBCode::stripAbstract($text);
486
487                 self::assertEquals($expected, $actual);
488         }
489
490         public function dataFetchShareAttributes(): array
491         {
492                 return [
493                         'no-tag' => [
494                                 'expected' => [],
495                                 '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.',
496                         ],
497                         'just-open' => [
498                                 'expected' => [],
499                                 'text' => '[share]',
500                         ],
501                         'empty-tag' => [
502                                 'expected' => [
503                                         'author' => '',
504                                         'profile' => '',
505                                         'avatar' => '',
506                                         'link' => '',
507                                         'posted' => '',
508                                         'guid' => '',
509                                         'message_id' => '',
510                                         'comment' => '',
511                                         'shared' => '',
512                                 ],
513                                 'text' => '[share][/share]',
514                         ],
515                         'comment-shared' => [
516                                 'expected' => [
517                                         'author' => '',
518                                         'profile' => '',
519                                         'avatar' => '',
520                                         'link' => '',
521                                         'posted' => '',
522                                         'guid' => '',
523                                         'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
524                                         'comment' => 'comment',
525                                         'shared' => '',
526                                 ],
527                                 'text' => ' comment
528                                 [share]https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243[/share]',
529                         ],
530                         'all-attributes' => [
531                                 'expected' => [
532                                         'author' => 'Hypolite Petovan',
533                                         'profile' => 'https://friendica.mrpetovan.com/profile/hypolite',
534                                         'avatar' => 'https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png',
535                                         'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
536                                         'posted' => '2022-06-16 12:34:10',
537                                         'guid' => '735a2029-1062-ab23-42e4-f9c631220243',
538                                         'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
539                                         'comment' => '',
540                                         'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
541 Disney: So a morally grey “choose your side” story, right?
542 Lucas: For the right price, yes.',
543                                 ],
544                                 'text' => "[share
545                                         author='Hypolite Petovan'
546                                         profile='https://friendica.mrpetovan.com/profile/hypolite'
547                                         avatar='https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png'
548                                         link='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243'
549                                         posted='2022-06-16 12:34:10'
550                                         guid='735a2029-1062-ab23-42e4-f9c631220243'
551                                         message_id='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243'
552                                 ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
553 Disney: So a morally grey “choose your side” story, right?
554 Lucas: For the right price, yes.[/share]",
555                         ],
556                         'optional-attributes' => [
557                                 'expected' => [
558                                         'author' => 'Hypolite Petovan',
559                                         'profile' => 'https://friendica.mrpetovan.com/profile/hypolite',
560                                         'avatar' => 'https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png',
561                                         'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
562                                         'posted' => '2022-06-16 12:34:10',
563                                         'guid' => '',
564                                         'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
565                                         'comment' => '',
566                                         'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
567 Disney: So a morally grey “choose your side” story, right?
568 Lucas: For the right price, yes.',
569                                 ],
570                                 'text' => "[share
571                                         author='Hypolite Petovan'
572                                         profile='https://friendica.mrpetovan.com/profile/hypolite'
573                                         avatar='https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png'
574                                         link='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243'
575                                         posted='2022-06-16 12:34:10'
576                                         message_id='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243'
577                                 ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
578 Disney: So a morally grey “choose your side” story, right?
579 Lucas: For the right price, yes.[/share]",
580                         ],
581                         'double-quotes' => [
582                                 'expected' => [
583                                         'author' => 'Hypolite Petovan',
584                                         'profile' => 'https://friendica.mrpetovan.com/profile/hypolite',
585                                         'avatar' => 'https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png',
586                                         'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
587                                         'posted' => '2022-06-16 12:34:10',
588                                         'guid' => '',
589                                         'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243',
590                                         'comment' => '',
591                                         'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
592 Disney: So a morally grey “choose your side” story, right?
593 Lucas: For the right price, yes.',
594                                 ],
595                                 'text' => '[share
596                                         author="Hypolite Petovan"
597                                         profile="https://friendica.mrpetovan.com/profile/hypolite"
598                                         avatar="https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png"
599                                         link="https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243"
600                                         message_id="https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243"
601                                         posted="2022-06-16 12:34:10"
602                                 ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion.
603 Disney: So a morally grey “choose your side” story, right?
604 Lucas: For the right price, yes.[/share]',
605                         ],
606                 ];
607         }
608
609         /**
610          * @dataProvider dataFetchShareAttributes
611          *
612          * @param array $expected Expected attribute array
613          * @param string $text    Input text
614          */
615         public function testFetchShareAttributes(array $expected, string $text)
616         {
617                 $actual = BBCode::fetchShareAttributes($text);
618
619                 self::assertEquals($expected, $actual);
620         }
621 }