aboutsummaryrefslogtreecommitdiffstats
path: root/tests/text_formatter/s9e/acp_utils_test.php
blob: 9d84924042e3c90cd88b194f0744809c331284b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

class phpbb_textformatter_s9e_acp_utils_test extends phpbb_test_case
{
	/**
	* @dataProvider get_analyse_bbcode_tests
	*/
	public function test_analyse_bbcode($definition, $template, $expected)
	{
		$container = $this->get_test_case_helpers()->set_s9e_services();
		$factory   = $container->get('text_formatter.s9e.factory');
		$acp_utils = new \phpbb\textformatter\s9e\acp_utils($factory);
		$actual    = $acp_utils->analyse_bbcode($definition, $template);

		$this->assertEquals($expected, $actual);
	}

	public function get_analyse_bbcode_tests()
	{
		return [
			[
				'[x]{TEXT}[/x]',
				'<b>{TEXT}</b>',
				[
					'status' => 'safe',
					'name'   => 'X'
				]
			],
			[
				'[hr]',
				'<hr>',
				[
					'status' => 'safe',
					'name'   => 'HR'
				]
			],
			[
				'[x]{TEXT}[/x]',
				'<script>{TEXT}</script>',
				[
					'status'     => 'unsafe',
					'name'       => 'X',
					'error_text' => 'Cannot allow unfiltered data in this context',
					'error_html' => '&lt;script&gt;
  <span class="highlight">&lt;xsl:apply-templates/&gt;</span>
&lt;/script&gt;'
				]
			],
			[
				'???',
				'<hr>',
				[
					'status'     => 'invalid_definition',
					'error_text' => 'Cannot interpret the BBCode definition'
				]
			],
			[
				'[x]{TEXT}[/x]',
				'<xsl:invalid',
				[
					'status'     => 'invalid_template',
					'name'       => 'X',
					'error_text' => "Invalid XSL: Couldn't find end of Start Tag invalid line 1\n"
				]
			],
		];
	}
}