]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Content/Text/BBCodeTest.php
Tests added
[friendica.git] / tests / src / Content / Text / BBCodeTest.php
index 10be79c722892bff7bacead84c511d52e9d3c6d9..74d34f5a5e836064cc001ac6a892a6eace2b48d7 100644 (file)
@@ -146,7 +146,7 @@ class BBCodeTest extends FixtureTest
        public function testAutoLinking(string $data, bool $assertHTML)
        {
                $output = BBCode::convert($data);
-               $assert = $this->HTMLPurifier->purify('<p><a href="' . $data . '" target="_blank" rel="noopener noreferrer">' . $data . '</a></p>');
+               $assert = $this->HTMLPurifier->purify('<a href="' . $data . '" target="_blank" rel="noopener noreferrer">' . $data . '</a>');
                if ($assertHTML) {
                        self::assertEquals($assert, $output);
                } else {
@@ -158,94 +158,94 @@ class BBCodeTest extends FixtureTest
        {
                return [
                        'bug-7271-condensed-space' => [
-                               'expectedHtml' => '<ul class="listdecimal" style="list-style-type:decimal;"><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
+                               'expectedHtml' => '<ol><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ol>',
                                'text' => '[ol][*] http://example.com/[/ol]',
                        ],
                        'bug-7271-condensed-nospace' => [
-                               'expectedHtml' => '<ul class="listdecimal" style="list-style-type:decimal;"><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
+                               'expectedHtml' => '<ol><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ol>',
                                'text' => '[ol][*]http://example.com/[/ol]',
                        ],
                        'bug-7271-indented-space' => [
-                               'expectedHtml' => '<ul class="listbullet" style="list-style-type:circle;"><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
+                               'expectedHtml' => '<ul><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
                                'text' => '[ul]
 [*] http://example.com/
 [/ul]',
                        ],
                        'bug-7271-indented-nospace' => [
-                               'expectedHtml' => '<ul class="listbullet" style="list-style-type:circle;"><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
+                               'expectedHtml' => '<ul><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
                                'text' => '[ul]
 [*]http://example.com/
 [/ul]',
                        ],
                        'bug-2199-named-size' => [
-                               'expectedHtml' => '<p><span style="font-size:xx-large;line-height:normal;">Test text</span></p>',
+                               'expectedHtml' => '<span style="font-size:xx-large;line-height:normal;">Test text</span>',
                                'text' => '[size=xx-large]Test text[/size]',
                        ],
                        'bug-2199-numeric-size' => [
-                               'expectedHtml' => '<p><span style="font-size:24px;line-height:normal;">Test text</span></p>',
+                               'expectedHtml' => '<span style="font-size:24px;line-height:normal;">Test text</span>',
                                'text' => '[size=24]Test text[/size]',
                        ],
                        'bug-2199-diaspora-no-named-size' => [
-                               'expectedHtml' => '<p>Test text</p>',
+                               'expectedHtml' => 'Test text',
                                'text' => '[size=xx-large]Test text[/size]',
                                'try_oembed' => false,
                                // Triggers the diaspora compatible output
                                'simpleHtml' => BBCode::DIASPORA,
                        ],
                        'bug-2199-diaspora-no-numeric-size' => [
-                               'expectedHtml' => '<p>Test text</p>',
+                               'expectedHtml' => 'Test text',
                                'text' => '[size=24]Test text[/size]',
                                'try_oembed' => false,
                                // Triggers the diaspora compatible output
                                'simpleHtml' => BBCode::DIASPORA,
                        ],
                        'bug-7665-audio-tag' => [
-                               'expectedHtml' => '<p><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></p>',
+                               '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>',
                                'text' => '[audio]http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3[/audio]',
                                'try_oembed' => true,
                        ],
                        'bug-7808-code-lt' => [
-                               'expectedHtml' => '<p><code>&lt;</code></p>',
+                               'expectedHtml' => '<code>&lt;</code>',
                                'text' => '[code]<[/code]',
                        ],
                        'bug-7808-code-gt' => [
-                               'expectedHtml' => '<p><code>&gt;</code></p>',
+                               'expectedHtml' => '<code>&gt;</code>',
                                'text' => '[code]>[/code]',
                        ],
                        'bug-7808-code-amp' => [
-                               'expectedHtml' => '<p><code>&amp;</code></p>',
+                               'expectedHtml' => '<code>&amp;</code>',
                                'text' => '[code]&[/code]',
                        ],
                        'task-8800-pre-spaces-notag' => [
-                               'expectedHtml' => '<p>[test] Space</p>',
+                               'expectedHtml' => '[test] Space',
                                'text' => '[test] Space',
                        ],
                        'task-8800-pre-spaces' => [
-                               'expectedHtml' => '<p>    Spaces</p>',
+                               'expectedHtml' => '    Spaces',
                                'text' => '[pre]    Spaces[/pre]',
                        ],
                        'bug-9611-purify-xss-nobb' => [
-                               'expectedHTML' => '<p><span>dare to move your mouse here</span></p>',
+                               'expectedHTML' => '<span>dare to move your mouse here</span>',
                                'text' => '[nobb]<span onmouseover="alert(0)">dare to move your mouse here</span>[/nobb]'
                        ],
                        'bug-9611-purify-xss-noparse' => [
-                               'expectedHTML' => '<p><span>dare to move your mouse here</span></p>',
+                               'expectedHTML' => '<span>dare to move your mouse here</span>',
                                'text' => '[noparse]<span onmouseover="alert(0)">dare to move your mouse here</span>[/noparse]'
                        ],
                        'bug-9611-purify-xss-attributes' => [
-                               'expectedHTML' => '<p><span>dare to move your mouse here</span></p>',
+                               'expectedHTML' => '<span>dare to move your mouse here</span>',
                                'text' => '[color="onmouseover=alert(0) style="]dare to move your mouse here[/color]'
                        ],
                        'bug-9611-purify-attributes-correct' => [
-                               'expectedHTML' => '<p><span style="color:#FFFFFF;">dare to move your mouse here</span></p>',
+                               'expectedHTML' => '<span style="color:#FFFFFF;">dare to move your mouse here</span>',
                                'text' => '[color=FFFFFF]dare to move your mouse here[/color]'
                        ],
                        'bug-9639-span-classes' => [
-                               'expectedHTML' => '<p><span class="arbitrary classes">Test</span></p>',
+                               'expectedHTML' => '<span class="arbitrary classes">Test</span>',
                                'text' => '[class=arbitrary classes]Test[/class]',
                        ],
                        'bug-10772-duplicated-links' => [
-                               'expectedHTML' => '<p>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</p>',
+                               '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',
                                'text' => "Jetzt wird mir klar, warum Kapitalisten jedes Mal durchdrehen wenn Marx und das Kapital ins Gespräch kommt. Soziopathen.
 Karl Marx - Die ursprüngliche Akkumulation
 [url=https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation]https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation[/url]
@@ -255,9 +255,29 @@ Karl Marx - Die ursprüngliche Akkumulation
                                'simpleHtml' => BBCode::TWITTER,
                        ],
                        'task-10886-deprecate-class' => [
-                               'expectedHTML' => '<p><span class="mastodon emoji"><img src="https://fedi.underscore.world/emoji/custom/custom/heart_nb.png" alt=":heart_nb:" title=":heart_nb:"></span></p>',
+                               'expectedHTML' => '<span class="mastodon emoji"><img src="https://fedi.underscore.world/emoji/custom/custom/heart_nb.png" alt=":heart_nb:" title=":heart_nb:"></span>',
                                'text' => '[emoji=https://fedi.underscore.world/emoji/custom/custom/heart_nb.png]:heart_nb:[/emoji]',
-                       ]
+                       ],
+                       'task-12900-multiple-paragraphs' => [
+                               '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>',
+                               'text' => "[h1]Header[/h1][ul][*]One[*]Two[/ul]\n\nThis is a paragraph\nwith a line feed.\n\nSecond Chapter",
+                       ],
+                       'task-12900-header-with-paragraphs' => [
+                               'expectedHTML' => '<h1>Header</h1><p>Some Chapter</p>',
+                               'text' => '[h1]Header[/h1]Some Chapter',
+                       ],
+                       'bug-12842-ul-newlines' => [
+                               'expectedHTML' => '<p>This is:</p><ul><li>some</li><li>amazing</li><li>list</li></ul>',
+                               'text' => "This is:\r\n[ul]\r\n[*]some\r\n[*]amazing\r\n[*]list\r\n[/ul]",
+                       ],
+                       'bug-12842-ol-newlines' => [
+                               'expectedHTML' => '<p>This is:</p><ol><li>some</li><li>amazing</li><li>list</li></ol>',
+                               'text' => "This is:\r\n[ol]\r\n[*]some\r\n[*]amazing\r\n[*]list\r\n[/ol]",
+                       ],
+                       'task-12917-tabs-between-linebreaks' => [
+                               'expectedHTML' => '<p>Paragraph</p><p>New Paragraph</p>',
+                               'text' => "Paragraph\n\t\nNew Paragraph",
+                       ],
                ];
        }
 
@@ -274,8 +294,9 @@ Karl Marx - Die ursprüngliche Akkumulation
         *
         * @throws InternalServerErrorException
         */
-       public function testConvert(string $expectedHtml, string $text, $try_oembed = false, int $simpleHtml = 0, bool $forPlaintext = false)
+       public function testConvert(string $expectedHtml, string $text, bool $try_oembed = true, int $simpleHtml = BBCode::INTERNAL, bool $forPlaintext = false)
        {
+               // This assumes system.remove_multiplicated_lines = false
                $actual = BBCode::convert($text, $try_oembed, $simpleHtml, $forPlaintext);
 
                self::assertEquals($expectedHtml, $actual);
@@ -296,6 +317,14 @@ Karl Marx - Die ursprüngliche Akkumulation
                                'expected' => '&amp;`&`',
                                'text' => '&[code]&[/code]',
                        ],
+                       'bug-12701-quotes' => [
+                               'expected' => '[![abc"fgh](https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png)](https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581)',
+                               'text' => '[url=https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581][img=https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png]abc"fgh[/img][/url]'
+                       ],
+                       'bug-12701-no-quotes' => [
+                               'expected' => '[![abcfgh](https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png "abcfgh")](https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581)',
+                               'text' => '[url=https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581][img=https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png]abcfgh[/img][/url]'
+                       ],
                ];
        }
 
@@ -310,7 +339,7 @@ Karl Marx - Die ursprüngliche Akkumulation
         *
         * @throws InternalServerErrorException
         */
-       public function testToMarkdown(string $expected, string $text, $for_diaspora = false)
+       public function testToMarkdown(string $expected, string $text, $for_diaspora = true)
        {
                $actual = BBCode::toMarkdown($text, $for_diaspora);