Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
9.31% |
19 / 204 |
|
50.00% |
5 / 10 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_textformatter_s9e_utils_test | |
9.31% |
19 / 204 |
|
50.00% |
5 / 10 |
84.58 | |
0.00% |
0 / 1 |
| test_unparse | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| get_unparse_tests | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |||
| test_clean_formatting | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| get_clean_formatting_tests | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
2 | |||
| test_get_outermost_quote_authors | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| get_outermost_quote_authors_tests | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
2 | |||
| test_generate_quote | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| get_generate_quote_tests | |
0.00% |
0 / 105 |
|
0.00% |
0 / 1 |
2 | |||
| test_remove_bbcode | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| get_remove_bbcode_tests | |
0.00% |
0 / 26 |
|
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 | |
| 14 | class phpbb_textformatter_s9e_utils_test extends phpbb_test_case |
| 15 | { |
| 16 | /** |
| 17 | * @dataProvider get_unparse_tests |
| 18 | */ |
| 19 | public function test_unparse($original, $expected) |
| 20 | { |
| 21 | $container = $this->get_test_case_helpers()->set_s9e_services(); |
| 22 | $utils = $container->get('text_formatter.utils'); |
| 23 | |
| 24 | $this->assertSame($expected, $utils->unparse($original)); |
| 25 | } |
| 26 | |
| 27 | public static function get_unparse_tests() |
| 28 | { |
| 29 | return array( |
| 30 | array( |
| 31 | '<t>Plain text</t>', |
| 32 | 'Plain text' |
| 33 | ), |
| 34 | array( |
| 35 | "<t>Multi<br/>\nline</t>", |
| 36 | "Multi\nline" |
| 37 | ), |
| 38 | array( |
| 39 | '<r><B><s>[b]</s>bold<e>[/b]</e></B></r>', |
| 40 | '[b]bold[/b]' |
| 41 | ) |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @dataProvider get_clean_formatting_tests |
| 47 | */ |
| 48 | public function test_clean_formatting($original, $expected) |
| 49 | { |
| 50 | $container = $this->get_test_case_helpers()->set_s9e_services(); |
| 51 | $utils = $container->get('text_formatter.utils'); |
| 52 | |
| 53 | $this->assertSame($expected, $utils->clean_formatting($original)); |
| 54 | } |
| 55 | |
| 56 | public static function get_clean_formatting_tests() |
| 57 | { |
| 58 | return array( |
| 59 | array( |
| 60 | '<t>Plain text</t>', |
| 61 | 'Plain text' |
| 62 | ), |
| 63 | array( |
| 64 | '<t>Plain & boring</t>', |
| 65 | 'Plain & boring' |
| 66 | ), |
| 67 | array( |
| 68 | "<t>Multi<br/>\nline</t>", |
| 69 | "Multi\nline" |
| 70 | ), |
| 71 | array( |
| 72 | '<r><B><s>[b]</s>bold<e>[/b]</e></B> & <I><s>[i]</s>italic<e>[/i]</e></I></r>', |
| 73 | ' bold & italic ' |
| 74 | ) |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @dataProvider get_outermost_quote_authors_tests |
| 80 | */ |
| 81 | public function test_get_outermost_quote_authors($original, $expected) |
| 82 | { |
| 83 | $container = $this->get_test_case_helpers()->set_s9e_services(); |
| 84 | $utils = $container->get('text_formatter.utils'); |
| 85 | $parser = $container->get('text_formatter.parser'); |
| 86 | |
| 87 | $this->assertSame($expected, $utils->get_outermost_quote_authors($parser->parse($original))); |
| 88 | } |
| 89 | |
| 90 | public static function get_outermost_quote_authors_tests() |
| 91 | { |
| 92 | return array( |
| 93 | array( |
| 94 | 'No quotes here', |
| 95 | array() |
| 96 | ), |
| 97 | array( |
| 98 | '[quote="foo"]..[/quote] [quote]..[/quote]', |
| 99 | array('foo') |
| 100 | ), |
| 101 | array( |
| 102 | '[quote=foo]..[/quote] [quote]..[/quote]', |
| 103 | array('foo') |
| 104 | ), |
| 105 | array( |
| 106 | '[quote=foo]..[/quote] [quote=bar]..[/quote]', |
| 107 | array('foo', 'bar') |
| 108 | ), |
| 109 | array( |
| 110 | '[quote=foo].[quote=baz]..[/quote].[/quote] [quote=bar]..[/quote]', |
| 111 | array('foo', 'bar') |
| 112 | ), |
| 113 | ); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @dataProvider get_generate_quote_tests |
| 118 | */ |
| 119 | public function test_generate_quote($text, $params, $expected) |
| 120 | { |
| 121 | $container = $this->get_test_case_helpers()->set_s9e_services(); |
| 122 | $utils = $container->get('text_formatter.utils'); |
| 123 | |
| 124 | $this->assertSame($expected, $utils->generate_quote($text, $params)); |
| 125 | } |
| 126 | |
| 127 | public static function get_generate_quote_tests() |
| 128 | { |
| 129 | return array( |
| 130 | array( |
| 131 | '...', |
| 132 | array(), |
| 133 | '[quote]...[/quote]', |
| 134 | ), |
| 135 | array( |
| 136 | '...', |
| 137 | array('author' => 'Brian Kibler'), |
| 138 | '[quote="Brian Kibler"]...[/quote]', |
| 139 | ), |
| 140 | array( |
| 141 | '...', |
| 142 | array('author' => 'Brian "Brian Kibler" Kibler of Brian Kibler Gaming'), |
| 143 | '[quote=\'Brian "Brian Kibler" Kibler of Brian Kibler Gaming\']...[/quote]', |
| 144 | ), |
| 145 | array( |
| 146 | '...', |
| 147 | array('author' => "Brian Kibler Gaming's Brian Kibler"), |
| 148 | '[quote="Brian Kibler Gaming\'s Brian Kibler"]...[/quote]', |
| 149 | ), |
| 150 | array( |
| 151 | '...', |
| 152 | array('author' => "\\\"'"), |
| 153 | '[quote="\\\\\\"\'"]...[/quote]', |
| 154 | ), |
| 155 | array( |
| 156 | '...', |
| 157 | array('author' => 'Lots of doubles """ one single \' one backslash \\'), |
| 158 | '[quote=\'Lots of doubles """ one single \\\' one backslash \\\\\']...[/quote]', |
| 159 | ), |
| 160 | array( |
| 161 | '...', |
| 162 | array('author' => "Lots of singles ''' one double \" one backslash \\"), |
| 163 | '[quote="Lots of singles \'\'\' one double \\" one backslash \\\\"]...[/quote]', |
| 164 | ), |
| 165 | array( |
| 166 | '...', |
| 167 | array('author' => 'Defaults to doublequotes """\'\'\''), |
| 168 | '[quote="Defaults to doublequotes \\"\\"\\"\'\'\'"]...[/quote]', |
| 169 | ), |
| 170 | array( |
| 171 | '...', |
| 172 | array( |
| 173 | 'author' => 'user', |
| 174 | 'post_id' => 123, |
| 175 | 'url' => 'http://example.org' |
| 176 | ), |
| 177 | '[quote=user post_id=123 url=http://example.org]...[/quote]', |
| 178 | ), |
| 179 | array( |
| 180 | '...', |
| 181 | array( |
| 182 | 'author' => 'user', |
| 183 | 'post_id' => 123, |
| 184 | 'user_id' => ANONYMOUS |
| 185 | ), |
| 186 | '[quote=user post_id=123]...[/quote]', |
| 187 | ), |
| 188 | array( |
| 189 | '...', |
| 190 | array('author' => ' '), |
| 191 | '[quote=" "]...[/quote]', |
| 192 | ), |
| 193 | array( |
| 194 | '...', |
| 195 | array('author' => 'foo bar'), |
| 196 | '[quote="foo bar"]...[/quote]', |
| 197 | ), |
| 198 | array( |
| 199 | '...', |
| 200 | array('author' => '\\'), |
| 201 | '[quote="\\\\"]...[/quote]', |
| 202 | ), |
| 203 | array( |
| 204 | '...', |
| 205 | array('author' => '[quote="foo"]'), |
| 206 | '[quote=\'[quote="foo"]\']...[/quote]', |
| 207 | ), |
| 208 | array( |
| 209 | '...', |
| 210 | array('author' => '""'), |
| 211 | '[quote=\'""\']...[/quote]', |
| 212 | ), |
| 213 | array( |
| 214 | '...', |
| 215 | array('author' => "''"), |
| 216 | '[quote="\'\'"]...[/quote]', |
| 217 | ), |
| 218 | array( |
| 219 | 'This is a long quote that is definitely going to exceed 80 characters', |
| 220 | array(), |
| 221 | "[quote]\nThis is a long quote that is definitely going to exceed 80 characters\n[/quote]", |
| 222 | ), |
| 223 | array( |
| 224 | ' This is a short quote on its own line ', |
| 225 | array(), |
| 226 | '[quote]This is a short quote on its own line[/quote]', |
| 227 | ), |
| 228 | array( |
| 229 | "This is a short quote\non two lines", |
| 230 | array(), |
| 231 | "[quote]\nThis is a short quote\non two lines\n[/quote]", |
| 232 | ), |
| 233 | ); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * @dataProvider get_remove_bbcode_tests |
| 238 | */ |
| 239 | public function test_remove_bbcode($original, $name, $depth, $expected) |
| 240 | { |
| 241 | $container = $this->get_test_case_helpers()->set_s9e_services(); |
| 242 | $parser = $container->get('text_formatter.parser'); |
| 243 | $utils = $container->get('text_formatter.utils'); |
| 244 | |
| 245 | $parsed = $parser->parse($original); |
| 246 | $actual = $utils->unparse($utils->remove_bbcode($parsed, $name, $depth)); |
| 247 | |
| 248 | $this->assertSame($expected, $actual); |
| 249 | } |
| 250 | |
| 251 | public static function get_remove_bbcode_tests() |
| 252 | { |
| 253 | return array( |
| 254 | array( |
| 255 | 'Plain text', |
| 256 | 'b', |
| 257 | 1, |
| 258 | 'Plain text' |
| 259 | ), |
| 260 | array( |
| 261 | '[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]', |
| 262 | 'quote', |
| 263 | 0, |
| 264 | '[b]bold[/b]', |
| 265 | ), |
| 266 | array( |
| 267 | '[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]', |
| 268 | 'quote', |
| 269 | 1, |
| 270 | '[quote="u0"]q0[/quote][b]bold[/b]', |
| 271 | ), |
| 272 | array( |
| 273 | '[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]', |
| 274 | 'quote', |
| 275 | 2, |
| 276 | '[quote="u0"][quote="u1"]q1[/quote]q0[/quote][b]bold[/b]', |
| 277 | ), |
| 278 | ); |
| 279 | } |
| 280 | } |