Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 75 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functional_acp_bbcodes_test | |
0.00% |
0 / 75 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| test_htmlspecialchars | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
| test_bbcode_error | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| get_bbcode_error_tests | |
0.00% |
0 / 44 |
|
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 | /** |
| 15 | * @group functional |
| 16 | */ |
| 17 | class phpbb_functional_acp_bbcodes_test extends phpbb_functional_test_case |
| 18 | { |
| 19 | public function test_htmlspecialchars() |
| 20 | { |
| 21 | $this->login(); |
| 22 | $this->admin_login(); |
| 23 | |
| 24 | // Create the BBCode |
| 25 | $crawler = self::request('GET', 'adm/index.php?i=acp_bbcodes&sid=' . $this->sid . '&mode=bbcodes&action=add'); |
| 26 | $form = $crawler->selectButton('Submit')->form(array( |
| 27 | 'bbcode_match' => '[mod="{TEXT1}"]{TEXT2}[/mod]', |
| 28 | 'bbcode_tpl' => '<div>{TEXT1}</div><div>{TEXT2}</div>', |
| 29 | 'bbcode_font_icon' => 'user', |
| 30 | )); |
| 31 | self::submit($form); |
| 32 | |
| 33 | // Test it in the "new topic" preview |
| 34 | $crawler = self::request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid); |
| 35 | $form = $crawler->selectButton('Preview')->form(array( |
| 36 | 'subject' => 'subject', |
| 37 | 'message' => '[mod=a]b[/mod][mod="c"]d[/mod]' |
| 38 | )); |
| 39 | $crawler = self::submit($form); |
| 40 | |
| 41 | $html = $crawler->filter('#preview')->html(); |
| 42 | $this->assertStringContainsString('<div>a</div>', $html); |
| 43 | $this->assertStringContainsString('<div>b</div>', $html); |
| 44 | $this->assertStringContainsString('<div>c</div>', $html); |
| 45 | $this->assertStringContainsString('<div>d</div>', $html); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @dataProvider get_bbcode_error_tests |
| 50 | */ |
| 51 | public function test_bbcode_error($match, $tpl, $icon, $error) |
| 52 | { |
| 53 | $this->login(); |
| 54 | $this->admin_login(); |
| 55 | |
| 56 | $crawler = self::request('GET', 'adm/index.php?i=acp_bbcodes&sid=' . $this->sid . '&mode=bbcodes&action=add'); |
| 57 | $form = $crawler->selectButton('Submit')->form([ |
| 58 | 'bbcode_match' => $match, |
| 59 | 'bbcode_tpl' => $tpl, |
| 60 | 'bbcode_font_icon' => $icon, |
| 61 | ]); |
| 62 | $crawler = self::submit($form); |
| 63 | |
| 64 | $text = $crawler->filter('.errorbox')->text(); |
| 65 | $this->assertStringContainsString($error, $text); |
| 66 | } |
| 67 | |
| 68 | public static function get_bbcode_error_tests() |
| 69 | { |
| 70 | return [ |
| 71 | [ |
| 72 | 'XXX', |
| 73 | '', |
| 74 | '', |
| 75 | 'BBCode is constructed in an invalid form' |
| 76 | ], |
| 77 | [ |
| 78 | '[x]{TEXT}[/x]', |
| 79 | '<xsl:invalid', |
| 80 | '', |
| 81 | 'template is invalid' |
| 82 | ], |
| 83 | [ |
| 84 | '[x]{TEXT}[/x]', |
| 85 | '<script>{TEXT}</script>', |
| 86 | '', |
| 87 | 'unsafe' |
| 88 | ], |
| 89 | 'icon name too long' => [ |
| 90 | '[mod2="{TEXT1}"]{TEXT2}[/mod2]', |
| 91 | '<div>{TEXT1}</div><div>{TEXT2}</div>', |
| 92 | str_repeat('a', 65), |
| 93 | 'is too long', |
| 94 | ], |
| 95 | 'icon name invalid' => [ |
| 96 | '[mod2="{TEXT1}"]{TEXT2}[/mod2]', |
| 97 | '<div>{TEXT1}</div><div>{TEXT2}</div>', |
| 98 | 'Not a valid icon name', |
| 99 | 'is invalid', |
| 100 | ], |
| 101 | 'icon name invalid double dash' => [ |
| 102 | '[mod2="{TEXT1}"]{TEXT2}[/mod2]', |
| 103 | '<div>{TEXT1}</div><div>{TEXT2}</div>', |
| 104 | 'us--er', |
| 105 | 'is invalid', |
| 106 | ], |
| 107 | 'icon name invalid trailing dash' => [ |
| 108 | '[mod2="{TEXT1}"]{TEXT2}[/mod2]', |
| 109 | '<div>{TEXT1}</div><div>{TEXT2}</div>', |
| 110 | 'user-', |
| 111 | 'is invalid', |
| 112 | ], |
| 113 | ]; |
| 114 | } |
| 115 | } |