]> git.mxchange.org Git - friendica.git/blob - tests/src/Content/Text/HTMLTest.php
Tests, still ongoing ...
[friendica.git] / tests / src / Content / Text / HTMLTest.php
1 <?php
2
3 namespace Friendica\Test\src\Content\Text;
4
5 use Friendica\Content\Text\HTML;
6 use Friendica\Test\MockedTest;
7 use Friendica\Test\Util\AppMockTrait;
8 use Friendica\Test\Util\VFSTrait;
9
10 class HTMLTest extends MockedTest
11 {
12         use VFSTrait;
13         use AppMockTrait;
14
15         protected function setUp()
16         {
17                 parent::setUp();
18                 $this->setUpVfsDir();
19                 $this->mockApp($this->root);
20         }
21
22         public function dataHTML()
23         {
24                 $inputFiles = glob(__DIR__ . '/../../../datasets/content/text/html/*.html');
25
26                 $data = [];
27
28                 foreach ($inputFiles as $file) {
29                         $data[str_replace('.html', '', $file)] = [
30                                 'input'    => file_get_contents($file),
31                                 'expected' => file_get_contents(str_replace('.html', '.txt', $file))
32                         ];
33                 }
34
35                 return $data;
36         }
37
38         /**
39          * Test convert different input Markdown text into HTML
40          *
41          * @dataProvider dataHTML
42          *
43          * @param string $input    The Markdown text to test
44          * @param string $expected The expected HTML output
45          * @throws \Exception
46          */
47         public function testToPlaintext($input, $expected)
48         {
49                 $output = HTML::toPlaintext($input, 0);
50
51                 $this->assertEquals($expected, $output);
52         }
53
54         public function dataHTMLText()
55         {
56                 return [
57                         'bug-7665-audio-tag' => [
58                                 'expectedBBCode' => '[audio]http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3[/audio]',
59                                 'html' => '<audio src="http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3" controls="controls"><a href="http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3">http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3</a></audio>',
60                         ],
61                         'bug-8075-html-tags' => [
62                                 'expectedBBCode' => "<big rant here> I don't understand tests",
63                                 'html' => "&lt;big rant here&gt; I don't understand tests",
64                         ],
65                 ];
66         }
67
68         /**
69          * Test convert bbcodes to HTML
70          *
71          * @dataProvider dataHTMLText
72          *
73          * @param string $expectedBBCode Expected BBCode output
74          * @param string $html           HTML text
75          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
76          */
77         public function testToBBCode($expectedBBCode, $html)
78         {
79                 $actual = HTML::toBBCode($html);
80
81                 $this->assertEquals($expectedBBCode, $actual);
82         }
83 }