]> git.mxchange.org Git - friendica.git/commitdiff
Add tests
authorPhilipp <admin@philipp.info>
Sun, 25 May 2025 17:17:17 +0000 (19:17 +0200)
committerPhilipp <admin@philipp.info>
Sun, 25 May 2025 17:17:17 +0000 (19:17 +0200)
tests/src/Content/Text/BBCodeTest.php
tests/src/Content/Text/MarkdownTest.php

index c7c7220cd94b58d4eee39810d249585dd70cc85e..df4f5c6bfc1df511f957362f04c5b291e2184524 100644 (file)
@@ -73,51 +73,51 @@ class BBCodeTest extends FixtureTestCase
                        ],
                        'no-protocol' => [
                                'data'       => 'example.com/path',
-                               'assertHTML' => false
+                               'assertHTML' => false,
                        ],
                        'wrong-protocol' => [
                                'data'       => 'ftp://example.com',
-                               'assertHTML' => false
+                               'assertHTML' => false,
                        ],
                        'wrong-domain-without-path' => [
                                'data'       => 'http://example',
-                               'assertHTML' => false
+                               'assertHTML' => false,
                        ],
                        'wrong-domain-with-path' => [
                                'data'       => 'http://example/path',
-                               'assertHTML' => false
+                               'assertHTML' => false,
                        ],
                        'bug-6857-domain-start' => [
                                'data'       => "http://\nexample.com",
-                               'assertHTML' => false
+                               'assertHTML' => false,
                        ],
                        'bug-6857-domain-end' => [
                                'data'       => "http://example\n.com",
-                               'assertHTML' => false
+                               'assertHTML' => false,
                        ],
                        'bug-6857-tld' => [
                                'data'       => "http://example.\ncom",
-                               'assertHTML' => false
+                               'assertHTML' => false,
                        ],
                        'bug-6857-end' => [
                                'data'       => "http://example.com\ntest",
-                               'assertHTML' => false
+                               'assertHTML' => false,
                        ],
                        'bug-6901' => [
                                'data'       => "http://example.com<ul>",
-                               'assertHTML' => false
+                               'assertHTML' => false,
                        ],
                        'bug-7150' => [
                                'data'       => html_entity_decode('http://example.com&nbsp;', ENT_QUOTES, 'UTF-8'),
-                               'assertHTML' => false
+                               'assertHTML' => false,
                        ],
                        'bug-7271-query-string-brackets' => [
                                'data'       => 'https://example.com/search?q=square+brackets+[url]',
-                               'assertHTML' => true
+                               'assertHTML' => true,
                        ],
                        'bug-7271-path-brackets' => [
                                'data'       => 'http://example.com/path/to/file[3].html',
-                               'assertHTML' => true
+                               'assertHTML' => true,
                        ],
                ];
        }
@@ -215,19 +215,19 @@ class BBCodeTest extends FixtureTestCase
                        ],
                        'bug-9611-purify-xss-nobb' => [
                                'expectedHTML' => '<span>dare to move your mouse here</span>',
-                               'text'         => '[nobb]<span onmouseover="alert(0)">dare to move your mouse here</span>[/nobb]'
+                               'text'         => '[nobb]<span onmouseover="alert(0)">dare to move your mouse here</span>[/nobb]',
                        ],
                        'bug-9611-purify-xss-noparse' => [
                                'expectedHTML' => '<span>dare to move your mouse here</span>',
-                               'text'         => '[noparse]<span onmouseover="alert(0)">dare to move your mouse here</span>[/noparse]'
+                               'text'         => '[noparse]<span onmouseover="alert(0)">dare to move your mouse here</span>[/noparse]',
                        ],
                        'bug-9611-purify-xss-attributes' => [
                                'expectedHTML' => '<span>dare to move your mouse here</span>',
-                               'text'         => '[color="onmouseover=alert(0) style="]dare to move your mouse here[/color]'
+                               'text'         => '[color="onmouseover=alert(0) style="]dare to move your mouse here[/color]',
                        ],
                        'bug-9611-purify-attributes-correct' => [
                                'expectedHTML' => '<span style="color:#FFFFFF;">dare to move your mouse here</span>',
-                               'text'         => '[color=FFFFFF]dare to move your mouse here[/color]'
+                               'text'         => '[color=FFFFFF]dare to move your mouse here[/color]',
                        ],
                        'bug-9639-span-classes' => [
                                'expectedHTML' => '<span class="arbitrary classes">Test</span>',
@@ -308,11 +308,11 @@ Karl Marx - Die ursprüngliche Akkumulation
                        ],
                        '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]'
+                               '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]'
+                               'text'     => '[url=https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581][img=https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png]abcfgh[/img][/url]',
                        ],
                ];
        }
@@ -345,7 +345,7 @@ Karl Marx - Die ursprüngliche Akkumulation
                        'bug-10692-start-line' => [
                                '#[url=https://friendica.local/search?tag=L160]L160[/url]',
                                '#L160',
-                       ]
+                       ],
                ];
        }
 
@@ -362,6 +362,58 @@ Karl Marx - Die ursprüngliche Akkumulation
                self::assertEquals($expected, $actual);
        }
 
+       public function dataExpandVideoLinks(): array
+       {
+               return [
+                       /** @see https://github.com/friendica/friendica/pull/14940 */
+                       'task-14940-youtube-watch-with-www' => [
+                               'expectedBBCode' => '[url=https://www.youtube.com/watch?v=hfwbmTzBFT0]https://www.youtube.com/watch?v=hfwbmTzBFT0[/url]',
+                               'text'         => '[youtube]https://www.youtube.com/watch?v=hfwbmTzBFT0[/youtube]',
+                       ],
+                       'task-14940-youtube-watch-without-www' => [
+                               'expectedBBCode' => '[url=https://www.youtube.com/watch?v=hfwbmTzBFT0]https://www.youtube.com/watch?v=hfwbmTzBFT0[/url]',
+                               'text'         => '[youtube]https://youtube.com/watch?v=hfwbmTzBFT0[/youtube]',
+                       ],
+                       'task-14940-youtube-shorts-with-www' => [
+                               'expectedBBCode' => '[url=https://www.youtube.com/watch?v=hfwbmTzBFT0]https://www.youtube.com/watch?v=hfwbmTzBFT0[/url]',
+                               'text'         => '[youtube]https://www.youtube.com/shorts/hfwbmTzBFT0[/youtube]',
+                       ],
+                       'task-14940-youtube-shorts-without-www' => [
+                               'expectedBBCode' => '[url=https://www.youtube.com/watch?v=hfwbmTzBFT0]https://www.youtube.com/watch?v=hfwbmTzBFT0[/url]',
+                               'text'         => '[youtube]https://youtube.com/shorts/hfwbmTzBFT0[/youtube]',
+                       ],
+                       'task-14940-youtube-embed-with-www' => [
+                               'expectedBBCode' => '[url=https://www.youtube.com/watch?v=hfwbmTzBFT0]https://www.youtube.com/watch?v=hfwbmTzBFT0[/url]',
+                               'text'         => '[youtube]https://www.youtube.com/embed/hfwbmTzBFT0[/youtube]',
+                       ],
+                       'task-14940-youtube-embed-without-www' => [
+                               'expectedBBCode' => '[url=https://www.youtube.com/watch?v=hfwbmTzBFT0]https://www.youtube.com/watch?v=hfwbmTzBFT0[/url]',
+                               'text'         => '[youtube]https://youtube.com/embed/hfwbmTzBFT0[/youtube]',
+                       ],
+                       'task-14940-vimeo' => [
+                               'expectedBBCode' => '[url=https://vimeo.com/2345345]https://vimeo.com/2345345[/url]',
+                               'text'         => '[vimeo]https://vimeo.com/2345345[/vimeo]',
+                       ],
+                       'task-14940-player-vimeo' => [
+                               'expectedBBCode' => '[url=https://vimeo.com/2345345]https://vimeo.com/2345345[/url]',
+                               'text'         => '[vimeo]https://player.vimeo.com/video/2345345[/vimeo]',
+                       ],
+               ];
+       }
+
+       /**
+        * @dataProvider dataExpandVideoLinks
+        *
+        * @param string $expected Expected BBCode output
+        * @param string $text     Input text
+        */
+       public function testExpandVideoLinks(string $expected, string $text)
+       {
+               $actual = BBCode::expandVideoLinks($text);
+
+               self::assertEquals($expected, $actual);
+       }
+
        public function dataGetAbstract(): array
        {
                return [
index 6882bec7f130ba06f73861b77141d6f8ec527397..2174b7670c61152d8913fd4ba13a51426c0f343b 100644 (file)
@@ -53,6 +53,44 @@ class MarkdownTest extends FixtureTestCase
                                'expectedBBCode' => 'with the <sup> and </sup> tag',
                                'markdown' => 'with the &lt;sup&gt; and &lt;/sup&gt; tag',
                        ],
+                       /** @see https://github.com/friendica/friendica/pull/14940 */
+                       'task-14940-youtube-watch-with-www' => [
+                               'expectedBBCode' => '[youtube]hfwbmTzBFT0[/youtube]',
+                               'markdown'         => '[url=https://www.youtube.com/watch?v=hfwbmTzBFT0]https://www.youtube.com/watch?v=hfwbmTzBFT0[/url]',
+                       ],
+                       'task-14940-youtube-watch-without-www' => [
+                               'expectedBBCode' => '[youtube]hfwbmTzBFT0[/youtube]',
+                               'markdown'         => '[url=https://youtube.com/watch?v=hfwbmTzBFT0]https://youtube.com/watch?v=hfwbmTzBFT0[/url]',
+                       ],
+                       'task-14940-youtube-shorts-with-www' => [
+                               'expectedBBCode' => '[youtube]hfwbmTzBFT0[/youtube]',
+                               'markdown'         => '[url=https://www.youtube.com/shorts/hfwbmTzBFT0]https://www.youtube.com/shorts/hfwbmTzBFT0[/url]',
+                       ],
+                       'task-14940-youtube-shorts-without-www' => [
+                               'expectedBBCode' => '[youtube]hfwbmTzBFT0[/youtube]',
+                               'markdown'         => '[url=https://youtube.com/shorts/hfwbmTzBFT0]https://youtube.com/shorts/hfwbmTzBFT0[/url]',
+                       ],
+                       'task-14940-youtube-embed-with-www' => [
+                               'expectedBBCode' => '[youtube]hfwbmTzBFT0[/youtube]',
+                               'markdown'         => '[url=https://www.youtube.com/embed/hfwbmTzBFT0]https://www.youtube.com/embed/hfwbmTzBFT0[/url]',
+                       ],
+                       'task-14940-youtube-embed-without-www' => [
+                               'expectedBBCode' => '[youtube]hfwbmTzBFT0[/youtube]',
+                               'markdown'         => '[url=https://youtube.com/embed/hfwbmTzBFT0]https://youtube.com/embed/hfwbmTzBFT0[/url]',
+                       ],
+                       // @todo - should we really ignore the URL content in favor of parsing the link of the body?
+                       'task-14940-vimeo-custom-url' => [
+                               'expectedBBCode' => '[vimeo]2345345[/vimeo]',
+                               'markdown'         => '[url=https://no.thing]https://vimeo.com/2345345[/url]',
+                       ],
+                       'task-14940-vimeo-custom-text' => [
+                               'expectedBBCode' => '[vimeo]2345345[/vimeo]',
+                               'markdown'         => '[url=https://vimeo.com/2345345]CustomText[/url]',
+                       ],
+                       'task-14940-player-vimeo' => [
+                               'expectedBBCode' => '[vimeo]2345345[/vimeo]',
+                               'markdown'         => '[url=https://player.vimeo.com/video/2345345]https://player.vimeo.com/video/2345345[/url]',
+                       ],
                ];
        }