aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2024-10-12 18:19:43 +0200
committerHarald Eilertsen <haraldei@anduin.net>2024-10-12 18:19:43 +0200
commitecde4a3dede85bfa0fa32a91c51c335716c68c4c (patch)
tree843a45cb8c1106b64b34035385cb13ae6e206c7e /tests/unit
parent687cda367316edb9f84b3e425e76c9e9279e96be (diff)
downloadvolse-hubzilla-ecde4a3dede85bfa0fa32a91c51c335716c68c4c.tar.gz
volse-hubzilla-ecde4a3dede85bfa0fa32a91c51c335716c68c4c.tar.bz2
volse-hubzilla-ecde4a3dede85bfa0fa32a91c51c335716c68c4c.zip
Change config used by Markdown tests to reflect actual use.
This makes the configuration used align better with how it is being used in the mdpost addon. This also reveals some issues that are less than ideal for Markdown posts. The relevant test cases have been adjusted to pass with the new config, but have been commented.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/includes/BBCodeTest.php8
-rw-r--r--tests/unit/includes/MarkdownTest.php33
2 files changed, 31 insertions, 10 deletions
diff --git a/tests/unit/includes/BBCodeTest.php b/tests/unit/includes/BBCodeTest.php
index c6a60f35b..136fc6e0e 100644
--- a/tests/unit/includes/BBCodeTest.php
+++ b/tests/unit/includes/BBCodeTest.php
@@ -143,6 +143,14 @@ class BBCodeTest extends UnitTestCase {
'example url: https://example.com',
'example url: <a href="https://example.com" target="_blank" rel="nofollow noopener">https://example.com</a>'
],
+ 'naked url followed by newline' => [
+ "https://www.example.com\nhave a great day.",
+ '<a href="https://www.example.com" target="_blank" rel="nofollow noopener">https://www.example.com</a><br />have a great day.',
+ ],
+ 'inline naked url' => [
+ "This is a link https://example.com/some/path more info.",
+ 'This is a link <a href="https://example.com/some/path" target="_blank" rel="nofollow noopener">https://example.com/some/path</a> more info.',
+ ],
'naked url within code block is not converted to link' => [
"[code]\nhttp://example.com\n[/code]",
"<pre><code>http://example.com</code></pre>"
diff --git a/tests/unit/includes/MarkdownTest.php b/tests/unit/includes/MarkdownTest.php
index 217d12ca2..55dbb4445 100644
--- a/tests/unit/includes/MarkdownTest.php
+++ b/tests/unit/includes/MarkdownTest.php
@@ -36,7 +36,7 @@ class MarkdownTest extends UnitTestCase {
* @dataProvider markdown_to_bbcode_provider
*/
public function test_markdown_to_bbcode(string $expected, string $src): void {
- $this->assertEquals($expected, markdown_to_bb($src));
+ $this->assertEquals($expected, markdown_to_bb($src, true, ['preserve_lf' => true]));
}
public static function markdown_to_bbcode_provider(): array {
@@ -54,11 +54,14 @@ class MarkdownTest extends UnitTestCase {
'This is a test of **bold text**, *italic text* and ***bold and italic text***'
],
'multiline text' => [
- 'This text is text wrapped over multiple lines.',
+ // This is not as expected in markdown, but may be needed
+ // for compatibility with bbcode behaviour.
+ "This text is\ntext wrapped\nover multiple\nlines.",
"This text is\ntext wrapped\nover multiple\nlines."
],
'text with hard linebreak' => [
- "Line one\nLine two",
+ // An extra line break is inserted here...
+ "Line one\n\nLine two",
"Line one \nLine two"
],
'paragraphs' => [
@@ -78,29 +81,39 @@ class MarkdownTest extends UnitTestCase {
'`some code`'
],
'inline code with wrapped text' => [
- '[code]some code unwrapped[/code]',
+ // Not sure if the newline should be preseved here?
+ "[code]some code\nunwrapped[/code]",
"`some code\n unwrapped`"
],
'code block no language' => [
- "[code]some code\nover multiple lines[/code]",
+ "[code]some code\nover multiple lines\n[/code]",
"```\nsome code\nover multiple lines\n```"
],
'code block no language indented' => [
- "[code]some code\n over multiple lines\n with indentation[/code]",
+ // For some reason one space char is eaten on indented lines.
+ "[code]some code\n over multiple lines\n with indentation\n[/code]",
"```\nsome code\n over multiple lines\n with indentation\n```"
],
'code block with language' => [
- "[code=php]&lt;?php\necho phpinfo();[/code]",
+ "[code=php]&lt;?php\necho phpinfo();\n[/code]",
"```php\n<?php\necho phpinfo();\n```"
],
'code block with URL' => [
- "[code]an example url https://example.com[/code]",
+ "[code]an example url https://example.com\n[/code]",
"```\nan example url https://example.com\n```"
],
'bbcode code block with URL' => [
- "[code] proxy_pass http://example.com; [/code]",
+ "[code]\nproxy_pass http://example.com;\n[/code]",
"[code]\nproxy_pass http://example.com;\n[/code]"
- ]
+ ],
+ 'naked url followed by newline' => [
+ "https://example.com\nhave a great day.",
+ "https://example.com\nhave a great day.",
+ ],
+ 'inline naked url' => [
+ 'This is a link https://example.com/some/path more info.',
+ 'This is a link https://example.com/some/path more info.',
+ ],
];
}