aboutsummaryrefslogtreecommitdiffstats
path: root/tests/text_formatter/s9e/utils_test.php
blob: 510beba8171601f59b33193d73253705de208991 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
*
* @package testing
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

require_once __DIR__ . '/../../../phpBB/includes/functions.php';
require_once __DIR__ . '/../../../phpBB/includes/functions_content.php';

class phpbb_textformatter_s9e_utils_test extends phpbb_test_case
{
	/**
	* @dataProvider get_unparse_tests
	*/
	public function test_unparse($original, $expected)
	{
		$container = $this->get_test_case_helpers()->set_s9e_services();
		$utils     = $container->get('text_formatter.utils');

		$this->assertSame($expected, $utils->unparse($original));
	}

	public function get_unparse_tests()
	{
		return array(
			array(
				'<t>Plain text</t>',
				'Plain text'
			),
			array(
				"<t>Multi<br/>\nline</t>",
				"Multi\nline"
			),
			array(
				'<r><B><s>[b]</s>bold<e>[/b]</e></B></r>',
				'[b]bold[/b]'
			)
		);
	}

	/**
	* @dataProvider get_remove_formatting_tests
	*/
	public function test_remove_formatting($original, $expected)
	{
		$container = $this->get_test_case_helpers()->set_s9e_services();
		$utils     = $container->get('text_formatter.utils');

		$this->assertSame($expected, $utils->remove_formatting($original));
	}

	public function get_remove_formatting_tests()
	{
		return array(
			array(
				'<t>Plain text</t>',
				'Plain text'
			),
			array(
				"<t>Multi<br/>\nline</t>",
				"Multi\nline"
			),
			array(
				'<r><B><s>[b]</s>bold<e>[/b]</e></B></r>',
				'bold'
			)
		);
	}

	/**
	* @dataProvider get_clean_formatting_tests
	*/
	public function test_clean_formatting($original, $expected)
	{
		$container = $this->get_test_case_helpers()->set_s9e_services();
		$utils     = $container->get('text_formatter.utils');

		$this->assertSame($expected, $utils->clean_formatting($original));
	}

	public function get_clean_formatting_tests()
	{
		return array(
			array(
				'<t>Plain text</t>',
				'Plain text'
			),
			array(
				"<t>Multi<br/>\nline</t>",
				"Multi\nline"
			),
			array(
				'<r><B><s>[b]</s>bold<e>[/b]</e></B></r>',
				' bold '
			)
		);
	}

	/**
	* @dataProvider get_remove_bbcode_tests
	*/
	public function test_remove_bbcode($original, $name, $depth, $expected)
	{
		$container = $this->get_test_case_helpers()->set_s9e_services();
		$utils     = $container->get('text_formatter.utils');

		$this->assertSame($expected, $utils->remove_bbcode($original, $name, $depth));
	}

	public function get_remove_bbcode_tests()
	{
		return array(
			array(
				'<t>Plain text</t>',
				'b',
				1,
				'<t>Plain text</t>'
			),
			array(
				'<r><QUOTE author="u0"><s>[quote="u0"]</s><QUOTE author="u1"><s>[quote="u1"]</s><QUOTE author="u2"><s>[quote="u2"]</s>q2<e>[/quote]</e></QUOTE>
q1<e>[/quote]</e></QUOTE>
q0<e>[/quote]</e></QUOTE>
<B><s>[b]</s>bold<e>[/b]</e></B></r>',
				'quote',
				0,
				'<r>
<B><s>[b]</s>bold<e>[/b]</e></B></r>'
			),
			array(
				'<r><QUOTE author="u0"><s>[quote="u0"]</s><QUOTE author="u1"><s>[quote="u1"]</s><QUOTE author="u2"><s>[quote="u2"]</s>q2<e>[/quote]</e></QUOTE>
q1<e>[/quote]</e></QUOTE>
q0<e>[/quote]</e></QUOTE>
<B><s>[b]</s>bold<e>[/b]</e></B></r>',
				'quote',
				1,
				'<r><QUOTE author="u0"><s>[quote="u0"]</s>
q0<e>[/quote]</e></QUOTE>
<B><s>[b]</s>bold<e>[/b]</e></B></r>'
			),
			array(
				'<r><QUOTE author="u0"><s>[quote="u0"]</s><QUOTE author="u1"><s>[quote="u1"]</s><QUOTE author="u2"><s>[quote="u2"]</s>q2<e>[/quote]</e></QUOTE>
q1<e>[/quote]</e></QUOTE>
q0<e>[/quote]</e></QUOTE>
<B><s>[b]</s>bold<e>[/b]</e></B></r>',
				'quote',
				2,
				'<r><QUOTE author="u0"><s>[quote="u0"]</s><QUOTE author="u1"><s>[quote="u1"]</s>
q1<e>[/quote]</e></QUOTE>
q0<e>[/quote]</e></QUOTE>
<B><s>[b]</s>bold<e>[/b]</e></B></r>'
			),
		);
	}
}