Compare commits

...

3 Commits

3 changed files with 515 additions and 418 deletions

View File

@ -8,7 +8,7 @@ namespace NAE\Validation;
* @author Marcel Naeve <php@naeve.info> * @author Marcel Naeve <php@naeve.info>
* @package NAE\Validation * @package NAE\Validation
*/ */
class ValidateStatic class Validate
{ {
/** /**
* Static method for validating email addresses with multiple secure levels and black- and whitelist. * Static method for validating email addresses with multiple secure levels and black- and whitelist.
@ -135,20 +135,20 @@ class ValidateStatic
"ES" => 24, "SE" => 24, "CH" => 21, "TN" => 24, "TR" => 26, "AE" => 23, "GB" => 22, "VG" => 24 "ES" => 24, "SE" => 24, "CH" => 21, "TN" => 24, "TR" => 26, "AE" => 23, "GB" => 22, "VG" => 24
]; ];
$iban = mb_ereg_replace("/(\s|\-)/", "", $iban); // sanitize for validation (remove spaces) $iban = preg_replace("/(\s|\-)/", "", $iban); // sanitize for validation (remove spaces)
$country = mb_strtoupper(mb_substr($iban, 0, 2)); $country = strtoupper(substr($iban, 0, 2));
// we know the country the IBAN belongs to? // we know the country the IBAN belongs to?
if(isset($country_length[$country])) { if(isset($country_length[$country])) {
// The IBAN matches in length and basic structure? // The IBAN matches in length and basic structure?
$matches = null; $matches = null;
if(mb_ereg_match('/^([A-Za-z]{2})(\d{2})([A-Za-z0-9]{' . ($country_length[$country]-4) . '})$/', $iban, $matches)) { if(preg_match('/^([A-Za-z]{2})(\d{2})([A-Za-z0-9]{' . ($country_length[$country]-4) . '})$/', $iban, $matches)) {
$checkNum = $matches[1]; $checkNum = $matches[1];
$bban = strtoupper($matches[2]); $bban = strtoupper($matches[2]);
// Replace letters with digits (a or A => 11, b or B => 12,..) // Replace letters with digits (a or A => 11, b or B => 12,..)
$checkString = mb_ereg_replace_callback('/[A-Z]/', function ($matches) { $checkString = preg_replace_callback('/[A-Z]/', function ($matches) {
return base_convert($matches[0], 36, 10); return base_convert($matches[0], 36, 10);
}, $bban . $country . '00'); }, $bban . $country . '00');
@ -188,7 +188,7 @@ class ValidateStatic
$swift = trim($swift); // sanitize swift/bic $swift = trim($swift); // sanitize swift/bic
if($iban !== null) { if($iban !== null) {
$iban = mb_ereg_replace("/(\s|\-)/", "", $iban); // sanitize iban $iban = preg_replace("/(\s|\-)/", "", $iban); // sanitize iban
$api_result = file_get_contents("https://api.swiftrefdata.com/v1/ibans/$iban/bic.xml"); $api_result = file_get_contents("https://api.swiftrefdata.com/v1/ibans/$iban/bic.xml");
$api_result_array = json_decode(json_encode((array) simplexml_load_string($api_result)),1); $api_result_array = json_decode(json_encode((array) simplexml_load_string($api_result)),1);
@ -199,7 +199,104 @@ class ValidateStatic
} }
return mb_ereg_match("^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$", $swift); return preg_match("^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$", $swift);
}
/**
* Static method to validate a Date-String.
* @param string $date Date-String
* @param bool $strict make sure there is only a date, no time?
* @return bool string is a valid date?
*/
static function date(string $date, bool $strict=false) : bool {
$d = strtotime($date);
$reverseDate = date('Y-m-d', $d);
if($d === false) {
return false;
}
if($strict && strtotime($reverseDate) != $d) {
return false;
}
return true;
}
/**
* Static method to validate a String containing a date and a time.
* @param string $datetime DateTime-String
* @param bool $strict make sure if there is both a date and time?
* @return bool string is a valid DateTime?
*/
static function datetime(string $datetime, bool $strict=false) : bool {
$d = strtotime($datetime);
$reverseDate = date('Y-m-d', $d);
if($d === false) {
return false;
}
if($strict && strtotime($reverseDate) != $d) {
return false;
}
return true;
}
/**
* Static method to validate a Time-String.
* @param string $time Time-String
* @return bool string is a valid Time?
*/
static function time(string $time) : bool {
$time = trim($time);
if(preg_match("/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/", $time)) {
$parts = explode(":", $time);
if(count($parts) < 2 or count($parts) > 3) { // at least hours and minutes, seconds optional
return false;
}
$h = intval($parts[0]);
$m = intval($parts[1]);
$s = intval($parts[2]??"0");
if($h === false || $m === false || $s === false) {
return false;
}
if($h < 0 || $m < 0 || $s < 0) {
return false;
}
$fullVal = $h*10000+$m*100+$s;
if($fullVal > 240000) { // max -> 24:00:00 == 00:00:00
return false;
}
if($fullVal < 0) { // min -> 00:00:00
return false;
}
if($h > 24) {
return false;
}
if($m > 59) {
return false;
}
if($s > 59) {
return false;
}
return true;
} elseif (preg_match("/^(0?[1-9]|1[0-2]):[0-5][0-9] (AM|PM)$/i", $time)) {
return true;
}
return false;
}
/**
* Static method for validating date or datetime is in a specific range.
* @param string $value date or datetime to be validated
* @param string $min min value
* @param string $max max value
* @return bool is the value between min and max?
*/
static function datetimeRange(string $value, string $min, string $max) : bool {
$v = strtotime($value);
$l = strtotime($min);
$h = strtotime($max);
if($v === false or $l === false or $h === false) {
return false;
}
return self::range($v, $l, $h);
} }
} }

View File

@ -0,0 +1,411 @@
<?php
namespace Tests\AppBundle;
include_once "../vendor/autoload.php";
require_once "../src/class.Validate.php";
use PHPUnit\Framework\TestCase;
use NAE\Validation\Validate;
/**
* User: Marcel Naeve <php@naeve.info>
* Date: 14.05.2016
* Time: 11:25
*/
class ValidateStaticTest extends TestCase
{
/*
* Validate::email(); Tests
*/
public function testEmail_myEmail_level1()
{
$result = Validate::email("confu5ed@serious-pro.de");
$this->assertTrue($result);
}
public function testEmail_myEmail_level2()
{
$result = Validate::email("confu5ed@serious-pro.de", 2);
$this->assertTrue($result);
}
public function testEmail_myEmail_level1_whitelisted()
{
$result = Validate::email("confu5ed@serious-pro.de", 1,["whitelist"=>["confu5ed@serious-pro.de"]]);
$this->assertTrue($result);
}
public function testEmail_myEmail_level1_not_in_whitelist()
{
$result = Validate::email("confu5ed@serious-pro.de", 1,["whitelist"=>["confu5ed@serious-pro.eu"]]);
$this->assertTrue($result);
}
public function testEmail_myEmail_level1_blacklisted()
{
$result = Validate::email("confu5ed@serious-pro.de",1,["blacklist"=>["confu5ed@serious-pro.de"]]);
$this->assertFalse($result);
}
public function testEmail_myEmail_level1_not_in_blacklist()
{
$result = Validate::email("confu5ed@serious-pro.de", 1,["blacklist"=>["confu5ed@serious-pro.eu"]]);
$this->assertTrue($result);
}
public function testEmail_myEmail_level2_whitelisted()
{
$result = Validate::email("confu5ed@serious-pro.de", 2,["whitelist"=>["confu5ed@serious-pro.de"]]);
$this->assertTrue($result);
}
public function testEmail_myEmail_level2_not_in_whitelist()
{
$result = Validate::email("confu5ed@serious-pro.de", 2,["whitelist"=>["confu5ed@serious-pro.eu"]]);
$this->assertTrue($result);
}
public function testEmail_myEmail_level2_blacklisted()
{
$result = Validate::email("confu5ed@serious-pro.de", 2,["blacklist"=>["confu5ed@serious-pro.de"]]);
$this->assertFalse($result);
}
public function testEmail_myEmail_level2_not_in_blacklist()
{
$result = Validate::email("confu5ed@serious-pro.de", 2,["blacklist"=>["confu5ed@serious-pro.eu"]]);
$this->assertTrue($result);
}
public function testEmail_random1_level1()
{
$result = Validate::email("tempus.lorem.fringilla@vitae.co.uk");
$this->assertTrue($result);
}
public function testEmail_random2_level1()
{
$result = Validate::email("Etiam.ligula@et.com");
$this->assertTrue($result);
}
public function testEmail_random3_level1()
{
$result = Validate::email("orci.tincidunt.adipiscing@famesacturpis.edu");
$this->assertTrue($result);
}
public function testEmail_random4_level1()
{
$result = Validate::email("_______@example.com");
$this->assertTrue($result);
}
public function testEmail_random5_level1()
{
$result = Validate::email("nonummy.Fusce.fermentum@ut.org");
$this->assertTrue($result);
}
public function testEmail_random6_level1()
{
$result = Validate::email('"email"@example.com');
$this->assertTrue($result);
}
public function testEmail_random7_level1()
{
$result = Validate::email('much."more\ unusual"@example.com');
$this->assertTrue($result);
}
public function testEmail_random8_level1()
{
$result = Validate::email('very.unusual."@".unusual.com@example.com');
$this->assertTrue($result);
}
public function testEmail_random9_level1()
{
$result = Validate::email('very."(),:;<>[]".VERY."very@\\"very".unusual@strange.example.com');
$this->assertTrue($result);
}
public function testEmail_random10_level2()
{
$result = Validate::email('very."(),:;<>[]".VERY."very@\\"very".unusual@serious-pro.de', 2);
$this->assertTrue($result);
}
public function testEmail_invalid1_level1()
{
$result = Validate::email("me@me@serious-pro.de");
$this->assertFalse($result);
}
public function testEmail_invalid2_level1()
{
$result = Validate::email("me me@serious-pro.de");
$this->assertFalse($result);
}
public function testEmail_invalid3_level1()
{
$result = Validate::email("me@serious pro.de");
$this->assertFalse($result);
}
/*
* Validate::ipv4(); Tests
*/
public function testIPv4_v4_localhost()
{
$this->assertTrue( Validate::ipv4("127.0.0.1") );
}
public function testIPv4_v4_network()
{
$this->assertTrue( Validate::ipv4("192.168.178.1") );
}
public function testIPv4_v4_googledns1()
{
$this->assertTrue( Validate::ipv4("8.8.8.8") );
}
public function testIPv4_v4_googledns2()
{
$this->assertTrue( Validate::ipv4("8.8.4.4") );
}
public function testIPv4_v4_mask()
{
$this->assertTrue( Validate::ipv4("255.255.255.255") );
}
public function testIPv4_v4_zero()
{
$this->assertTrue( Validate::ipv4("0.0.0.0") );
}
public function testIPv4_v4_tomuch()
{
$this->assertFalse( Validate::ipv4("256.255.255.255") );
}
public function testIPv4_domain()
{
$this->assertFalse( Validate::ipv4("serious-pro.de") );
}
public function testIPv4_v6_localhost()
{
$this->assertFalse( Validate::ipv4("::1") );
}
public function testIPv4_v6_googledns1()
{
$this->assertFalse( Validate::ipv4("2001:4860:4860::8888") );
}
public function testIPv4_v6_googledns2()
{
$this->assertFalse( Validate::ipv4("2001:4860:4860::8844") );
}
/*
* Validate::ipv6(); Tests
*/
public function testIPv6_v4_localhost()
{
$this->assertFalse( Validate::ipv6("127.0.0.1") );
}
public function testIPv6_v4_network()
{
$this->assertFalse( Validate::ipv6("192.168.178.1") );
}
public function testIPv6_v4_googledns1()
{
$this->assertFalse( Validate::ipv6("8.8.8.8") );
}
public function testIPv6_v4_googledns2()
{
$this->assertFalse( Validate::ipv6("8.8.4.4") );
}
public function testIPv6_v4_mask()
{
$this->assertFalse( Validate::ipv6("255.255.255.255") );
}
public function testIPv6_v4_zero()
{
$this->assertFalse( Validate::ipv6("0.0.0.0") );
}
public function testIPv6_v4_tomuch()
{
$this->assertFalse( Validate::ipv6("256.255.255.255") );
}
public function testIPv6_domain()
{
$this->assertFalse( Validate::ipv6("serious-pro.de") );
}
public function testIPv6_v6_localhost()
{
$this->assertTrue( Validate::ipv6("::1") );
}
public function testIPv6_v6_googledns1()
{
$this->assertTrue( Validate::ipv6("2001:4860:4860::8888") );
}
public function testIPv6_v6_googledns2()
{
$this->assertTrue( Validate::ipv6("2001:4860:4860::8844") );
}
/*
* Validate::ip(); Tests
*/
public function testIP_v4_localhost()
{
$this->assertTrue( Validate::ip("127.0.0.1") );
}
public function testIP_v4_network()
{
$this->assertTrue( Validate::ip("192.168.178.1") );
}
public function testIP_v4_googledns1()
{
$this->assertTrue( Validate::ip("8.8.8.8") );
}
public function testIP_v4_googledns2()
{
$this->assertTrue( Validate::ip("8.8.4.4") );
}
public function testIP_v4_mask()
{
$this->assertTrue( Validate::ip("255.255.255.255") );
}
public function testIP_v4_zero()
{
$this->assertTrue( Validate::ip("0.0.0.0") );
}
public function testIP_v4_tomuch()
{
$this->assertFalse( Validate::ip("256.255.255.255") );
}
public function testIP_domain()
{
$this->assertFalse( Validate::ip("serious-pro.de") );
}
public function testIP_v6_localhost()
{
$this->assertTrue( Validate::ip("::1") );
}
public function testIP_v6_googledns1()
{
$this->assertTrue( Validate::ip("2001:4860:4860::8888") );
}
public function testIP_v6_googledns2()
{
$this->assertTrue( Validate::ip("2001:4860:4860::8844") );
}
public function testIP_empty()
{
$this->assertFalse( Validate::ip("") );
}
public function testIP_trash1()
{
$this->assertFalse( Validate::ip("%") );
}
public function testIP_trash2()
{
$this->assertFalse( Validate::ip("~") );
}
public function testIP_trash3()
{
$this->assertFalse( Validate::ip("@") );
}
/*
* Validate::mac(); Tests
*/
public function testMac_random_valid11()
{
$this->assertTrue( Validate::mac("ce:bb:ac:22:9e:72") );
}
public function testMac_random_valid12()
{
$this->assertTrue( Validate::mac("ce-bb-ac-22-9e-72") );
}
public function testMac_random_valid13()
{
$this->assertTrue( Validate::mac("cebb.ac22.9e72") );
}
public function testMac_random_valid21()
{
$this->assertTrue( Validate::mac("77:a8:7a:bf:45:6f") );
}
public function testMac_random_valid22()
{
$this->assertTrue( Validate::mac("77-a8-7a-bf-45-6f") );
}
public function testMac_random_valid23()
{
$this->assertTrue( Validate::mac("77a8.7abf.456f") );
}
public function testMac_invalid1()
{
$this->assertFalse( Validate::mac("58-E4-C8-C3-5G-23") );
}
public function testMac_invalid2()
{
$this->assertFalse( Validate::mac("58-E4-C8-C3-5-23") );
}
public function testMac_invalid3()
{
$this->assertFalse( Validate::mac("58-E4-C8-C3-23") );
}
public function testMac_invalid4()
{
$this->assertFalse( Validate::mac("58-E4-C8-23") );
}
public function testMac_empty()
{
$this->assertFalse( Validate::mac("") );
}
public function testMac_trash1()
{
$this->assertFalse( Validate::mac("%") );
}
public function testMac_trash2()
{
$this->assertFalse( Validate::mac("-") );
}
public function testMac_trash3()
{
$this->assertFalse( Validate::mac(".") );
}
public function testMac_trash4()
{
$this->assertFalse( Validate::mac(":") );
}
/*
* Validate::range(); Tests
*/
public function testRange_int1() {
$this->assertTrue( Validate::range(23, 20, 25) );
}
public function testRange_int2() {
$this->assertTrue( Validate::range(0, -1, 3) );
}
public function testRange_int3() {
$this->assertFalse( Validate::range(-50, -1, 3) );
}
public function testRange_float1() {
$this->assertTrue( Validate::range(2.3, 2.0, 2.5) );
}
public function testRange_float2() {
$this->assertTrue( Validate::range(0.0, -0.1, 0.3) );
}
public function testRange_float3() {
$this->assertFalse( Validate::range(-5.0, -0.1, 0.3) );
}
public function testRange_int_in_float1() {
$this->assertTrue( Validate::range(2, 1.9, 2.1) );
}
public function testRange_int_in_float2() {
$this->assertTrue( Validate::range(0, -0.1, 0.3) );
}
public function testRange_int_in_float3() {
$this->assertFalse( Validate::range(5, -0.1, 0.3) );
}
public function testRange_float_in_int1() {
$this->assertTrue( Validate::range(2.1, 2, 3) );
}
public function testRange_float_in_int2() {
$this->assertTrue( Validate::range(0.1, 0, 1) );
}
public function testRange_float_in_int3() {
$this->assertFalse( Validate::range(-5.5, -5, 0) );
}
/*
* Validate::iban(); Tests
*/
/*
* Validate::swift(); Tests
*/
}

View File

@ -1,411 +0,0 @@
<?php
namespace Tests\AppBundle;
include_once "../vendor/autoload.php";
require_once "../src/class.ValidateStatic.php";
use PHPUnit\Framework\TestCase;
use NAE\Validation\ValidateStatic;
/**
* User: Marcel Naeve <php@naeve.info>
* Date: 14.05.2016
* Time: 11:25
*/
class ValidateStaticTest extends TestCase
{
/*
* ValidateStatic::email(); Tests
*/
public function testEmail_myEmail_level1()
{
$result = ValidateStatic::email("confu5ed@serious-pro.de");
$this->assertTrue($result);
}
public function testEmail_myEmail_level2()
{
$result = ValidateStatic::email("confu5ed@serious-pro.de", 2);
$this->assertTrue($result);
}
public function testEmail_myEmail_level1_whitelisted()
{
$result = ValidateStatic::email("confu5ed@serious-pro.de", 1,["whitelist"=>["confu5ed@serious-pro.de"]]);
$this->assertTrue($result);
}
public function testEmail_myEmail_level1_not_in_whitelist()
{
$result = ValidateStatic::email("confu5ed@serious-pro.de", 1,["whitelist"=>["confu5ed@serious-pro.eu"]]);
$this->assertTrue($result);
}
public function testEmail_myEmail_level1_blacklisted()
{
$result = ValidateStatic::email("confu5ed@serious-pro.de",1,["blacklist"=>["confu5ed@serious-pro.de"]]);
$this->assertFalse($result);
}
public function testEmail_myEmail_level1_not_in_blacklist()
{
$result = ValidateStatic::email("confu5ed@serious-pro.de", 1,["blacklist"=>["confu5ed@serious-pro.eu"]]);
$this->assertTrue($result);
}
public function testEmail_myEmail_level2_whitelisted()
{
$result = ValidateStatic::email("confu5ed@serious-pro.de", 2,["whitelist"=>["confu5ed@serious-pro.de"]]);
$this->assertTrue($result);
}
public function testEmail_myEmail_level2_not_in_whitelist()
{
$result = ValidateStatic::email("confu5ed@serious-pro.de", 2,["whitelist"=>["confu5ed@serious-pro.eu"]]);
$this->assertTrue($result);
}
public function testEmail_myEmail_level2_blacklisted()
{
$result = ValidateStatic::email("confu5ed@serious-pro.de", 2,["blacklist"=>["confu5ed@serious-pro.de"]]);
$this->assertFalse($result);
}
public function testEmail_myEmail_level2_not_in_blacklist()
{
$result = ValidateStatic::email("confu5ed@serious-pro.de", 2,["blacklist"=>["confu5ed@serious-pro.eu"]]);
$this->assertTrue($result);
}
public function testEmail_random1_level1()
{
$result = ValidateStatic::email("tempus.lorem.fringilla@vitae.co.uk");
$this->assertTrue($result);
}
public function testEmail_random2_level1()
{
$result = ValidateStatic::email("Etiam.ligula@et.com");
$this->assertTrue($result);
}
public function testEmail_random3_level1()
{
$result = ValidateStatic::email("orci.tincidunt.adipiscing@famesacturpis.edu");
$this->assertTrue($result);
}
public function testEmail_random4_level1()
{
$result = ValidateStatic::email("_______@example.com");
$this->assertTrue($result);
}
public function testEmail_random5_level1()
{
$result = ValidateStatic::email("nonummy.Fusce.fermentum@ut.org");
$this->assertTrue($result);
}
public function testEmail_random6_level1()
{
$result = ValidateStatic::email('"email"@example.com');
$this->assertTrue($result);
}
public function testEmail_random7_level1()
{
$result = ValidateStatic::email('much."more\ unusual"@example.com');
$this->assertTrue($result);
}
public function testEmail_random8_level1()
{
$result = ValidateStatic::email('very.unusual."@".unusual.com@example.com');
$this->assertTrue($result);
}
public function testEmail_random9_level1()
{
$result = ValidateStatic::email('very."(),:;<>[]".VERY."very@\\"very".unusual@strange.example.com');
$this->assertTrue($result);
}
public function testEmail_random10_level2()
{
$result = ValidateStatic::email('very."(),:;<>[]".VERY."very@\\"very".unusual@serious-pro.de', 2);
$this->assertTrue($result);
}
public function testEmail_invalid1_level1()
{
$result = ValidateStatic::email("me@me@serious-pro.de");
$this->assertFalse($result);
}
public function testEmail_invalid2_level1()
{
$result = ValidateStatic::email("me me@serious-pro.de");
$this->assertFalse($result);
}
public function testEmail_invalid3_level1()
{
$result = ValidateStatic::email("me@serious pro.de");
$this->assertFalse($result);
}
/*
* ValidateStatic::ipv4(); Tests
*/
public function testIPv4_v4_localhost()
{
$this->assertTrue( ValidateStatic::ipv4("127.0.0.1") );
}
public function testIPv4_v4_network()
{
$this->assertTrue( ValidateStatic::ipv4("192.168.178.1") );
}
public function testIPv4_v4_googledns1()
{
$this->assertTrue( ValidateStatic::ipv4("8.8.8.8") );
}
public function testIPv4_v4_googledns2()
{
$this->assertTrue( ValidateStatic::ipv4("8.8.4.4") );
}
public function testIPv4_v4_mask()
{
$this->assertTrue( ValidateStatic::ipv4("255.255.255.255") );
}
public function testIPv4_v4_zero()
{
$this->assertTrue( ValidateStatic::ipv4("0.0.0.0") );
}
public function testIPv4_v4_tomuch()
{
$this->assertFalse( ValidateStatic::ipv4("256.255.255.255") );
}
public function testIPv4_domain()
{
$this->assertFalse( ValidateStatic::ipv4("serious-pro.de") );
}
public function testIPv4_v6_localhost()
{
$this->assertFalse( ValidateStatic::ipv4("::1") );
}
public function testIPv4_v6_googledns1()
{
$this->assertFalse( ValidateStatic::ipv4("2001:4860:4860::8888") );
}
public function testIPv4_v6_googledns2()
{
$this->assertFalse( ValidateStatic::ipv4("2001:4860:4860::8844") );
}
/*
* ValidateStatic::ipv6(); Tests
*/
public function testIPv6_v4_localhost()
{
$this->assertFalse( ValidateStatic::ipv6("127.0.0.1") );
}
public function testIPv6_v4_network()
{
$this->assertFalse( ValidateStatic::ipv6("192.168.178.1") );
}
public function testIPv6_v4_googledns1()
{
$this->assertFalse( ValidateStatic::ipv6("8.8.8.8") );
}
public function testIPv6_v4_googledns2()
{
$this->assertFalse( ValidateStatic::ipv6("8.8.4.4") );
}
public function testIPv6_v4_mask()
{
$this->assertFalse( ValidateStatic::ipv6("255.255.255.255") );
}
public function testIPv6_v4_zero()
{
$this->assertFalse( ValidateStatic::ipv6("0.0.0.0") );
}
public function testIPv6_v4_tomuch()
{
$this->assertFalse( ValidateStatic::ipv6("256.255.255.255") );
}
public function testIPv6_domain()
{
$this->assertFalse( ValidateStatic::ipv6("serious-pro.de") );
}
public function testIPv6_v6_localhost()
{
$this->assertTrue( ValidateStatic::ipv6("::1") );
}
public function testIPv6_v6_googledns1()
{
$this->assertTrue( ValidateStatic::ipv6("2001:4860:4860::8888") );
}
public function testIPv6_v6_googledns2()
{
$this->assertTrue( ValidateStatic::ipv6("2001:4860:4860::8844") );
}
/*
* ValidateStatic::ip(); Tests
*/
public function testIP_v4_localhost()
{
$this->assertTrue( ValidateStatic::ip("127.0.0.1") );
}
public function testIP_v4_network()
{
$this->assertTrue( ValidateStatic::ip("192.168.178.1") );
}
public function testIP_v4_googledns1()
{
$this->assertTrue( ValidateStatic::ip("8.8.8.8") );
}
public function testIP_v4_googledns2()
{
$this->assertTrue( ValidateStatic::ip("8.8.4.4") );
}
public function testIP_v4_mask()
{
$this->assertTrue( ValidateStatic::ip("255.255.255.255") );
}
public function testIP_v4_zero()
{
$this->assertTrue( ValidateStatic::ip("0.0.0.0") );
}
public function testIP_v4_tomuch()
{
$this->assertFalse( ValidateStatic::ip("256.255.255.255") );
}
public function testIP_domain()
{
$this->assertFalse( ValidateStatic::ip("serious-pro.de") );
}
public function testIP_v6_localhost()
{
$this->assertTrue( ValidateStatic::ip("::1") );
}
public function testIP_v6_googledns1()
{
$this->assertTrue( ValidateStatic::ip("2001:4860:4860::8888") );
}
public function testIP_v6_googledns2()
{
$this->assertTrue( ValidateStatic::ip("2001:4860:4860::8844") );
}
public function testIP_empty()
{
$this->assertFalse( ValidateStatic::ip("") );
}
public function testIP_trash1()
{
$this->assertFalse( ValidateStatic::ip("%") );
}
public function testIP_trash2()
{
$this->assertFalse( ValidateStatic::ip("~") );
}
public function testIP_trash3()
{
$this->assertFalse( ValidateStatic::ip("@") );
}
/*
* ValidateStatic::mac(); Tests
*/
public function testMac_random_valid11()
{
$this->assertTrue( ValidateStatic::mac("ce:bb:ac:22:9e:72") );
}
public function testMac_random_valid12()
{
$this->assertTrue( ValidateStatic::mac("ce-bb-ac-22-9e-72") );
}
public function testMac_random_valid13()
{
$this->assertTrue( ValidateStatic::mac("cebb.ac22.9e72") );
}
public function testMac_random_valid21()
{
$this->assertTrue( ValidateStatic::mac("77:a8:7a:bf:45:6f") );
}
public function testMac_random_valid22()
{
$this->assertTrue( ValidateStatic::mac("77-a8-7a-bf-45-6f") );
}
public function testMac_random_valid23()
{
$this->assertTrue( ValidateStatic::mac("77a8.7abf.456f") );
}
public function testMac_invalid1()
{
$this->assertFalse( ValidateStatic::mac("58-E4-C8-C3-5G-23") );
}
public function testMac_invalid2()
{
$this->assertFalse( ValidateStatic::mac("58-E4-C8-C3-5-23") );
}
public function testMac_invalid3()
{
$this->assertFalse( ValidateStatic::mac("58-E4-C8-C3-23") );
}
public function testMac_invalid4()
{
$this->assertFalse( ValidateStatic::mac("58-E4-C8-23") );
}
public function testMac_empty()
{
$this->assertFalse( ValidateStatic::mac("") );
}
public function testMac_trash1()
{
$this->assertFalse( ValidateStatic::mac("%") );
}
public function testMac_trash2()
{
$this->assertFalse( ValidateStatic::mac("-") );
}
public function testMac_trash3()
{
$this->assertFalse( ValidateStatic::mac(".") );
}
public function testMac_trash4()
{
$this->assertFalse( ValidateStatic::mac(":") );
}
/*
* ValidateStatic::range(); Tests
*/
public function testRange_int1() {
$this->assertTrue( ValidateStatic::range(23, 20, 25) );
}
public function testRange_int2() {
$this->assertTrue( ValidateStatic::range(0, -1, 3) );
}
public function testRange_int3() {
$this->assertFalse( ValidateStatic::range(-50, -1, 3) );
}
public function testRange_float1() {
$this->assertTrue( ValidateStatic::range(2.3, 2.0, 2.5) );
}
public function testRange_float2() {
$this->assertTrue( ValidateStatic::range(0.0, -0.1, 0.3) );
}
public function testRange_float3() {
$this->assertFalse( ValidateStatic::range(-5.0, -0.1, 0.3) );
}
public function testRange_int_in_float1() {
$this->assertTrue( ValidateStatic::range(2, 1.9, 2.1) );
}
public function testRange_int_in_float2() {
$this->assertTrue( ValidateStatic::range(0, -0.1, 0.3) );
}
public function testRange_int_in_float3() {
$this->assertFalse( ValidateStatic::range(5, -0.1, 0.3) );
}
public function testRange_float_in_int1() {
$this->assertTrue( ValidateStatic::range(2.1, 2, 3) );
}
public function testRange_float_in_int2() {
$this->assertTrue( ValidateStatic::range(0.1, 0, 1) );
}
public function testRange_float_in_int3() {
$this->assertFalse( ValidateStatic::range(-5.5, -5, 0) );
}
/*
* ValidateStatic::iban(); Tests
*/
/*
* ValidateStatic::swift(); Tests
*/
}