summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-12-15 05:22:05 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-12-15 05:22:05 +0000
commit8e38d459e5946d51c16bce3355ec5393143c8824 (patch)
treefc9e1dbc6f9751e9d61bbda927b7246ef87f339f
parenteb807e70e030a19e4b72984a955d0412a9f9b463 (diff)
downloadbrdo-8e38d459e5946d51c16bce3355ec5393143c8824.tar.gz
brdo-8e38d459e5946d51c16bce3355ec5393143c8824.tar.bz2
#653940 follow-up by Damien Tournoud: Clean-up of error handling from first stab at test reporting fixes.
-rw-r--r--includes/common.inc14
-rw-r--r--includes/stream_wrappers.inc7
-rw-r--r--modules/field/modules/field_sql_storage/field_sql_storage.module6
-rw-r--r--modules/filter/filter.module8
-rw-r--r--modules/simpletest/drupal_web_test_case.php12
-rw-r--r--modules/simpletest/tests/common.test8
-rw-r--r--modules/simpletest/tests/file.test4
7 files changed, 24 insertions, 35 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 66464963a..8ff820452 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -807,16 +807,20 @@ function drupal_http_request($url, array $options = array()) {
$result = new stdClass();
- // Validate the passed URL. FILTER_VALIDATE_URL uses parse_url() internally,
- // but unlike parse_url() itself, it will not throw a run-time notice for
- // bogus URLs.
- if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
+ // Parse the URL and make sure we can handle the schema.
+ $uri = @parse_url($url);
+
+ if ($uri == FALSE) {
$result->error = 'unable to parse URL';
$result->code = -1001;
return $result;
}
- $uri = parse_url($url);
+ if (!isset($uri['scheme'])) {
+ $result->error = 'missing schema';
+ $result->code = -1002;
+ return $result;
+ }
timer_start(__FUNCTION__);
diff --git a/includes/stream_wrappers.inc b/includes/stream_wrappers.inc
index bfbe528b4..c58c58231 100644
--- a/includes/stream_wrappers.inc
+++ b/includes/stream_wrappers.inc
@@ -500,12 +500,7 @@ abstract class DrupalLocalStreamWrapper implements DrupalStreamWrapperInterface
public function url_stat($uri, $flags) {
$this->uri = $uri;
if ($flags & STREAM_URL_STAT_QUIET) {
- if (file_exists($this->getLocalPath())) {
- return stat($this->getLocalPath());
- }
- else {
- return FALSE;
- }
+ return @stat($this->getLocalPath());
}
else {
return stat($this->getLocalPath());
diff --git a/modules/field/modules/field_sql_storage/field_sql_storage.module b/modules/field/modules/field_sql_storage/field_sql_storage.module
index a7bbd6637..0231e94ce 100644
--- a/modules/field/modules/field_sql_storage/field_sql_storage.module
+++ b/modules/field/modules/field_sql_storage/field_sql_storage.module
@@ -489,11 +489,7 @@ function field_sql_storage_field_storage_query($field_id, $conditions, $options)
foreach ($conditions as $condition) {
// A condition is either a (column, value, operator) triple, or a
// (column, value) pair with implied operator.
- list($column, $value) = $condition;
- $operator = NULL;
- if (isset($condition[2])) {
- $operator = $condition[2];
- }
+ @list($column, $value, $operator) = $condition;
// Translate operator and value if needed.
switch ($operator) {
case 'STARTS_WITH':
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index b2ae5dc0a..235cb187a 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -793,12 +793,10 @@ function _filter_tips($format_id, $long = FALSE) {
* A DOMDocument that represents the loaded (X)HTML snippet.
*/
function filter_dom_load($text) {
- // Suppress all libxml warnings during loading of HTML.
- libxml_use_internal_errors(TRUE);
- $document = new DOMDocument();
- $document->loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $text . '</body></html>');
+ // Ignore warnings during HTML soup loading.
+ $dom_document = @DOMDocument::loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $text . '</body></html>');
- return $document;
+ return $dom_document;
}
/**
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 3c4a2396c..1946e5dc3 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1387,16 +1387,14 @@ class DrupalWebTestCase extends DrupalTestCase {
*/
protected function parse() {
if (!$this->elements) {
- // Suppress all libxml warnings during loading of HTML.
- // @todo Remove this when core produces XHTML valid output.
- libxml_use_internal_errors(TRUE);
- $document = new DOMDocument();
- $result = $document->loadHTML($this->content);
- if ($result) {
+ // DOM can load HTML soup. But, HTML soup can throw warnings, suppress
+ // them.
+ @$htmlDom = DOMDocument::loadHTML($this->content);
+ if ($htmlDom) {
$this->pass(t('Valid HTML found on "@path"', array('@path' => $this->getUrl())), t('Browser'));
// It's much easier to work with simplexml than DOM, luckily enough
// we can just simply import our DOM tree.
- $this->elements = simplexml_import_dom($document);
+ $this->elements = simplexml_import_dom($htmlDom);
}
}
if (!$this->elements) {
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index b2223d579..35a2a7f87 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -801,8 +801,8 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase {
// Parse URL schema.
$missing_scheme = drupal_http_request('example.com/path');
- $this->assertEqual($missing_scheme->code, -1001, t('Returned with "-1001" error code.'));
- $this->assertEqual($missing_scheme->error, 'unable to parse URL', t('Returned with "unable to parse URL" error message.'));
+ $this->assertEqual($missing_scheme->code, -1002, t('Returned with "-1002" error code.'));
+ $this->assertEqual($missing_scheme->error, 'missing schema', t('Returned with "missing schema" error message.'));
$unable_to_parse = drupal_http_request('http:///path');
$this->assertEqual($unable_to_parse->code, -1001, t('Returned with "-1001" error code.'));
@@ -860,8 +860,8 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase {
$this->assertFalse(isset($redirect_301->redirect_code), t('drupal_http_request does not follow 301 redirect if max_redirects = 0.'));
$redirect_invalid = drupal_http_request(url('system-test/redirect-noscheme', array('absolute' => TRUE)), array('max_redirects' => 1));
- $this->assertEqual($redirect_invalid->code, -1001, t('301 redirect to invalid URL returned with error code !error.', array('!error' => $redirect_invalid->error)));
- $this->assertEqual($redirect_invalid->error, 'unable to parse URL', t('301 redirect to invalid URL returned with error message "!error".', array('!error' => $redirect_invalid->error)));
+ $this->assertEqual($redirect_invalid->code, -1002, t('301 redirect to invalid URL returned with error code !error.', array('!error' => $redirect_invalid->error)));
+ $this->assertEqual($redirect_invalid->error, 'missing schema', t('301 redirect to invalid URL returned with error message "!error".', array('!error' => $redirect_invalid->error)));
$redirect_invalid = drupal_http_request(url('system-test/redirect-noparse', array('absolute' => TRUE)), array('max_redirects' => 1));
$this->assertEqual($redirect_invalid->code, -1001, t('301 redirect to invalid URL returned with error message code "!error".', array('!error' => $redirect_invalid->error)));
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test
index 08263668c..051d57889 100644
--- a/modules/simpletest/tests/file.test
+++ b/modules/simpletest/tests/file.test
@@ -728,9 +728,7 @@ class FileDirectoryTest extends FileTestCase {
// Remove .htaccess file to then test that it gets re-created.
$directory = file_directory_path();
- if (file_exists($directory . '/.htaccess')) {
- unlink($directory . '/.htaccess');
- }
+ @unlink($directory . '/.htaccess');
$this->assertFalse(is_file($directory . '/.htaccess'), t('Successfully removed the .htaccess file in the files directory.'), 'File');
file_ensure_htaccess();
$this->assertTrue(is_file($directory . '/.htaccess'), t('Successfully re-created the .htaccess file in the files directory.'), 'File');