r83303 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83302‎ | r83303 | r83304 >
Date:17:30, 5 March 2011
Author:hashar
Status:ok
Tags:
Comment:
tests for IP class, mostly incompletes

* IP::sanitizeIP()
* IP::canonicalize()
* IP::isInRange()
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/IPTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/IPTest.php
@@ -230,6 +230,15 @@
231231 }
232232
233233 /**
 234+ * Improve IP::sanitizeIP() code coverage
 235+ * @todo Most probably incomplete
 236+ */
 237+ public function testSanitizeIP() {
 238+ $this->assertNull( IP::sanitizeIP('') );
 239+ $this->assertNull( IP::sanitizeIP(' ') );
 240+ }
 241+
 242+ /**
234243 * test wrapper around ip2long which might return -1 or false depending on PHP version
235244 */
236245 public function testip2longWrapper() {
@@ -323,4 +332,68 @@
324333 $this->assertNet( '10.128.0.0' , '10.135.0.0/9' );
325334 $this->assertNet( '134.0.0.0' , '134.0.5.1/8' );
326335 }
 336+
 337+
 338+ /**
 339+ * @covers IP::canonicalize
 340+ */
 341+ public function testIPCanonicalizeOnValidIp() {
 342+ $this->assertEquals( '192.0.2.152', IP::canonicalize( '192.0.2.152' ),
 343+ 'Canonicalization of a valid IP returns it unchanged' );
 344+ }
 345+
 346+ /**
 347+ * @covers IP::canonicalize
 348+ */
 349+ public function testIPCanonicalizeMappedAddress() {
 350+ $this->assertEquals(
 351+ '192.0.2.152',
 352+ IP::canonicalize( '::ffff:192.0.2.152' )
 353+ );
 354+ $this->assertEquals(
 355+ '192.0.2.152',
 356+ IP::canonicalize( '::192.0.2.152' )
 357+ );
 358+ }
 359+
 360+ /**
 361+ * Issues there are most probably from IP::toHex() or IP::parseRange()
 362+ * @covers IP::isInRange
 363+ * @dataProvider provideIPsAndRanges
 364+ */
 365+ public function testIPIsInRange( $expected, $addr, $range, $message = '' ) {
 366+ $this->assertEquals(
 367+ $expected,
 368+ IP::isInRange( $addr, $range ),
 369+ $message
 370+ );
 371+ }
 372+
 373+ /** Provider for testIPIsInRange() */
 374+ function provideIPsAndRanges() {
 375+ # Format: (expected boolean, address, range, optional message)
 376+ return array(
 377+ # IPv4
 378+ array( true , '192.0.2.0' , '192.0.2.0/24', 'Network address' ),
 379+ array( true , '192.0.2.77' , '192.0.2.0/24', 'Simple address' ),
 380+ array( true , '192.0.2.255' , '192.0.2.0/24', 'Broadcast address' ),
 381+
 382+ array( false, '0.0.0.0' , '192.0.2.0/24' ),
 383+ array( false, '255.255.255' , '192.0.2.0/24' ),
 384+
 385+ # IPv6
 386+ array( false, '::1' , '2001:DB8::/32' ),
 387+ array( false, '::' , '2001:DB8::/32' ),
 388+ array( false, 'FE80::1', '2001:DB8::/32' ),
 389+
 390+ array( true , '2001:DB8::' , '2001:DB8::/32' ),
 391+ array( true , '2001:0DB8::' , '2001:DB8::/32' ),
 392+ array( true , '2001:DB8::1' , '2001:DB8::/32' ),
 393+ array( true , '2001:0DB8::1', '2001:DB8::/32' ),
 394+ array( true , '2001:0DB8:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF',
 395+ '2001:DB8::/32' ),
 396+
 397+ array( false, '2001:0DB8:F::', '2001:DB8::/96' ),
 398+ );
 399+ }
327400 }

Status & tagging log