summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-07-02 20:05:11 +0000
committerDries Buytaert <dries@buytaert.net>2008-07-02 20:05:11 +0000
commitfe06b4ccd8faa23ebc2b67147fc9064b785a675b (patch)
tree18322723050ef42cadd08614886c350116ef5731
parentca144061cb72903c7f9e78286f964c41acc51bfe (diff)
downloadbrdo-fe06b4ccd8faa23ebc2b67147fc9064b785a675b.tar.gz
brdo-fe06b4ccd8faa23ebc2b67147fc9064b785a675b.tar.bz2
- Patch #276581 by catch: wrote missing tests for contact module and simplified contact module thanks to that. Also removed some whitespace.
-rw-r--r--includes/bootstrap.inc2
-rw-r--r--includes/tests/bootstrap.test14
-rw-r--r--modules/contact/contact.admin.inc16
-rw-r--r--modules/contact/contact.test5
-rw-r--r--modules/simpletest/drupal_web_test_case.php2
5 files changed, 18 insertions, 21 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 89e515369..fc7743989 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -1160,7 +1160,7 @@ function language_default($property = NULL) {
/**
* If Drupal is behind a reverse proxy, we use the X-Forwarded-For header
- * instead of $_SERVER['REMOTE_ADDR'], which would be the IP address of
+ * instead of $_SERVER['REMOTE_ADDR'], which would be the IP address of
* the proxy server, and not the client's. If Drupal is run in a cluster
* we use the X-Cluster-Client-Ip header instead.
*
diff --git a/includes/tests/bootstrap.test b/includes/tests/bootstrap.test
index beb94edf0..4b2cf3089 100644
--- a/includes/tests/bootstrap.test
+++ b/includes/tests/bootstrap.test
@@ -24,14 +24,14 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
$this->forwarded_ip = '127.0.0.3';
$this->cluster_ip = '127.0.0.4';
$this->untrusted_ip = '0.0.0.0';
-
+
$_SERVER['REMOTE_ADDR'] = $this->remote_ip;
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
unset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']);
-
+
parent::setUp();
}
-
+
/**
* Implementation of tearDown().
*/
@@ -49,14 +49,14 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
ip_address(true) == $this->remote_ip,
t('Got remote IP address')
);
-
+
// Proxy forwarding on but no proxy addresses defined.
variable_set('reverse_proxy', 1);
$this->assertTrue(
ip_address(true) == $this->remote_ip,
t('Proxy forwarding without trusted proxies got remote IP address')
);
-
+
// Proxy forwarding on and proxy address not trusted.
variable_set('reverse_proxy_addresses', array($this->proxy_ip));
$_SERVER['REMOTE_ADDR'] = $this->untrusted_ip;
@@ -71,8 +71,8 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
$this->assertTrue(
ip_address(true) == $this->forwarded_ip,
t('Proxy forwarding with trusted proxy got forwarded IP address')
- );
-
+ );
+
// Cluster environment.
$_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] = $this->cluster_ip;
$this->assertTrue(
diff --git a/modules/contact/contact.admin.inc b/modules/contact/contact.admin.inc
index 16178078c..df9733594 100644
--- a/modules/contact/contact.admin.inc
+++ b/modules/contact/contact.admin.inc
@@ -79,18 +79,10 @@ function contact_admin_edit($form_state = array(), $op, $contact = NULL) {
* Validate the contact category edit page form submission.
*/
function contact_admin_edit_validate($form, &$form_state) {
- if (empty($form_state['values']['category'])) {
- form_set_error('category', t('You must enter a category.'));
- }
- if (empty($form_state['values']['recipients'])) {
- form_set_error('recipients', t('You must enter one or more recipients.'));
- }
- else {
- $recipients = explode(',', $form_state['values']['recipients']);
- foreach ($recipients as $recipient) {
- if (!valid_email_address(trim($recipient))) {
- form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
- }
+ $recipients = explode(',', $form_state['values']['recipients']);
+ foreach ($recipients as $recipient) {
+ if (!valid_email_address(trim($recipient))) {
+ form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
}
}
}
diff --git a/modules/contact/contact.test b/modules/contact/contact.test
index 6cfe62994..05f633286 100644
--- a/modules/contact/contact.test
+++ b/modules/contact/contact.test
@@ -51,6 +51,11 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
$this->assertRaw(t('%recipient is an invalid e-mail address.', array('%recipient' => $invalid_recipient)), t('Caught invalid recipient (' . $invalid_recipient . ').'));
}
+ // Test validation of empty category and recipients fields.
+ $this->addCategory($category = '', '', '', TRUE);
+ $this->assertText(t('Category field is required.'), t('Caught empty category field'));
+ $this->assertText(t('Recipients field is required.'), t('Caught empty recipients field.'));
+
// Create valid categories.
$recipients = array('simpletest@test.com', 'simpletest2@test.com', 'simpletest3@test.com');
$this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0])), '', TRUE);
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 453824fba..2f3d40155 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -842,7 +842,7 @@ class DrupalWebTestCase {
$upload = array();
$submit_matches = $this->handleForm($post, $edit, $upload, $submit, $form);
$action = isset($form['action']) ? $this->getAbsoluteUrl($form['action']) : $this->getUrl();
-
+
// We post only if we managed to handle every field in edit and the
// submit button matches.
if (!$edit && $submit_matches) {