From: Chad Horohoe Date: Wed, 3 Feb 2010 13:32:44 +0000 (+0000) Subject: Port IP tests to PHPUnit format X-Git-Tag: 1.31.0-rc.0~37953 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=d9f9cfc195469a71cfa2f7dc6c461775813665ba;p=lhc%2Fweb%2Fwiklou.git Port IP tests to PHPUnit format --- diff --git a/tests/IPTest.php b/tests/IPTest.php new file mode 100644 index 0000000000..9db77f72c6 --- /dev/null +++ b/tests/IPTest.php @@ -0,0 +1,52 @@ +assertTrue( IP::isValid( $ip ) , "$ip is a valid IPv4 address" ); + } + } + } + + public function testInvalidIPs() { + foreach ( range( 256, 999 ) as $i ) { + $a = sprintf( "%03d", $i ); + $b = sprintf( "%02d", $i ); + $c = sprintf( "%01d", $i ); + foreach ( array_unique( array( $a, $b, $c ) ) as $f ) { + $ip = "$f.$f.$f.$f"; + $this->assertFalse( IP::isValid( $ip ), "$ip is not a valid IPv4 address" ); + } + } + } + + public function testBogusIPs() { + $invalid = array( + 'www.xn--var-xla.net', + '216.17.184.G', + '216.17.184.1.', + '216.17.184', + '216.17.184.', + '256.17.184.1' + ); + foreach ( $invalid as $i ) { + $this->assertFalse( IP::isValid( $i ), "$i is an invalid IPv4 address" ); + } + } + + public function testPrivateIPs() { + $private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' ); + foreach ( $private as $p ) { + $this->assertFalse( IP::isPublic( $p ), "$p is not a public IP address" ); + } + } +}