Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
6.67% |
1 / 15 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_network_ip_normalise_test | |
6.67% |
1 / 15 |
|
50.00% |
1 / 2 |
5.25 | |
0.00% |
0 / 1 |
| data_provider | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |||
| test_ip_normalise | |
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_network_ip_normalise_test extends phpbb_test_case |
| 15 | { |
| 16 | public static function data_provider() |
| 17 | { |
| 18 | return array( |
| 19 | // From: A Recommendation for IPv6 Address Text Representation |
| 20 | // http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07 |
| 21 | |
| 22 | // Section 4: A Recommendation for IPv6 Text Representation |
| 23 | // Section 4.1: Handling Leading Zeros in a 16 Bit Field |
| 24 | array('2001:0db8::0001', '2001:db8::1'), |
| 25 | |
| 26 | // Section 4.2: "::" Usage |
| 27 | // Section 4.2.1: Shorten As Much As Possible |
| 28 | array('2001:db8::0:1', '2001:db8::1'), |
| 29 | |
| 30 | // Section 4.2.2: Handling One 16 Bit 0 Field |
| 31 | array('2001:db8::1:1:1:1:1', '2001:db8:0:1:1:1:1:1'), |
| 32 | |
| 33 | // Section 4.2.3: Choice in Placement of "::" |
| 34 | array('2001:db8:0:0:1:0:0:1', '2001:db8::1:0:0:1'), |
| 35 | |
| 36 | // Section 4.3: Lower Case |
| 37 | array('2001:DB8::1', '2001:db8::1'), |
| 38 | |
| 39 | // Section 5: Text Representation of Special Addresses |
| 40 | // We want to show IPv4-mapped addresses as plain IPv4 addresses, though. |
| 41 | array('::ffff:192.168.0.1', '192.168.0.1'), |
| 42 | array('0000::0000:ffff:c000:0280', '192.0.2.128'), |
| 43 | |
| 44 | // IPv6 addresses with the last 32-bit written in dotted-quad notation |
| 45 | // should be converted to hex-only IPv6 addresses. |
| 46 | array('2001:db8::192.0.2.128', '2001:db8::c000:280'), |
| 47 | |
| 48 | // Any string not passing the IPv4 or IPv6 regular expression |
| 49 | // is supposed to result in false being returned. |
| 50 | // Valid and invalid IP addresses are tested in |
| 51 | // tests/regex/ipv4.php and tests/regex/ipv6.php. |
| 52 | array('', false), |
| 53 | array('192.168.1.256', false), |
| 54 | array('::ffff:192.168.255.256', false), |
| 55 | array('::1111:2222:3333:4444:5555:6666::', false), |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @dataProvider data_provider |
| 61 | */ |
| 62 | public function test_ip_normalise($ip_address, $expected) |
| 63 | { |
| 64 | $this->assertEquals($expected, phpbb_ip_normalise($ip_address)); |
| 65 | } |
| 66 | } |