From 39a537c415fad16c51e1422ff32ab60ac76da6b8 Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <hypolite@mrpetovan.com>
Date: Fri, 20 Dec 2019 23:20:41 -0500
Subject: [PATCH] Added test for BBCode to Markdown chevron issue

- See https://github.com/friendica/friendica/issues/7808

Add tests
---
 tests/src/Content/Text/BBCodeTest.php | 47 +++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php
index 1ff653db9..ed33306ed 100644
--- a/tests/src/Content/Text/BBCodeTest.php
+++ b/tests/src/Content/Text/BBCodeTest.php
@@ -203,6 +203,18 @@ class BBCodeTest extends MockedTest
 				'text' => '[audio]http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3[/audio]',
 				'try_oembed' => true,
 			],
+			'bug-7808-code-lt' => [
+				'expectedHtml' => '<code>&lt;</code>',
+				'text' => '[code]<[/code]',
+			],
+			'bug-7808-code-gt' => [
+				'expectedHtml' => '<code>&gt;</code>',
+				'text' => '[code]>[/code]',
+			],
+			'bug-7808-code-amp' => [
+				'expectedHtml' => '<code>&amp;</code>',
+				'text' => '[code]&[/code]',
+			]
 		];
 	}
 
@@ -224,4 +236,39 @@ class BBCodeTest extends MockedTest
 
 		$this->assertEquals($expectedHtml, $actual);
 	}
+
+	public function dataBBCodesToMarkdown()
+	{
+		return [
+			'bug-7808-gt' => [
+				'expected' => '&gt;`>`',
+				'text' => '>[code]>[/code]',
+			],
+			'bug-7808-lt' => [
+				'expected' => '&lt;`<`',
+				'text' => '<[code]<[/code]',
+			],
+			'bug-7808-amp' => [
+				'expected' => '&amp;`&`',
+				'text' => '&[code]&[/code]',
+			],
+		];
+	}
+
+	/**
+	 * Test convert bbcodes to Markdown
+	 *
+	 * @dataProvider dataBBCodesToMarkdown
+	 *
+	 * @param string $expected     Expected Markdown output
+	 * @param string $text         BBCode text
+	 * @param bool   $for_diaspora
+	 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+	 */
+	public function testToMarkdown($expected, $text, $for_diaspora = false)
+	{
+		$actual = BBCode::toMarkdown($text, $for_diaspora);
+
+		$this->assertEquals($expected, $actual);
+	}
 }