From 6ea6eb10345e00368c31503f9287f136f215db1c Mon Sep 17 00:00:00 2001 From: henoheno Date: Sat, 27 Dec 2008 23:50:00 +0900 Subject: [PATCH] is_ip() --- spam/SpamTest.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/spam/SpamTest.php b/spam/SpamTest.php index 882480b..b2b273f 100644 --- a/spam/SpamTest.php +++ b/spam/SpamTest.php @@ -1,5 +1,5 @@ assertEquals('192\.168\.', generate_host_regex('192.168.')); } + function testFunc_is_ip() + { + // 1st argument: Null + foreach($this->setup_string_null() as $key => $value){ + $this->assertEquals(FALSE, is_ip($value), $key); + } + + // IPv4 + foreach(array( + '192.168.1.1', + ) as $value){ + $this->assertEquals(4, is_ip($value), $key, '[' . $value . ']'); + } + + // IPv6 + foreach(array( + '::', // 0:0:0:0:0:0:0:0 + '::192.168.1.1', // IPv4 within IPv6 network + ) as $value){ + $this->assertEquals(6, is_ip($value), $key, '[' . $value . ']'); + } + + // Invalid + foreach(array( + '', + '.', + ) as $value){ + $this->assertEquals(FALSE, is_ip($value), $key, '[' . $value . ']'); + } + + } + function testFunc_get_blocklist() { if (! defined('SPAM_INI_FILE') || ! file_exists(SPAM_INI_FILE)) { -- 2.11.0