Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
9.80% covered (danger)
9.80%
5 / 51
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_textformatter_s9e_acp_utils_test
9.80% covered (danger)
9.80%
5 / 51
50.00% covered (danger)
50.00%
1 / 2
4.94
0.00% covered (danger)
0.00%
0 / 1
 test_analyse_bbcode
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 get_analyse_bbcode_tests
0.00% covered (danger)
0.00%
0 / 46
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class phpbb_textformatter_s9e_acp_utils_test extends phpbb_test_case
15{
16    /**
17    * @dataProvider get_analyse_bbcode_tests
18    */
19    public function test_analyse_bbcode($definition, $template, $expected)
20    {
21        $container = $this->get_test_case_helpers()->set_s9e_services();
22        $factory   = $container->get('text_formatter.s9e.factory');
23        $acp_utils = new \phpbb\textformatter\s9e\acp_utils($factory);
24        $actual    = $acp_utils->analyse_bbcode($definition, $template);
25
26        $this->assertEquals($expected, $actual);
27    }
28
29    public static function get_analyse_bbcode_tests()
30    {
31        return [
32            [
33                '[x]{TEXT}[/x]',
34                '<b>{TEXT}</b>',
35                [
36                    'status' => 'safe',
37                    'name'   => 'X'
38                ]
39            ],
40            [
41                '[hr]',
42                '<hr>',
43                [
44                    'status' => 'safe',
45                    'name'   => 'HR'
46                ]
47            ],
48            [
49                '[x]{TEXT}[/x]',
50                '<script>{TEXT}</script>',
51                [
52                    'status'     => 'unsafe',
53                    'name'       => 'X',
54                    'error_text' => 'Cannot allow unfiltered data in this context',
55                    'error_html' => '&lt;script&gt;
56  <span class="highlight">&lt;xsl:apply-templates/&gt;</span>
57&lt;/script&gt;'
58                ]
59            ],
60            [
61                '???',
62                '<hr>',
63                [
64                    'status'     => 'invalid_definition',
65                    'error_text' => 'Cannot interpret the BBCode definition'
66                ]
67            ],
68            [
69                '[x]{TEXT}[/x]',
70                '<xsl:invalid',
71                [
72                    'status'     => 'invalid_template',
73                    'name'       => 'X',
74                    'error_text' => "Invalid XSL: Couldn't find end of Start Tag invalid line 1\n"
75                ]
76            ],
77        ];
78    }
79}