3 * Tests for IP validity functions. Ported from /t/inc/IP.t by avar.
6 class IPTest
extends PHPUnit_Framework_TestCase
{
8 public function testValidIPs() {
9 foreach ( range( 0, 255 ) as $i ) {
10 $a = sprintf( "%03d", $i );
11 $b = sprintf( "%02d", $i );
12 $c = sprintf( "%01d", $i );
13 foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
15 $this->assertTrue( IP
::isValid( $ip ) , "$ip is a valid IPv4 address" );
20 public function testInvalidIPs() {
21 foreach ( range( 256, 999 ) as $i ) {
22 $a = sprintf( "%03d", $i );
23 $b = sprintf( "%02d", $i );
24 $c = sprintf( "%01d", $i );
25 foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
27 $this->assertFalse( IP
::isValid( $ip ), "$ip is not a valid IPv4 address" );
32 public function testBogusIPs() {
34 'www.xn--var-xla.net',
41 foreach ( $invalid as $i ) {
42 $this->assertFalse( IP
::isValid( $i ), "$i is an invalid IPv4 address" );
46 public function testPrivateIPs() {
47 $private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
48 foreach ( $private as $p ) {
49 $this->assertFalse( IP
::isPublic( $p ), "$p is not a public IP address" );