Index: trunk/phase3/tests/phpunit/includes/IPTest.php |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | class IPTest extends MediaWikiTestCase { |
8 | 8 | /** |
9 | 9 | * not sure it should be tested with boolean false. hashar 20100924 |
| 10 | + * @covers IP::isIPAddress |
10 | 11 | */ |
11 | 12 | public function testisIPAddress() { |
12 | 13 | $this->assertFalse( IP::isIPAddress( false ), 'Boolean false is not an IP' ); |
— | — | @@ -34,6 +35,9 @@ |
35 | 36 | } |
36 | 37 | } |
37 | 38 | |
| 39 | + /** |
| 40 | + * @covers IP::isIPv6 |
| 41 | + */ |
38 | 42 | public function testisIPv6() { |
39 | 43 | $this->assertFalse( IP::isIPv6( ':fc:100::' ), 'IPv6 starting with lone ":"' ); |
40 | 44 | $this->assertFalse( IP::isIPv6( 'fc:100:::' ), 'IPv6 ending with a ":::"' ); |
— | — | @@ -86,6 +90,9 @@ |
87 | 91 | $this->assertTrue( IP::isIPv6( 'fc:100:a:d:1:e:ac:0' ) ); |
88 | 92 | } |
89 | 93 | |
| 94 | + /** |
| 95 | + * @covers IP::isIPv4 |
| 96 | + */ |
90 | 97 | public function testisIPv4() { |
91 | 98 | $this->assertFalse( IP::isIPv4( false ), 'Boolean false is not an IP' ); |
92 | 99 | $this->assertFalse( IP::isIPv4( true ), 'Boolean true is not an IP' ); |
— | — | @@ -101,6 +108,9 @@ |
102 | 109 | $this->assertTrue( IP::isIPv4( '74.24.52.13/20', 'IPv4 range' ) ); |
103 | 110 | } |
104 | 111 | |
| 112 | + /** |
| 113 | + * @covers IP::isValid |
| 114 | + */ |
105 | 115 | public function testValidIPs() { |
106 | 116 | foreach ( range( 0, 255 ) as $i ) { |
107 | 117 | $a = sprintf( "%03d", $i ); |
— | — | @@ -142,6 +152,9 @@ |
143 | 153 | $this->assertFalse( IP::isValid( 'fc:100:a:d:1:e:ac:0:1::' ), 'IPv6 with 9 words ending with "::"' ); |
144 | 154 | } |
145 | 155 | |
| 156 | + /** |
| 157 | + * @covers IP::isValid |
| 158 | + */ |
146 | 159 | public function testInvalidIPs() { |
147 | 160 | // Out of range... |
148 | 161 | foreach ( range( 256, 999 ) as $i ) { |
— | — | @@ -189,6 +202,9 @@ |
190 | 203 | } |
191 | 204 | } |
192 | 205 | |
| 206 | + /** |
| 207 | + * @covers IP::isValidBlock |
| 208 | + */ |
193 | 209 | public function testValidBlocks() { |
194 | 210 | $valid = array( |
195 | 211 | '116.17.184.5/32', |
— | — | @@ -209,6 +225,9 @@ |
210 | 226 | } |
211 | 227 | } |
212 | 228 | |
| 229 | + /** |
| 230 | + * @covers IP::isValidBlock |
| 231 | + */ |
213 | 232 | public function testInvalidBlocks() { |
214 | 233 | $invalid = array( |
215 | 234 | '116.17.184.5/33', |
— | — | @@ -240,6 +259,7 @@ |
241 | 260 | |
242 | 261 | /** |
243 | 262 | * test wrapper around ip2long which might return -1 or false depending on PHP version |
| 263 | + * @covers IP::toUnsigned |
244 | 264 | */ |
245 | 265 | public function testip2longWrapper() { |
246 | 266 | // fixme : add more tests ? |
— | — | @@ -248,6 +268,9 @@ |
249 | 269 | $this->assertFalse( IP::toUnSigned( $i ) ); |
250 | 270 | } |
251 | 271 | |
| 272 | + /** |
| 273 | + * @covers IP::isPublic |
| 274 | + */ |
252 | 275 | public function testPrivateIPs() { |
253 | 276 | $private = array( 'fc::3', 'fc::ff', '::1', '10.0.0.1', '172.16.0.1', '192.168.0.1' ); |
254 | 277 | foreach ( $private as $p ) { |
— | — | @@ -267,6 +290,9 @@ |
268 | 291 | $this->assertEquals( $expected, long2ip( $parse[0] ), "network shifting $CIDR" ); |
269 | 292 | } |
270 | 293 | |
| 294 | + /** |
| 295 | + * @covers IP::hexToQuad |
| 296 | + */ |
271 | 297 | public function testHexToQuad() { |
272 | 298 | $this->assertEquals( '0.0.0.1' , IP::hexToQuad( '00000001' ) ); |
273 | 299 | $this->assertEquals( '255.0.0.0' , IP::hexToQuad( 'FF000000' ) ); |
— | — | @@ -279,6 +305,9 @@ |
280 | 306 | $this->assertEquals( '0.0.255.0' , IP::hexToQuad( 'FF00' ) ); |
281 | 307 | } |
282 | 308 | |
| 309 | + /** |
| 310 | + * @covers IP::hexToOctet |
| 311 | + */ |
283 | 312 | public function testHexToOctet() { |
284 | 313 | $this->assertEquals( '0:0:0:0:0:0:0:1', |
285 | 314 | IP::hexToOctet( '00000000000000000000000000000001' ) ); |
— | — | @@ -302,6 +331,7 @@ |
303 | 332 | /* |
304 | 333 | * IP::parseCIDR() returns an array containing a signed IP address |
305 | 334 | * representing the network mask and the bit mask. |
| 335 | + * @covers IP::parseCIDR |
306 | 336 | */ |
307 | 337 | function testCIDRParsing() { |
308 | 338 | $this->assertFalseCIDR( '192.0.2.0' , "missing mask" ); |