Index: trunk/phase3/tests/phpunit/includes/IPTest.php |
— | — | @@ -4,7 +4,10 @@ |
5 | 5 | */ |
6 | 6 | |
7 | 7 | class IPTest extends MediaWikiTestCase { |
8 | | - // not sure it should be tested with boolean false. hashar 20100924 |
| 8 | + /** |
| 9 | + * not sure it should be tested with boolean false. hashar 20100924 |
| 10 | + * @covers IP:isIPAddress() |
| 11 | + */ |
9 | 12 | public function testisIPAddress() { |
10 | 13 | $this->assertFalse( IP::isIPAddress( false ), 'Boolean false is not an IP' ); |
11 | 14 | $this->assertFalse( IP::isIPAddress( true ), 'Boolean true is not an IP' ); |
— | — | @@ -32,6 +35,9 @@ |
33 | 36 | } |
34 | 37 | } |
35 | 38 | |
| 39 | + /** |
| 40 | + * @covers IP::isIPv6() |
| 41 | + */ |
36 | 42 | public function testisIPv6() { |
37 | 43 | $this->assertFalse( IP::isIPv6( ':fc:100::' ), 'IPv6 starting with lone ":"' ); |
38 | 44 | $this->assertFalse( IP::isIPv6( 'fc:100:::' ), 'IPv6 ending with a ":::"' ); |
— | — | @@ -75,6 +81,9 @@ |
76 | 82 | $this->assertTrue( IP::isIPv6( 'fc:100:a:d:1:e:ac:0' ) ); |
77 | 83 | } |
78 | 84 | |
| 85 | + /** |
| 86 | + * @covers IP::isIPv4() |
| 87 | + */ |
79 | 88 | public function testisIPv4() { |
80 | 89 | $this->assertFalse( IP::isIPv4( false ), 'Boolean false is not an IP' ); |
81 | 90 | $this->assertFalse( IP::isIPv4( true ), 'Boolean true is not an IP' ); |
— | — | @@ -90,7 +99,9 @@ |
91 | 100 | $this->assertTrue( IP::isIPv4( '74.24.52.13/20', 'IPv4 range' ) ); |
92 | 101 | } |
93 | 102 | |
94 | | - // tests isValid() |
| 103 | + /** |
| 104 | + * @covers IP::isValid() |
| 105 | + */ |
95 | 106 | public function testValidIPs() { |
96 | 107 | foreach ( range( 0, 255 ) as $i ) { |
97 | 108 | $a = sprintf( "%03d", $i ); |
— | — | @@ -112,7 +123,9 @@ |
113 | 124 | } |
114 | 125 | } |
115 | 126 | |
116 | | - // tests isValid() |
| 127 | + /** |
| 128 | + * @covers IP::isValid() |
| 129 | + */ |
117 | 130 | public function testInvalidIPs() { |
118 | 131 | // Out of range... |
119 | 132 | foreach ( range( 256, 999 ) as $i ) { |
— | — | @@ -160,7 +173,9 @@ |
161 | 174 | } |
162 | 175 | } |
163 | 176 | |
164 | | - // tests isValidBlock() |
| 177 | + /** |
| 178 | + * @covers IP::isValidBlock() |
| 179 | + */ |
165 | 180 | public function testValidBlocks() { |
166 | 181 | $valid = array( |
167 | 182 | '116.17.184.5/32', |
— | — | @@ -181,7 +196,9 @@ |
182 | 197 | } |
183 | 198 | } |
184 | 199 | |
185 | | - // tests isValidBlock() |
| 200 | + /** |
| 201 | + * @covers IP::isValidBlock() |
| 202 | + */ |
186 | 203 | public function testInvalidBlocks() { |
187 | 204 | $invalid = array( |
188 | 205 | '116.17.184.5/33', |
— | — | @@ -202,7 +219,10 @@ |
203 | 220 | } |
204 | 221 | } |
205 | 222 | |
206 | | - // test wrapper around ip2long which might return -1 or false depending on PHP version |
| 223 | + /** |
| 224 | + * test wrapper around ip2long which might return -1 or false depending on PHP version |
| 225 | + * @covers IP::toUnsigned() |
| 226 | + */ |
207 | 227 | public function testip2longWrapper() { |
208 | 228 | // fixme : add more tests ? |
209 | 229 | $this->assertEquals( pow(2,32) - 1, IP::toUnsigned( '255.255.255.255' )); |
— | — | @@ -210,7 +230,9 @@ |
211 | 231 | $this->assertFalse( IP::toUnSigned( $i ) ); |
212 | 232 | } |
213 | 233 | |
214 | | - // tests isPublic() |
| 234 | + /** |
| 235 | + * @covers IP::isPublic() |
| 236 | + */ |
215 | 237 | public function testPrivateIPs() { |
216 | 238 | $private = array( 'fc::3', 'fc::ff', '::1', '10.0.0.1', '172.16.0.1', '192.168.0.1' ); |
217 | 239 | foreach ( $private as $p ) { |
— | — | @@ -230,6 +252,9 @@ |
231 | 253 | $this->assertEquals( $expected, long2ip( $parse[0] ), "network shifting $CIDR" ); |
232 | 254 | } |
233 | 255 | |
| 256 | + /** |
| 257 | + * @covers IP::hexToQuad() |
| 258 | + */ |
234 | 259 | public function testHexToQuad() { |
235 | 260 | $this->assertEquals( '0.0.0.1' , IP::hexToQuad( '00000001' ) ); |
236 | 261 | $this->assertEquals( '255.0.0.0' , IP::hexToQuad( 'FF000000' ) ); |
— | — | @@ -242,6 +267,9 @@ |
243 | 268 | $this->assertEquals( '0.0.255.0' , IP::hexToQuad( 'FF00' ) ); |
244 | 269 | } |
245 | 270 | |
| 271 | + /** |
| 272 | + * @covers IP::hexToOctet() |
| 273 | + */ |
246 | 274 | public function testHexToOctet() { |
247 | 275 | $this->assertEquals( '0:0:0:0:0:0:0:1', |
248 | 276 | IP::hexToOctet( '00000000000000000000000000000001' ) ); |
— | — | @@ -265,6 +293,7 @@ |
266 | 294 | /* |
267 | 295 | * IP::parseCIDR() returns an array containing a signed IP address |
268 | 296 | * representing the network mask and the bit mask. |
| 297 | + * @covers IP::parseCIDR() |
269 | 298 | */ |
270 | 299 | function testCIDRParsing() { |
271 | 300 | $this->assertFalseCIDR( '192.0.2.0' , "missing mask" ); |