summaryrefslogtreecommitdiff
path: root/modules/contact
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-02-17 03:59:43 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-02-17 03:59:43 +0000
commit8151b56c28de3f0ae5b4f67b7666d6457721ac4f (patch)
tree6be8b248feb88a2f993f9327ed22474a29d14591 /modules/contact
parentdb7f5e4c909316167b19d9f62e9eea93ed4ef181 (diff)
downloadbrdo-8151b56c28de3f0ae5b4f67b7666d6457721ac4f.tar.gz
brdo-8151b56c28de3f0ae5b4f67b7666d6457721ac4f.tar.bz2
#246880 by mr.baileys: Fixed Error when adding duplicate category to contact form module (with tests).
Diffstat (limited to 'modules/contact')
-rw-r--r--modules/contact/contact.admin.inc12
-rw-r--r--modules/contact/contact.test5
2 files changed, 17 insertions, 0 deletions
diff --git a/modules/contact/contact.admin.inc b/modules/contact/contact.admin.inc
index 585d5f8a0..6677962a5 100644
--- a/modules/contact/contact.admin.inc
+++ b/modules/contact/contact.admin.inc
@@ -112,6 +112,18 @@ function contact_category_edit_form($form, &$form_state, array $category = array
function contact_category_edit_form_validate($form, &$form_state) {
// Validate and each e-mail recipient.
$recipients = explode(',', $form_state['values']['recipients']);
+
+ // When creating a new contact form, or renaming the category on an existing
+ // contact form, make sure that the given category is unique.
+ $category = $form_state['values']['category'];
+ $query = db_select('contact', 'c')->condition('c.category', $category, '=');
+ if (!empty($form_state['values']['cid'])) {
+ $query->condition('c.cid', $form_state['values']['cid'], '<>');
+ }
+ if ($query->countQuery()->execute()->fetchField()) {
+ form_set_error('category', t('A contact form with category %category already exists.', array('%category' => $category)));
+ }
+
foreach ($recipients as &$recipient) {
$recipient = trim($recipient);
if (!valid_email_address($recipient)) {
diff --git a/modules/contact/contact.test b/modules/contact/contact.test
index 02adc9709..b54dbe3d0 100644
--- a/modules/contact/contact.test
+++ b/modules/contact/contact.test
@@ -94,6 +94,11 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
$this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE);
$this->assertRaw(t('Category %category has been saved.', array('%category' => $category)), t('Category successfully saved.'));
+ // Try adding a category that already exists.
+ $this->addCategory($category, '', '', FALSE);
+ $this->assertNoRaw(t('Category %category has been saved.', array('%category' => $category)), t('Category not saved.'));
+ $this->assertRaw(t('A contact form with category %category already exists.', array('%category' => $category)), t('Duplicate category error found.'));
+
// Clear flood table in preparation for flood test and allow other checks to complete.
db_delete('flood')->execute();
$num_records_after = db_query("SELECT COUNT(*) FROM {flood}")->fetchField();