#936418: Site-wide contact test relies on autoincrement details.

From: Damien Tournoud <damien@commerceguys.com>


---
 contact/contact.test |   31 ++++++++++++++++---------------
 1 files changed, 16 insertions(+), 15 deletions(-)

diff --git modules/contact/contact.test modules/contact/contact.test
index b758a08..8c286a3 100644
--- modules/contact/contact.test
+++ modules/contact/contact.test
@@ -116,19 +116,20 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
     $this->assertResponse(200, t('Access granted to anonymous user with permission.'));
 
     // Submit contact form with invalid values.
-    $this->submitContact('', $recipients[0], $this->randomName(16), $categories[0], $this->randomName(64));
+    $category_id = reset($categories);
+    $this->submitContact('', $recipients[0], $this->randomName(16), $category_id, $this->randomName(64));
     $this->assertText(t('Your name field is required.'), t('Name required.'));
 
-    $this->submitContact($this->randomName(16), '', $this->randomName(16), $categories[0], $this->randomName(64));
+    $this->submitContact($this->randomName(16), '', $this->randomName(16), $category_id, $this->randomName(64));
     $this->assertText(t('Your e-mail address field is required.'), t('E-mail required.'));
 
-    $this->submitContact($this->randomName(16), $invalid_recipients[0], $this->randomName(16), $categories[0], $this->randomName(64));
+    $this->submitContact($this->randomName(16), $invalid_recipients[0], $this->randomName(16), $category_id, $this->randomName(64));
     $this->assertText(t('You must enter a valid e-mail address.'), t('Valid e-mail required.'));
 
-    $this->submitContact($this->randomName(16), $recipients[0], '', $categories[0], $this->randomName(64));
+    $this->submitContact($this->randomName(16), $recipients[0], '', $category_id, $this->randomName(64));
     $this->assertText(t('Subject field is required.'), t('Subject required.'));
 
-    $this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), $categories[0], '');
+    $this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), $category_id, '');
     $this->assertText(t('Message field is required.'), t('Message required.'));
 
     // Test contact form with no default category selected.
@@ -144,7 +145,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
 
     // Submit contact form with correct values and check flood interval.
     for ($i = 0; $i < $flood_limit; $i++) {
-      $this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), $categories[0], $this->randomName(64));
+      $this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), $category_id, $this->randomName(64));
       $this->assertText(t('Your message has been sent.'), t('Message sent.'));
     }
     // Submit contact form one over limit.
@@ -171,11 +172,12 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
     $this->addCategory('foo', 'foo@example.com', $foo_autoreply, FALSE);
     $this->addCategory('bar', 'bar@example.com', $bar_autoreply, FALSE);
     $this->addCategory('no_autoreply', 'bar@example.com', '', FALSE);
+    $categories = $this->getCategories();
 
     // Test the auto-reply for category 'foo'.
     $email = $this->randomName(32) . '@example.com';
     $subject = $this->randomName(64);
-    $this->submitContact($this->randomName(16), $email, $subject, 2, $this->randomString(128));
+    $this->submitContact($this->randomName(16), $email, $subject, $categories['foo'], $this->randomString(128));
 
     // We are testing the auto-reply, so there should be one e-mail going to the sender.
     $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'foo@example.com'));
@@ -184,7 +186,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
 
     // Test the auto-reply for category 'bar'.
     $email = $this->randomName(32) . '@example.com';
-    $this->submitContact($this->randomName(16), $email, $this->randomString(64), 3, $this->randomString(128));
+    $this->submitContact($this->randomName(16), $email, $this->randomString(64), $categories['bar'], $this->randomString(128));
 
     // Auto-reply for category 'bar' should result in one auto-reply e-mail to the sender.
     $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'bar@example.com'));
@@ -193,7 +195,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
 
     // Verify that no auto-reply is sent when the auto-reply field is left blank.
     $email = $this->randomName(32) . '@example.com';
-    $this->submitContact($this->randomName(16), $email, $this->randomString(64), 4, $this->randomString(128));
+    $this->submitContact($this->randomName(16), $email, $this->randomString(64), $categories['no_autoreply'], $this->randomString(128));
     $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'no_autoreply@example.com'));
     $this->assertEqual(count($captured_emails), 0, t('No auto-reply e-mail was sent to the sender for category "no-autoreply".'), t('Contact'));
   }
@@ -258,20 +260,19 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
    */
   function deleteCategories() {
     $categories = $this->getCategories();
-    foreach ($categories as $category) {
-      $category_name = db_query("SELECT category FROM {contact} WHERE cid = :cid", array(':cid' => $category))->fetchField();
-      $this->drupalPost('admin/structure/contact/delete/' . $category, array(), t('Delete'));
-      $this->assertRaw(t('Category %category has been deleted.', array('%category' => $category_name)), t('Category deleted sucessfully.'));
+    foreach ($categories as $name => $cid) {
+      $this->drupalPost('admin/structure/contact/delete/' . $cid, array(), t('Delete'));
+      $this->assertRaw(t('Category %category has been deleted.', array('%category' => $name)), t('Category deleted sucessfully.'));
     }
   }
 
   /**
    * Get list category ids.
    *
-   * @return array Category ids.
+   * @return array Category ids, keyed by category name.
    */
   function getCategories() {
-    $categories = db_query('SELECT cid FROM {contact}')->fetchCol();
+    $categories = db_query('SELECT category, cid FROM {contact}')->fetchAllKeyed();
     return $categories;
   }
 }
