Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
41.03% |
32 / 78 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_textreparser_test_row_based_plugin | |
41.03% |
32 / 78 |
|
83.33% |
5 / 6 |
21.13 | |
0.00% |
0 / 1 |
| get_reparser | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| get_rows | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| test_get_max_id | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_dry_run | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_reparse | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| get_reparse_tests | |
0.00% |
0 / 46 |
|
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 | require_once __DIR__ . '/../../test_framework/phpbb_database_test_case.php'; |
| 15 | |
| 16 | abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_test_case |
| 17 | { |
| 18 | /** @var \phpbb\db\driver\driver_interface */ |
| 19 | protected $db; |
| 20 | |
| 21 | abstract protected function get_reparser(); |
| 22 | |
| 23 | protected function get_rows(array $ids) |
| 24 | { |
| 25 | $reparser = $this->get_reparser(); |
| 26 | $columns = $reparser->get_columns(); |
| 27 | |
| 28 | $reflection_reparser = new ReflectionClass(get_class($reparser)); |
| 29 | $table_property = $reflection_reparser->getProperty('table'); |
| 30 | |
| 31 | $sql = 'SELECT ' . $columns['id'] . ' AS id, ' . $columns['text'] . ' AS text |
| 32 | FROM ' . $table_property->getValue($reparser) . ' |
| 33 | WHERE ' . $this->db->sql_in_set($columns['id'], $ids) . ' |
| 34 | ORDER BY id'; |
| 35 | $result = $this->db->sql_query($sql); |
| 36 | $rows = $this->db->sql_fetchrowset($result); |
| 37 | $this->db->sql_freeresult($result); |
| 38 | |
| 39 | return $rows; |
| 40 | } |
| 41 | |
| 42 | protected function setUp(): void |
| 43 | { |
| 44 | global $config; |
| 45 | if (!isset($config)) |
| 46 | { |
| 47 | $config = new \phpbb\config\config(array()); |
| 48 | } |
| 49 | $this->get_test_case_helpers()->set_s9e_services(); |
| 50 | $this->db = $this->new_dbal(); |
| 51 | parent::setUp(); |
| 52 | } |
| 53 | |
| 54 | public function test_get_max_id() |
| 55 | { |
| 56 | $reparser = $this->get_reparser(); |
| 57 | $this->assertEquals(1000, $reparser->get_max_id()); |
| 58 | } |
| 59 | |
| 60 | public function test_dry_run() |
| 61 | { |
| 62 | $old_rows = $this->get_rows(array(1)); |
| 63 | $reparser = $this->get_reparser(); |
| 64 | $reparser->disable_save(); |
| 65 | $reparser->reparse_range(1, 1); |
| 66 | $new_rows = $this->get_rows(array(1)); |
| 67 | $this->assertEquals($old_rows, $new_rows); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @dataProvider get_reparse_tests |
| 72 | */ |
| 73 | public function test_reparse($min_id, $max_id, $expected) |
| 74 | { |
| 75 | $reparser = $this->get_reparser(); |
| 76 | $reparser->reparse_range($min_id, $max_id); |
| 77 | |
| 78 | $ids = array(); |
| 79 | foreach ($expected as $row) |
| 80 | { |
| 81 | $ids[] = $row['id']; |
| 82 | } |
| 83 | |
| 84 | $this->assertEquals($expected, $this->get_rows($ids)); |
| 85 | } |
| 86 | |
| 87 | public static function get_reparse_tests() |
| 88 | { |
| 89 | return array( |
| 90 | array( |
| 91 | 2, |
| 92 | 5, |
| 93 | array( |
| 94 | array( |
| 95 | 'id' => '1', |
| 96 | 'text' => 'This row should be [b]ignored[/b]', |
| 97 | ), |
| 98 | array( |
| 99 | 'id' => '2', |
| 100 | 'text' => '<t>[b]Not bold[/b] :) http://example.org</t>', |
| 101 | ), |
| 102 | array( |
| 103 | 'id' => '3', |
| 104 | 'text' => '<r><B><s>[b]</s>Bold<e>[/b]</e></B> :) http://example.org</r>', |
| 105 | ), |
| 106 | array( |
| 107 | 'id' => '4', |
| 108 | 'text' => '<r>[b]Not bold[/b] <E>:)</E> http://example.org</r>', |
| 109 | ), |
| 110 | array( |
| 111 | 'id' => '5', |
| 112 | 'text' => '<r>[b]Not bold[/b] :) <URL url="http://example.org">http://example.org</URL></r>', |
| 113 | ), |
| 114 | array( |
| 115 | 'id' => '1000', |
| 116 | 'text' => 'This row should be [b]ignored[/b]', |
| 117 | ), |
| 118 | ) |
| 119 | ), |
| 120 | array( |
| 121 | 8, |
| 122 | 9, |
| 123 | array( |
| 124 | array( |
| 125 | 'id' => '8', |
| 126 | 'text' => '<r><IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG></r>', |
| 127 | ), |
| 128 | array( |
| 129 | 'id' => '9', |
| 130 | 'text' => '<t>[img]http://example.org/img.png[/img]</t>', |
| 131 | ), |
| 132 | ) |
| 133 | ), |
| 134 | ); |
| 135 | } |
| 136 | } |