Add new ignoreChildren behavior to HTML::tagToBBCode
[friendica.git/.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                 ];
62         }
63
64         /**
65          * Test convert bbcodes to HTML
66          *
67          * @dataProvider dataHTMLText
68          *
69          * @param string $expectedBBCode Expected BBCode output
70          * @param string $html           HTML text
71          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
72          */
73         public function testToBBCode($expectedBBCode, $html)
74         {
75                 $actual = HTML::toBBCode($html);
76
77                 $this->assertEquals($expectedBBCode, $actual);
78         }
79 }