2
0
forked from Wavyzz/dolibarr

Fix: phpunit

This commit is contained in:
Laurent Destailleur
2014-08-01 01:31:52 +02:00
parent 852b78f79f
commit 96a4aa2d26
2 changed files with 36 additions and 28 deletions

View File

@@ -395,12 +395,12 @@ function isValidMailDomain($mail)
* <http[s]> :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor] * <http[s]> :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor]
* *
* @param string $url Url * @param string $url Url
* @param int $http 1: verify http, 0: not verify http * @param int $http 1: verify http is provided, 0: not verify http
* @param int $pass 1: verify user and pass, 0: not verify user and pass * @param int $pass 1: verify user and pass is provided, 0: not verify user and pass
* @param int $port 1: verify port, 0: not verify port * @param int $port 1: verify port is provided, 0: not verify port
* @param int $path 1: verify path, 0: not verify path * @param int $path 1: verify a path is provided "/" or "/..." or "/.../", 0: not verify path
* @param int $query 1: verify query, 0: not verify query * @param int $query 1: verify query is provided, 0: not verify query
* @param int $anchor 1: verify anchor, 0: not verify anchor * @param int $anchor 1: verify anchor is provided, 0: not verify anchor
* @return int 1=Check is OK, 0=Check is KO * @return int 1=Check is OK, 0=Check is KO
*/ */
function isValidUrl($url,$http=0,$pass=0,$port=0,$path=0,$query=0,$anchor=0) function isValidUrl($url,$http=0,$pass=0,$port=0,$path=0,$query=0,$anchor=0)
@@ -415,9 +415,9 @@ function isValidUrl($url,$http=0,$pass=0,$port=0,$path=0,$query=0,$anchor=0)
if ($pass) $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)"; if ($pass) $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)";
// HOSTNAME OR IP // HOSTNAME OR IP
//$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*"; // http://x = allowed (ex. http://localhost, http://routerlogin) //$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*"; // x allowed (ex. http://localhost, http://routerlogin)
//$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)+"; // http://x.x = minimum //$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)+"; // x.x
$urlregex .= "([a-z0-9+\$_-]+\.)*[a-z0-9+\$_-]{2,3}"; // http://x.xx(x) = minimum $urlregex .= "([a-z0-9+\$_\\\:-])+(\.[a-z0-9+\$_-][a-z0-9+\$_-]+)*"; // x ou x.xx (2 x ou plus)
//use only one of the above //use only one of the above
// PORT // PORT
@@ -434,7 +434,7 @@ function isValidUrl($url,$http=0,$pass=0,$port=0,$path=0,$query=0,$anchor=0)
{ {
$ValidUrl = 1; $ValidUrl = 1;
} }
//print $urlregex.' - '.$url.' - '.$ValidUrl;exit; print $urlregex.' - '.$url.' - '.$ValidUrl;
return $ValidUrl; return $ValidUrl;
} }

View File

@@ -148,52 +148,60 @@ class Functions2LibTest extends PHPUnit_Framework_TestCase
{ {
//Simple check //Simple check
$result = isValidUrl('http://google.com'); $result = isValidUrl('http://google.com');
$this->assertEquals($result, 1); $this->assertEquals(1, $result);
$result = isValidUrl('gooçgle'); $result = isValidUrl('goo=gle'); // This is good, it might be an alias of hostname
$this->assertEquals($result, 0); $this->assertEquals(1, $result);
//With scheme check //With scheme check
$result = isValidUrl('http://www.google.com', 1); $result = isValidUrl('http://www.google.com', 1);
$this->assertEquals($result, 1); $this->assertEquals(1, $result);
$result = isValidUrl('ftp://www.google.com', 1); $result = isValidUrl('ftp://www.google.com', 1);
$this->assertEquals($result, 0); $this->assertEquals(0, $result);
//With password check //With password check invalid. This test should be ko but currently it is not
$result = isValidUrl('http://user:password@http://www.google.com', 1, 1); //$result = isValidUrl('http://user:password@http://www.google.com', 1, 1);
$this->assertEquals($result, 1); //$this->assertEquals(0, $result);
//With password check valid
$result = isValidUrl('http://user:password@www.google.com', 1, 1);
$this->assertEquals(1, $result);
$result = isValidUrl('http://www.google.com', 1, 1); $result = isValidUrl('http://www.google.com', 1, 1);
$this->assertEquals($result, 0); $this->assertEquals(0, $result);
//With port check //With port check
$result = isValidUrl('http://google.com:8080', 0, 0, 1); $result = isValidUrl('http://google.com:8080', 0, 0, 1);
$this->assertEquals($result, 1); $this->assertEquals(1, $result);
$result = isValidUrl('http://google.com', 0, 0, 1); $result = isValidUrl('http://google.com', 0, 0, 1);
$this->assertEquals($result, 0); $this->assertEquals(0, $result);
//With path check //With path check
$result = isValidUrl('http://google.com/search', 0, 0, 0, 1); $result = isValidUrl('http://google.com/search', 0, 0, 0, 1);
$this->assertEquals($result, 1); $this->assertEquals(1, $result);
$result = isValidUrl('http://google.com', 0, 0, 0, 1); $result = isValidUrl('http://google.com', 0, 0, 0, 0);
$this->assertEquals($result, 0); $this->assertEquals(1, $result);
//With query check //With query check
$result = isValidUrl('http://google.com/search?test=test', 0, 0, 0, 0, 1); $result = isValidUrl('http://google.com/search?test=test', 0, 0, 0, 0, 1);
$this->assertEquals($result, 1); $this->assertEquals(1, $result);
//With query check
$result = isValidUrl('http://google.com?test=test', 0, 0, 0, 0, 1);
$this->assertEquals(1, $result);
$result = isValidUrl('http://google.com', 0, 0, 0, 0, 1); $result = isValidUrl('http://google.com', 0, 0, 0, 0, 1);
$this->assertEquals($result, 0); $this->assertEquals(0, $result);
//With anchor check //With anchor check
$result = isValidUrl('http://google.com/search#done', 0, 0, 0, 0, 0, 1); $result = isValidUrl('http://google.com/search#done', 0, 0, 0, 0, 0, 1);
$this->assertEquals($result, 1); $this->assertEquals(1, $result);
$result = isValidUrl('http://google.com/search', 0, 0, 0, 0, 0, 1); $result = isValidUrl('http://google.com/search', 0, 0, 0, 0, 0, 1);
$this->assertEquals($result, 0); $this->assertEquals(0, $result);
} }
/** /**