Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
23.53% |
20 / 85 |
|
57.14% |
4 / 7 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_installer_database_helper_test | |
23.53% |
20 / 85 |
|
57.14% |
4 / 7 |
28.91 | |
0.00% |
0 / 1 |
| setUp | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_remove_comments | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_split_sql | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_validate_table_prefix | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
| comment_string_provider | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
2 | |||
| sql_file_string_provider | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| prefix_test_case_provider | |
0.00% |
0 / 35 |
|
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_installer_database_helper_test extends phpbb_test_case |
| 15 | { |
| 16 | /** |
| 17 | * @var phpbb\install\helper\database |
| 18 | */ |
| 19 | private $database_helper; |
| 20 | |
| 21 | protected function setUp(): void |
| 22 | { |
| 23 | $filesystem = new \phpbb\filesystem\filesystem(); |
| 24 | $phpbb_root_path = ''; |
| 25 | $this->database_helper = new \phpbb\install\helper\database($filesystem, $phpbb_root_path); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @param string $input |
| 30 | * @param string $expected |
| 31 | * |
| 32 | * @dataProvider comment_string_provider |
| 33 | */ |
| 34 | public function test_remove_comments($input, $expected) |
| 35 | { |
| 36 | $this->assertEquals($expected, $this->database_helper->remove_comments($input)); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param array $expected |
| 41 | * @param string $sql |
| 42 | * @param string $delimiter |
| 43 | * |
| 44 | * @dataProvider sql_file_string_provider |
| 45 | */ |
| 46 | public function test_split_sql($expected, $sql, $delimiter) |
| 47 | { |
| 48 | $this->assertEquals($expected, $this->database_helper->split_sql_file($sql, $delimiter)); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param bool|array $expected |
| 53 | * @param string $test_string |
| 54 | * |
| 55 | * @dataProvider prefix_test_case_provider |
| 56 | */ |
| 57 | public function test_validate_table_prefix($expected, $test_string) |
| 58 | { |
| 59 | $db_helper_mock = $this->getMockBuilder('\phpbb\install\helper\database') |
| 60 | ->onlyMethods(array('get_available_dbms')) |
| 61 | ->disableOriginalConstructor() |
| 62 | ->getMock(); |
| 63 | |
| 64 | $db_helper_mock->method('get_available_dbms') |
| 65 | ->willReturn(array('sqlite3' => array( |
| 66 | 'LABEL' => 'SQLite3', |
| 67 | 'SCHEMA' => 'sqlite', |
| 68 | 'MODULE' => 'sqlite3', |
| 69 | 'DELIM' => ';', |
| 70 | 'DRIVER' => 'phpbb\db\driver\sqlite3', |
| 71 | 'AVAILABLE' => true, |
| 72 | '2.0.x' => false, |
| 73 | ))); |
| 74 | |
| 75 | $this->assertEquals($expected, $db_helper_mock->validate_table_prefix('sqlite3', $test_string)); |
| 76 | } |
| 77 | |
| 78 | // Data provider for the remove comments function |
| 79 | public static function comment_string_provider() |
| 80 | { |
| 81 | return array( |
| 82 | array( |
| 83 | 'abc', |
| 84 | 'abc', |
| 85 | ), |
| 86 | array( |
| 87 | 'abc /* asdf */', |
| 88 | "abc \n", |
| 89 | ), |
| 90 | array( |
| 91 | 'abc /* asdf */ f', |
| 92 | "abc \n f", |
| 93 | ), |
| 94 | array( |
| 95 | '# abc', |
| 96 | "\n", |
| 97 | ), |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | // Data provider for the sql file splitter function |
| 102 | public static function sql_file_string_provider() |
| 103 | { |
| 104 | return array( |
| 105 | array( |
| 106 | array( |
| 107 | 'abcd "efgh"' . "\n" . 'qwerty', |
| 108 | 'SELECT * FROM table', |
| 109 | ), |
| 110 | 'abcd "efgh"' . "\n" . |
| 111 | 'qwerty;' . "\n" . |
| 112 | 'SELECT * FROM table', |
| 113 | ';', |
| 114 | ), |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | // Test data for prefix test |
| 119 | public static function prefix_test_case_provider() |
| 120 | { |
| 121 | return array( |
| 122 | array( |
| 123 | true, |
| 124 | 'phpbb_', |
| 125 | ), |
| 126 | array( |
| 127 | true, |
| 128 | 'phpbb', |
| 129 | ), |
| 130 | array( |
| 131 | array( |
| 132 | array('title' => 'INST_ERR_DB_INVALID_PREFIX'), |
| 133 | ), |
| 134 | '1hpbb_', |
| 135 | ), |
| 136 | array( |
| 137 | array( |
| 138 | array('title' => 'INST_ERR_DB_INVALID_PREFIX'), |
| 139 | ), |
| 140 | '?hpbb_', |
| 141 | ), |
| 142 | array( |
| 143 | array( |
| 144 | array('title' => array('INST_ERR_PREFIX_TOO_LONG', 200)), |
| 145 | ), |
| 146 | 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', |
| 147 | ), |
| 148 | array( |
| 149 | array( |
| 150 | array('title' => 'INST_ERR_DB_INVALID_PREFIX'), |
| 151 | array('title' => array('INST_ERR_PREFIX_TOO_LONG', 200)), |
| 152 | ), |
| 153 | '_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', |
| 154 | ), |
| 155 | ); |
| 156 | } |
| 157 | } |