Add tests for autolinker in BBCde::convert
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 9 Mar 2019 15:17:36 +0000 (10:17 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 9 Mar 2019 15:20:51 +0000 (10:20 -0500)
tests/src/Content/Text/BBCodeTest.php [new file with mode: 0644]

diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php
new file mode 100644 (file)
index 0000000..f155eee
--- /dev/null
@@ -0,0 +1,111 @@
+<?php\r
+\r
+namespace Friendica\Test\src\Content\Text;\r
+\r
+use Friendica\Content\Text\BBCode;\r
+use Friendica\Test\MockedTest;\r
+use Friendica\Test\Util\AppMockTrait;\r
+use Friendica\Test\Util\L10nMockTrait;\r
+use Friendica\Test\Util\VFSTrait;\r
+\r
+/**\r
+ * @runTestsInSeparateProcesses\r
+ * @preserveGlobalState disabled\r
+ */\r
+class BBCodeTest extends MockedTest\r
+{\r
+       use VFSTrait;\r
+       use AppMockTrait;\r
+       use L10nMockTrait;\r
+\r
+       protected function setUp()\r
+       {\r
+               parent::setUp();\r
+               $this->setUpVfsDir();\r
+               $this->mockApp($this->root);\r
+               $this->app->videowidth = 425;\r
+               $this->app->videoheight = 350;\r
+               $this->configMock->shouldReceive('get')\r
+                       ->with('system', 'remove_multiplicated_lines')\r
+                       ->andReturn(false);\r
+               $this->configMock->shouldReceive('get')\r
+                       ->with('system', 'no_oembed')\r
+                       ->andReturn(false);\r
+               $this->configMock->shouldReceive('get')\r
+                       ->with('system', 'allowed_link_protocols')\r
+                       ->andReturn(null);\r
+               $this->configMock->shouldReceive('get')\r
+                       ->with('system', 'itemcache_duration')\r
+                       ->andReturn(-1);\r
+               $this->mockL10nT();\r
+       }\r
+\r
+       public function dataLinks()\r
+       {\r
+               return [\r
+                       /** @see https://github.com/friendica/friendica/issues/2487 */\r
+                       'bug-2487-1' => [\r
+                               'data' => 'https://de.wikipedia.org/wiki/Juha_Sipilä',\r
+                               'assertHTML' => true,\r
+                       ],\r
+                       'bug-2487-2' => [\r
+                               'data' => 'https://de.wikipedia.org/wiki/Dnepr_(Motorradmarke)',\r
+                               'assertHTML' => true,\r
+                       ],\r
+                       'bug-2487-3' => [\r
+                               'data' => 'https://friendica.wäckerlin.ch/friendica',\r
+                               'assertHTML' => true,\r
+                       ],\r
+                       'bug-2487-4' => [\r
+                               'data' => 'https://mastodon.social/@morevnaproject',\r
+                               'assertHTML' => true,\r
+                       ],\r
+                       /** @see https://github.com/friendica/friendica/issues/5795 */\r
+                       'bug-5795' => [\r
+                               'data' => 'https://social.nasqueron.org/@liw/100798039015010628',\r
+                               'assertHTML' => true,\r
+                       ],\r
+                       /** @see https://github.com/friendica/friendica/issues/6095 */\r
+                       'bug-6095' => [\r
+                               'data' => 'https://en.wikipedia.org/wiki/Solid_(web_decentralization_project)',\r
+                               'assertHTML' => true,\r
+                       ],\r
+                       'no-protocol' => [\r
+                               'data' => 'example.com/path',\r
+                               'assertHTML' => false\r
+                       ],\r
+                       'wrong-protocol' => [\r
+                               'data' => 'ftp://example.com',\r
+                               'assertHTML' => false\r
+                       ],\r
+                       'wrong-domain-without-path' => [\r
+                               'data' => 'http://example',\r
+                               'assertHTML' => false\r
+                       ],\r
+                       'wrong-domain-with-path' => [\r
+                               'data' => 'http://example/path',\r
+                               'assertHTML' => false\r
+                       ],\r
+               ];\r
+       }\r
+\r
+       /**\r
+        * Test convert different links inside a text\r
+        * @dataProvider dataLinks\r
+        *\r
+        * @param string $data The data to text\r
+        * @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)\r
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException\r
+        */\r
+       public function testAutoLinking($data, $assertHTML)\r
+       {\r
+               $output = BBCode::convert($data);\r
+               if ($assertHTML) {\r
+                       $assert = '<a href="' . $data . '" target="_blank">' . $data . '</a>';\r
+               } else {\r
+                       $assert = $data;\r
+               }\r
+\r
+               $this->assertEquals($assert, $output);\r
+       }\r
+}
\ No newline at end of file