From 37d4d303b33d241ab54cc60bf22e6547dc4c54fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Thu, 17 Jul 2014 21:19:03 +0200 Subject: [PATCH] Updated is_ip comment and added a test for is_ip function --- htdocs/core/lib/functions2.lib.php | 6 ++---- test/phpunit/Functions2LibTest.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 3f13e6dccaa..294dbafa82e 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1364,10 +1364,8 @@ function getListOfModels($db,$type,$maxfilenamelength=0) /** * This function evaluates a string that should be a valid IPv4 * - * @param string $ip IP Address - * @return It returns 0 if $ip is not a valid IPv4 - * It returns 1 if $ip is a valid IPv4 and is a public IP - * It returns 2 if $ip is a valid IPv4 and is a private lan IP + * @param string $ip IP Address + * @return int 0 if not valid, 1 if valid and public IP, 2 if valid and private range IP */ function is_ip($ip) { diff --git a/test/phpunit/Functions2LibTest.php b/test/phpunit/Functions2LibTest.php index 8e4bfe7550f..b59b9f3795c 100755 --- a/test/phpunit/Functions2LibTest.php +++ b/test/phpunit/Functions2LibTest.php @@ -154,4 +154,23 @@ class Functions2LibTest extends PHPUnit_Framework_TestCase $this->assertEquals(0,$result); } + /** + * is_ip + * + * @return void + */ + public function testIsIp() { + + //Test not valid IP + $result = is_ip('192.168.1.267'); + $this->assertEquals(0, $result); + + //Test private range IP + $result = is_ip('192.168.1.1'); + $this->assertEquals(2, $result); + + //Test public range IP + $result = is_ip('91.121.33.228'); + $this->assertEquals(1, $result); + } }