Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
79 / 79 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_textreparser_poll_option_test | |
100.00% |
79 / 79 |
|
100.00% |
7 / 7 |
8 | |
100.00% |
1 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_reparser | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_rows | |
100.00% |
7 / 7 |
|
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 | |||
| testReparse | |
100.00% |
56 / 56 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | class phpbb_textreparser_poll_option_test extends phpbb_database_test_case |
| 17 | { |
| 18 | protected $db; |
| 19 | |
| 20 | public function getDataSet() |
| 21 | { |
| 22 | return $this->createXMLDataSet(__DIR__ . '/fixtures/poll_options.xml'); |
| 23 | } |
| 24 | |
| 25 | protected function get_reparser() |
| 26 | { |
| 27 | return new \phpbb\textreparser\plugins\poll_option($this->db, POLL_OPTIONS_TABLE); |
| 28 | } |
| 29 | |
| 30 | protected function get_rows() |
| 31 | { |
| 32 | $sql = 'SELECT topic_id, poll_option_id, poll_option_text |
| 33 | FROM ' . POLL_OPTIONS_TABLE . ' |
| 34 | ORDER BY topic_id, poll_option_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(123, $reparser->get_max_id()); |
| 58 | } |
| 59 | |
| 60 | public function test_dry_run() |
| 61 | { |
| 62 | $old_rows = $this->get_rows(); |
| 63 | $reparser = $this->get_reparser(); |
| 64 | $reparser->disable_save(); |
| 65 | $reparser->reparse_range(1, 1); |
| 66 | $new_rows = $this->get_rows(); |
| 67 | $this->assertEquals($old_rows, $new_rows); |
| 68 | } |
| 69 | |
| 70 | public function testReparse() |
| 71 | { |
| 72 | $reparser = $this->get_reparser(); |
| 73 | $reparser->enable_save(); |
| 74 | $reparser->reparse_range(2, 13); |
| 75 | $expected = array( |
| 76 | array( |
| 77 | 'topic_id' => 1, |
| 78 | 'poll_option_id' => 1, |
| 79 | 'poll_option_text' => 'This row should be [b]ignored[/b]', |
| 80 | ), |
| 81 | array( |
| 82 | 'topic_id' => 1, |
| 83 | 'poll_option_id' => 2, |
| 84 | 'poll_option_text' => 'This row should be [b:abcd1234]ignored[/b:abcd1234]', |
| 85 | ), |
| 86 | array( |
| 87 | 'topic_id' => 2, |
| 88 | 'poll_option_id' => 1, |
| 89 | 'poll_option_text' => '<r><B><s>[b]</s>Bold<e>[/b]</e></B></r>', |
| 90 | ), |
| 91 | array( |
| 92 | 'topic_id' => 2, |
| 93 | 'poll_option_id' => 2, |
| 94 | 'poll_option_text' => '<r><E>:)</E></r>', |
| 95 | ), |
| 96 | array( |
| 97 | 'topic_id' => 2, |
| 98 | 'poll_option_id' => 3, |
| 99 | 'poll_option_text' => '<r><URL url="http://example.org">http://example.org</URL></r>', |
| 100 | ), |
| 101 | array( |
| 102 | 'topic_id' => 11, |
| 103 | 'poll_option_id' => 1, |
| 104 | 'poll_option_text' => '<r><B><s>[b]</s>Bold<e>[/b]</e></B> :) http://example.org</r>', |
| 105 | ), |
| 106 | array( |
| 107 | 'topic_id' => 12, |
| 108 | 'poll_option_id' => 1, |
| 109 | 'poll_option_text' => '<r>[b]Not bold[/b] <E>:)</E> http://example.org</r>', |
| 110 | ), |
| 111 | array( |
| 112 | 'topic_id' => 13, |
| 113 | 'poll_option_id' => 1, |
| 114 | 'poll_option_text' => '<r>[b]Not bold[/b] :) <URL url="http://example.org">http://example.org</URL></r>', |
| 115 | ), |
| 116 | array( |
| 117 | 'topic_id' => 123, |
| 118 | 'poll_option_id' => 1, |
| 119 | 'poll_option_text' => 'This row should be [b]ignored[/b]', |
| 120 | ), |
| 121 | array( |
| 122 | 'topic_id' => 123, |
| 123 | 'poll_option_id' => 2, |
| 124 | 'poll_option_text' => 'This row should be [b:abcd1234]ignored[/b:abcd1234]', |
| 125 | ), |
| 126 | ); |
| 127 | $this->assertEquals($expected, $this->get_rows()); |
| 128 | } |
| 129 | } |