Permalink
Browse files

Implemented Request #17963: Allow test suite to run without DNS resol…

…ver [patch by remicollet, adjustments by dufuz]

git-svn-id: http://svn.php.net/repository/pear/packages/Validate/trunk@309242 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 29e2106 commit 210e17cf4c4fbb13f5b0ee7e1b4e115a756bfc33 @helgi helgi committed Mar 15, 2011
Showing with 98 additions and 14 deletions.
  1. +1 −6 tests/email.phpt
  2. +49 −0 tests/email_domaincheck.phpt
  3. +0 −8 tests/uri.phpt
  4. +48 −0 tests/uri_domaincheck.phpt
View
@@ -1,5 +1,5 @@
--TEST--
-email.phpt: Unit tests for
+email.phpt: Unit tests for email validation
--FILE--
<?php
// $Id$
@@ -10,9 +10,6 @@ require 'Validate.php';
echo "Test Validate_Email\n";
$emails = array(
- // Try dns lookup
- array('pear-general@lists.php.net', true), // OK
- array('example@fluffffffrefrffrfrfrfrfrfr.is', false), // OK
// with out the dns lookup
'example@fluffffffrefrffrfrfrfrfrfr.is', // OK
@@ -116,8 +113,6 @@ foreach ($emails as $email) {
?>
--EXPECT--
Test Validate_Email
-pear-general@lists.php.net: with domain check : YES
-example@fluffffffrefrffrfrfrfrfrfr.is: without domain check : YES
example@fluffffffrefrffrfrfrfrfrfr.is: YES
davidc@php.net: YES
example (though bad)@example.com: YES
@@ -0,0 +1,49 @@
+--TEST--
+domaincheck.phpt: Unit tests for email validation with dns checks
+--SKIPIF--
+<?php
+if (!function_exists('checkdnsrr') || !checkdnsrr('php.net', 'A')) {
+ echo 'skip Missing checkdnsrr()';
+}
+?>
+--FILE--
+<?php
+// $Id: email.phpt 276490 2009-02-26 09:32:16Z amir $
+// Validate test script
+$noYes = array('NO', 'YES');
+require 'Validate.php';
+
+echo "Test Validate_Email\n";
+
+$emails = array(
+ // Try dns lookup
+ array('pear-general@lists.php.net', true), // OK
+ array('example@fluffffffrefrffrfrfrfrfrfr.is', true) // OK
+ );
+
+list($version) = explode(".", phpversion(), 2);
+foreach ($emails as $email) {
+ if (is_array($email)) {
+ echo "{$email[0]}:";
+ if (!is_array($email[1])) {
+ echo " with". ($email[1] ? '' : 'out') . ' domain check :';
+ }
+ echo ' ' . $noYes[Validate::email($email[0], $email[1])]."\n";
+ } else {
+ echo "{$email}: ";
+ if ((int)$version > 4) {
+ try {
+ echo $noYes[Validate::email($email)]."\n";
+ } catch (Exception $e) {
+ echo $e->getMessage()."\n";
+ }
+ } else {
+ echo $noYes[Validate::email($email)]."\n";
+ }
+ }
+}
+?>
+--EXPECT--
+Test Validate_Email
+pear-general@lists.php.net: with domain check : YES
+example@fluffffffrefrffrfrfrfrfrfr.is: with domain check : NO
View
@@ -29,14 +29,9 @@ $uris = array(
'//-.com', // NOK
'//example.-com', // NOK
'//-example.com-', // NOK
- // Try dns lookup
- array('//php.net', 'domain_check' => true), // OK
- array('//example.gor', 'domain_check' => true), // NOK
// Try schemes lookup
array('//example.org', 'allowed_schemes' => array('ftp', 'http')), // NOK
array('http://example.org', 'allowed_schemes' => array('ftp', 'http')), // OK
- array('http://php.net', 'allowed_schemes' => array('ftp', 'http'),
- 'domain_check' => true), // OK
array(
'//example.org/tkik-wkik_rss.php?ver=2http://www.hyperlecture.info//http://www.hyperlecture.info/accueil',
'strict' => ''), // OK
@@ -83,11 +78,8 @@ http://user:password@127.0.0.1:8080/pub/ietf/uri;rfc2396?test=ok&end=next#Relate
//-.com: NO
//example.-com: NO
//-example.com-: NO
-//php.net: schemes() with domain check : YES
-//example.gor: schemes() with domain check : NO
//example.org: schemes(ftp,http) without domain check : NO
http://example.org: schemes(ftp,http) without domain check : YES
-http://php.net: schemes(ftp,http) with domain check : YES
//example.org/tkik-wkik_rss.php?ver=2http://www.hyperlecture.info//http://www.hyperlecture.info/accueil: schemes() without domain check : (strict : ) YES
http://domain.tld//: YES
http://domain.tld/.: YES
View
@@ -0,0 +1,48 @@
+--TEST--
+domaincheck.phpt: Unit tests for uri validation with dns check
+--SKIPIF--
+<?php
+if (!function_exists('checkdnsrr') || !checkdnsrr('php.net', 'A')) {
+ echo 'skip Missing checkdnsrr()';
+}
+?>
+--FILE--
+<?php
+// $Id: $
+// Validate test script
+$noYes = array('NO', 'YES');
+require 'Validate.php';
+
+echo "Test Validate::uri()\n";
+
+$uris = array(
+ // Try dns lookup
+ array('//php.net', 'domain_check' => true), // OK
+ array('//example.gor', 'domain_check' => true), // NOK
+ // Try schemes lookup
+ array('http://php.net', 'allowed_schemes' => array('ftp', 'http'),
+ 'domain_check' => true) // OK
+ );
+
+foreach ($uris as $uri) {
+ if (is_array($uri)) {
+ $options = $uri;
+ unset($options[0]);
+ echo "{$uri[0]}: schemes(" .
+ (isset($options['allowed_schemes']) ?
+ implode(',', $options['allowed_schemes']) : '') .") with".
+ (isset($options['domain_check']) && $options['domain_check'] ?
+ '' : 'out') . ' domain check : '.
+ (isset($options['strict']) ? "(strict : {$options['strict']}) " : '') .
+ $noYes[Validate::uri($uri[0], $options )]."\n";
+ } else {
+ echo "{$uri}: ".
+ $noYes[Validate::uri($uri)]."\n";
+ }
+}
+?>
+--EXPECT--
+Test Validate::uri()
+//php.net: schemes() with domain check : YES
+//example.gor: schemes() with domain check : NO
+http://php.net: schemes(ftp,http) with domain check : YES

0 comments on commit 210e17c

Please sign in to comment.