Index: trunk/phase3/maintenance/tests/phpunit/includes/IPTest.php |
— | — | @@ -6,8 +6,9 @@ |
7 | 7 | class IPTest extends PHPUnit_Framework_TestCase { |
8 | 8 | // not sure it should be tested with boolean false. hashar 20100924 |
9 | 9 | public function testisIPAddress() { |
10 | | - $this->assertFalse( IP::isIPAddress( false ) ); |
11 | | - $this->assertFalse( IP::isIPAddress( "" ) ); |
| 10 | + $this->assertFalse( IP::isIPAddress( false ), 'Boolean false is not an IP' ); |
| 11 | + $this->assertFalse( IP::isIPAddress( true ), 'Boolean true is not an IP' ); |
| 12 | + $this->assertFalse( IP::isIPAddress( "" ), 'Empty string is not an IP' ); |
12 | 13 | $this->assertFalse( IP::isIPAddress( 'abc' ) ); |
13 | 14 | $this->assertFalse( IP::isIPAddress( ':' ) ); |
14 | 15 | $this->assertFalse( IP::isIPAddress( '2001:0DB8::A:1::1'), 'IPv6 with a double :: occurence' ); |
— | — | @@ -19,7 +20,8 @@ |
20 | 21 | |
21 | 22 | $this->assertTrue( IP::isIPAddress( 'fc:100::' ) ); |
22 | 23 | $this->assertTrue( IP::isIPAddress( 'fc:100:a:d:1:e:ac::' ) ); |
23 | | - $this->assertTrue( IP::isIPAddress( '::' ), 'IPv6 zero address' ); |
| 24 | + $this->assertTrue( IP::isIPAddress( '::' ), 'RFC 4291 IPv6 Unspecified Address' ); |
| 25 | + $this->assertTrue( IP::isIPAddress( '::1' ), 'RFC 4291 IPv6 Loopback Address' ); |
24 | 26 | $this->assertTrue( IP::isIPAddress( '::fc' ) ); |
25 | 27 | $this->assertTrue( IP::isIPAddress( '::fc:100:a:d:1:e:ac' ) ); |
26 | 28 | $this->assertTrue( IP::isIPAddress( 'fc::100' ) ); |
— | — | @@ -41,8 +43,8 @@ |
42 | 44 | $this->assertTrue( IP::isIPv6( 'fc:100:a:d:1::' ) ); |
43 | 45 | $this->assertTrue( IP::isIPv6( 'fc:100:a:d:1:e::' ) ); |
44 | 46 | $this->assertTrue( IP::isIPv6( 'fc:100:a:d:1:e:ac::' ) ); |
45 | | - $this->assertFalse( IP::isIPv6( 'fc:100:a:d:1:e:ac:0::' ), 'IPv6 ending it "::" with 8 words' ); |
46 | | - $this->assertFalse( IP::isIPv6( 'fc:100:a:d:1:e:ac:0:1::' ), 'IPv6 with 9 words' ); |
| 47 | + $this->assertFalse( IP::isIPv6( 'fc:100:a:d:1:e:ac:0::' ), 'IPv6 with 8 words ending with "::"' ); |
| 48 | + $this->assertFalse( IP::isIPv6( 'fc:100:a:d:1:e:ac:0:1::' ), 'IPv6 with 9 words ending with "::"' ); |
47 | 49 | |
48 | 50 | $this->assertFalse( IP::isIPv6( ':::' ) ); |
49 | 51 | $this->assertFalse( IP::isIPv6( '::0:' ), 'IPv6 ending in a lone ":"' ); |
— | — | @@ -55,11 +57,11 @@ |
56 | 58 | $this->assertTrue( IP::isIPv6( '::fc:100:a:d:1' ) ); |
57 | 59 | $this->assertTrue( IP::isIPv6( '::fc:100:a:d:1:e' ) ); |
58 | 60 | $this->assertTrue( IP::isIPv6( '::fc:100:a:d:1:e:ac' ) ); |
59 | | - $this->assertFalse( IP::isIPv6( '::fc:100:a:d:1:e:ac:0' ), 'IPv6 with "::" and 8 octets' ); |
60 | | - $this->assertFalse( IP::isIPv6( '::fc:100:a:d:1:e:ac:0:1' ), 'IPv6 with 9 octets' ); |
| 61 | + $this->assertFalse( IP::isIPv6( '::fc:100:a:d:1:e:ac:0' ), 'IPv6 with "::" and 8 words' ); |
| 62 | + $this->assertFalse( IP::isIPv6( '::fc:100:a:d:1:e:ac:0:1' ), 'IPv6 with 9 words' ); |
61 | 63 | |
62 | 64 | $this->assertFalse( IP::isIPv6( ':fc::100' ), 'IPv6 starting with lone ":"' ); |
63 | | - $this->assertFalse( IP::isIPv6( 'fc::100:' ), 'IPv6 ending in lone ":"' ); |
| 65 | + $this->assertFalse( IP::isIPv6( 'fc::100:' ), 'IPv6 ending with lone ":"' ); |
64 | 66 | $this->assertFalse( IP::isIPv6( 'fc:::100' ), 'IPv6 with ":::" in the middle' ); |
65 | 67 | $this->assertTrue( IP::isIPv6( 'fc::100' ) ); |
66 | 68 | $this->assertTrue( IP::isIPv6( 'fc::100:a' ) ); |
— | — | @@ -67,8 +69,8 @@ |
68 | 70 | $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1' ) ); |
69 | 71 | $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e' ) ); |
70 | 72 | $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e:ac' ) ); |
71 | | - $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0' ), 'IPv6 with "::" and 8 octets' ); |
72 | | - $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0:1' ), 'IPv6 with 9 octets' ); |
| 73 | + $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0' ), 'IPv6 with "::" and 8 words' ); |
| 74 | + $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0:1' ), 'IPv6 with 9 words' ); |
73 | 75 | |
74 | 76 | $this->assertTrue( IP::isIPv6( 'fc:100:a:d:1:e:ac:0' ) ); |
75 | 77 | } |
— | — | @@ -83,7 +85,7 @@ |
84 | 86 | $this->assertTrue( IP::isValid( $ip ) , "$ip is a valid IPv4 address" ); |
85 | 87 | } |
86 | 88 | } |
87 | | - foreach ( range( 0, 65535 ) as $i ) { |
| 89 | + foreach ( range( 0x0, 0xFFFF ) as $i ) { |
88 | 90 | $a = sprintf( "%04x", $i ); |
89 | 91 | $b = sprintf( "%03x", $i ); |
90 | 92 | $c = sprintf( "%02x", $i ); |
— | — | @@ -105,9 +107,9 @@ |
106 | 108 | } |
107 | 109 | } |
108 | 110 | foreach ( range( 'g', 'z' ) as $i ) { |
109 | | - $a = sprintf( "%04", $i ); |
110 | | - $b = sprintf( "%03", $i ); |
111 | | - $c = sprintf( "%02", $i ); |
| 111 | + $a = sprintf( "%04s", $i ); |
| 112 | + $b = sprintf( "%03s", $i ); |
| 113 | + $c = sprintf( "%02s", $i ); |
112 | 114 | foreach ( array_unique( array( $a, $b, $c ) ) as $f ) { |
113 | 115 | $ip = "$f:$f:$f:$f:$f:$f:$f:$f"; |
114 | 116 | $this->assertFalse( IP::isValid( $ip ) , "$ip is not a valid IPv6 address" ); |