Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
12.50% |
3 / 24 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_regex_ipv4_test | |
12.50% |
3 / 24 |
|
60.00% |
3 / 5 |
21.75 | |
0.00% |
0 / 1 |
| setUp | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| positive_match_data | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| negative_match_data | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
2 | |||
| test_positive_match | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_negative_match | |
100.00% |
1 / 1 |
|
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 | class phpbb_regex_ipv4_test extends phpbb_test_case |
| 15 | { |
| 16 | protected $regex; |
| 17 | |
| 18 | protected function setUp(): void |
| 19 | { |
| 20 | $this->regex = get_preg_expression('ipv4'); |
| 21 | } |
| 22 | |
| 23 | public static function positive_match_data() |
| 24 | { |
| 25 | return array( |
| 26 | array('0.0.0.0'), |
| 27 | array('127.0.0.1'), |
| 28 | array('192.168.0.1'), |
| 29 | array('255.255.255.255'), |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | public static function negative_match_data() |
| 34 | { |
| 35 | return array( |
| 36 | // IPv6 addresses |
| 37 | array('2001:0db8:85a3:0000:0000:8a2e:0370:1337'), |
| 38 | array('2001:db8:85a3:c:d:8a2e:370:1337'), |
| 39 | array('2001:db8:85a3::8a2e:370:1337'), |
| 40 | array('2001:db8:0:1::192.168.0.2'), |
| 41 | array('0:0:0:0:0:0:0:1'), |
| 42 | array('0:0::0:0:1'), |
| 43 | array('::1'), |
| 44 | |
| 45 | // Out of scope |
| 46 | array('255.255.255.256'), |
| 47 | |
| 48 | // Other tests |
| 49 | array('a.b.c.d'), |
| 50 | array('11.22.33.'), |
| 51 | array('11.22.33'), |
| 52 | array('11.22'), |
| 53 | array('11'), |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @dataProvider positive_match_data |
| 59 | */ |
| 60 | public function test_positive_match($address) |
| 61 | { |
| 62 | $this->assertEquals(1, preg_match($this->regex, $address)); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @dataProvider negative_match_data |
| 67 | */ |
| 68 | public function test_negative_match($address) |
| 69 | { |
| 70 | $this->assertEquals(0, preg_match($this->regex, $address)); |
| 71 | } |
| 72 | } |
| 73 |