X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FContent%2FText%2FBBCodeTest.php;h=ed33306edf85bb395504bf53293374d669a387f3;hb=71181704d48307b14b0c78a3bfd6957d5e7bdd3c;hp=802a90278b9ec33c1b2070033b2ed4539fd0a531;hpb=7406c9328b634f43a7c30ff11dfdbbcecc312b11;p=friendica.git diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 802a90278b..ed33306edf 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -2,21 +2,17 @@ namespace Friendica\Test\src\Content\Text; +use Friendica\App\BaseURL; use Friendica\Content\Text\BBCode; +use Friendica\Core\L10n\L10n; use Friendica\Test\MockedTest; use Friendica\Test\Util\AppMockTrait; -use Friendica\Test\Util\L10nMockTrait; use Friendica\Test\Util\VFSTrait; -/** - * @runTestsInSeparateProcesses - * @preserveGlobalState disabled - */ class BBCodeTest extends MockedTest { use VFSTrait; use AppMockTrait; - use L10nMockTrait; protected function setUp() { @@ -40,7 +36,21 @@ class BBCodeTest extends MockedTest $this->configMock->shouldReceive('get') ->with('system', 'url') ->andReturn('friendica.local'); - $this->mockL10nT(); + $this->configMock->shouldReceive('get') + ->with('system', 'no_smilies') + ->andReturn(false); + + $l10nMock = \Mockery::mock(L10n::class); + $l10nMock->shouldReceive('t')->withAnyArgs()->andReturnUsing(function ($args) { return $args; }); + $this->dice->shouldReceive('create') + ->with(L10n::class) + ->andReturn($l10nMock); + + $baseUrlMock = \Mockery::mock(BaseURL::class); + $baseUrlMock->shouldReceive('get')->withAnyArgs()->andReturn('friendica.local'); + $this->dice->shouldReceive('create') + ->with(BaseURL::class) + ->andReturn($baseUrlMock); } public function dataLinks() @@ -109,6 +119,18 @@ class BBCodeTest extends MockedTest 'data' => "http://example.com
<
',
+ 'text' => '[code]<[/code]',
+ ],
+ 'bug-7808-code-gt' => [
+ 'expectedHtml' => '>
',
+ 'text' => '[code]>[/code]',
+ ],
+ 'bug-7808-code-amp' => [
+ 'expectedHtml' => '&
',
+ 'text' => '[code]&[/code]',
+ ]
+ ];
+ }
+
+ /**
+ * Test convert bbcodes to HTML
+ *
+ * @dataProvider dataBBCodes
+ *
+ * @param string $expectedHtml Expected HTML output
+ * @param string $text BBCode text
+ * @param bool $try_oembed Whether to convert multimedia BBCode tag
+ * @param int $simpleHtml BBCode::convert method $simple_html parameter value, optional.
+ * @param bool $forPlaintext BBCode::convert method $for_plaintext parameter value, optional.
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ public function testConvert($expectedHtml, $text, $try_oembed = false, $simpleHtml = 0, $forPlaintext = false)
+ {
+ $actual = BBCode::convert($text, $try_oembed, $simpleHtml, $forPlaintext);
+
+ $this->assertEquals($expectedHtml, $actual);
+ }
+
+ public function dataBBCodesToMarkdown()
+ {
+ return [
+ 'bug-7808-gt' => [
+ 'expected' => '>`>`',
+ 'text' => '>[code]>[/code]',
+ ],
+ 'bug-7808-lt' => [
+ 'expected' => '<`<`',
+ 'text' => '<[code]<[/code]',
+ ],
+ 'bug-7808-amp' => [
+ 'expected' => '&`&`',
+ '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);
+ }
}