Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
34 / 34 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_functions_validate_num_test | |
100.00% |
34 / 34 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| setUp | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_validate_num | |
100.00% |
32 / 32 |
|
100.00% |
1 / 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__ . '/../../phpBB/includes/functions_user.php'; |
| 15 | require_once __DIR__ . '/validate_data_helper.php'; |
| 16 | |
| 17 | class phpbb_functions_validate_num_test extends phpbb_test_case |
| 18 | { |
| 19 | protected $helper; |
| 20 | |
| 21 | protected function setUp(): void |
| 22 | { |
| 23 | parent::setUp(); |
| 24 | |
| 25 | $this->helper = new phpbb_functions_validate_data_helper($this); |
| 26 | } |
| 27 | |
| 28 | public function test_validate_num() |
| 29 | { |
| 30 | $this->helper->assert_valid_data(array( |
| 31 | 'empty' => array( |
| 32 | array(), |
| 33 | null, // '' < 0 is true since PHP 8.0, hence use null instead of '' (empty string) |
| 34 | array('num'), |
| 35 | ), |
| 36 | 'zero' => array( |
| 37 | array(), |
| 38 | '0', |
| 39 | array('num'), |
| 40 | ), |
| 41 | 'five_minmax_correct' => array( |
| 42 | array(), |
| 43 | '5', |
| 44 | array('num', false, 2, 6), |
| 45 | ), |
| 46 | 'five_minmax_short' => array( |
| 47 | array('TOO_SMALL'), |
| 48 | '5', |
| 49 | array('num', false, 7, 10), |
| 50 | ), |
| 51 | 'five_minmax_long' => array( |
| 52 | array('TOO_LARGE'), |
| 53 | '5', |
| 54 | array('num', false, 2, 3), |
| 55 | ), |
| 56 | 'string' => array( |
| 57 | version_compare(PHP_VERSION, '7.5', '<=') ? [] : ['TOO_LARGE'], // See https://wiki.php.net/rfc/string_to_number_comparison |
| 58 | 'foobar', |
| 59 | array('num'), |
| 60 | ), |
| 61 | )); |
| 62 | } |
| 63 | } |