Les dejo el codgio de las dos clases.
Código PHP:
<?php
include ('IWT_ValidateIP.php');
class IWT_ValidateLocalhostIPAddress extends IWT_ValidateIP
{
public function testValidateLocalHostIP()
{
$ip = $this->validate->localhostIpAddress('192.15.178.10');
$this->assertFalse($ip->isValid, "Not Localhost IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'IPADDRESS_NOT_LOCALHOST', "Not complete IP [$ip->value] must be invalid");
$ip = $this->validate->localhostIpAddress('127.0.0.1');
$this->assertTrue($ip->isValid, "Localhost IP [$ip->value] must be valid");
$ip = $this->validate->localhostIpAddress('::1');
$this->assertTrue($ip->isValid, "Localhost IP [$ip->value] must be valid");
$ip = $this->validate->localhostIpAddress('0:0:0:0:0:0:0:1');
$this->assertTrue($ip->isValid, "Localhost IP [$ip->value] must be valid");
}
}
?>
Código PHP:
<?php
class IWT_ValidateIP extends PHPUnit_Framework_TestCase
{
protected $validate;
protected function setUp()
{
iwt_init(iwt_test_config());
$find = iwt_finder();
$this->validate = $find->any('IWT_Validate');
}
public function testValidateEmptyIP()
{
$ip = $this->validate->localhostIpAddress('');
$this->assertFalse($ip->isValid, "Empty IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'INVALID_IPADDRESS', "Empty IP [$ipt->value] must be invalid");
}
public function testValidateInvalidCharactersIP()
{
$ip = $this->validate->localhostIpAddress('19a.168.152.134');
$this->assertFalse($ip->isValid, "Invalid Character IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'INVALID_IPADDRESS', "Invalid Character IP [$ip->value] must be invalid");
$ip = $this->validate->localhostIpAddress('192.1»8.152.134');
$this->assertFalse($ip->isValid, "Invalid Character IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'INVALID_IPADDRESS', "Invalid Character IP [$ip->value] must be invalid");
$ip = $this->validate->localhostIpAddress('192.138.15♫.134');
$this->assertFalse($ip->isValid, "Invalid Character IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'INVALID_IPADDRESS', "Invalid Character IP [$ip->value] must be invalid");
$ip = $this->validate->localhostIpAddress('192.128.152.13¾');
$this->assertFalse($ip->isValid, "Invalid Character IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'INVALID_IPADDRESS', "Invalid Character IP [$ip->value] must be invalid");
}
public function testValidateTwoPointsIP()
{
$ip = $this->validate->localhostIpAddress('192.15..131.120');
$this->assertFalse($ip->isValid, "Two Points IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'INVALID_IPADDRESS', "Two Points IP [$ip->value] must be invalid");
}
public function testValidateOutOfRangeIP()
{
$ip = $this->validate->localhostIpAddress('192.15.256.120');
$this->assertFalse($ip->isValid, "Out of range IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'INVALID_IPADDRESS', "Out of range IP [$ip->value] must be invalid");
$ip = $this->validate->localhostIpAddress('-1.255.255.300');
$this->assertFalse($ip->isValid, "Out of range IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'INVALID_IPADDRESS', "Out of range IP [$ip->value] must be invalid");
}
public function testValidateIPNotComplete()
{
$ip = $this->validate->localhostIpAddress('192.15.178');
$this->assertFalse($ip->isValid, "Not complete IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'INVALID_IPADDRESS', "Not complete IP [$ip->value] must be invalid");
$ip = $this->validate->localhostIpAddress('192.15.178.1.145');
$this->assertFalse($ip->isValid, "Not complete IP [$ip->value] must be invalid");
$this->assertEquals($ip->errorCode, 'INVALID_IPADDRESS', "Not complete IP [$ip->value] must be invalid");
}
}
?>