add missing comments - tests directory
[civicrm-core.git] / tests / phpunit / WebTest / Mailing / AddMessageTemplateTest.php
index 5a2d5d07c4957f360f9e4a495395dde0e0e865a5..f3ea2be417c52762eae1295d84e4b717e10825fe 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -24,7 +24,6 @@
  +--------------------------------------------------------------------+
 */
 
-
 require_once 'CiviTest/CiviSeleniumTestCase.php';
 class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
 
@@ -32,10 +31,13 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
     parent::setUp();
   }
 
+  /**
+   * @param bool $useTokens
+   * @param null $msgTitle
+   */
   function testTemplateAdd($useTokens = FALSE, $msgTitle = NULL) {
     $this->webtestLogin();
 
-    // Go directly to the URL of the screen that you will be testing (Add Message Template).
     $this->openCiviPage("admin/messageTemplates/add", "action=add&reset=1");
 
     // Fill message title.
@@ -45,27 +47,12 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
     $this->type("msg_title", $msgTitle);
     if ($useTokens) {
       //Add Tokens
-      $this->click("css=#msg_subject + a");
-      $this->waitForElementPresent("css=#tokenSubject + .ui-dialog-buttonpane button");
-      $this->type("filter3", "display");
-      $this->addSelection("token3", "label=Display Name");
-      $this->type("filter3", "contact");
-      $this->addSelection("token3", "label=Contact Type");
-      $this->click("css=#tokenSubject + .ui-dialog-buttonpane button");
-      $this->click("//span[@id='helptext']/a/label");
-      $this->waitForElementPresent("css=#tokenText + .ui-dialog-buttonpane button");
-      $this->type("filter1", "display");
-      $this->addSelection("token1", "label=Display Name");
-      $this->type("filter1", "contact");
-      $this->addSelection("token1", "label=Contact Type");
-      $this->click("css=#tokenText + .ui-dialog-buttonpane button");
-      $this->click("//span[@id='helphtml']/a/label");
-      $this->waitForElementPresent("css=#tokenHtml + .ui-dialog-buttonpane button");
-      $this->type("filter2", "display");
-      $this->addSelection("token2", "label=Display Name");
-      $this->type("filter2", "contact");
-      $this->addSelection("token2", "label=Contact Type");
-      $this->click("css=#tokenHtml + .ui-dialog-buttonpane button");
+      $this->select2("msg_subject", "Display Name");
+      $this->select2("msg_subject", "Contact Type");
+      $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Display Name", FALSE, TRUE);
+      $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Contact Type", FALSE, TRUE);
+      $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Display Name", FALSE, TRUE);
+      $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Contact Type", FALSE, TRUE);
     }
     else {
       // Fill message subject.
@@ -85,7 +72,7 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     // Is status message correct
-    $this->assertElementContainsText('crm-notification-container', "The Message Template '$msgTitle' has been saved.");
+    $this->waitForText('crm-notification-container', "The Message Template '$msgTitle' has been saved.");
 
     // Verify text.
     $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[1][contains(text(), '$msgTitle')]"),
@@ -113,14 +100,8 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
     $this->click("_qf_GroupContact_next");
 
     // configure default mail-box
-    $this->openCiviPage("admin/mailSettings", "action=update&id=1&reset=1", '_qf_MailSettings_cancel-bottom');
-    $this->type('name', 'Test Domain');
-    $this->type('domain', 'example.com');
-    $this->select('protocol', 'value=1');
-    $this->click('_qf_MailSettings_next-bottom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->setupDefaultMailbox();
 
-    // Go directly to Schedule and Send Mailing form
     $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
 
     // fill mailing name
@@ -145,6 +126,9 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
 
     $this->click("template");
     $this->select("template", "label=$msgTitle");
+    // Because it tends to cause problems, all uses of sleep() must be justified in comments
+    // Sleep should never be used for wait for anything to load from the server
+    // Justification for this instance: FIXME
     sleep(5);
     $this->click("xpath=id('Upload')/div[2]/fieldset[@id='compose_id']/div[2]/div[1]");
     $this->click('subject');
@@ -176,8 +160,8 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //check redirected page to Scheduled and Sent Mailings and  verify for mailing name
-    $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings");
-    $this->assertElementContainsText("xpath=//table[@class='selector']/tbody//tr//td", "Mailing $mailingName Webtest");
+    $this->assertElementContainsText('page-title', "Find Mailings");
+    $this->isTextPresent("Mailing $mailingName Webtest");
     $this->openCiviPage('mailing/queue', 'reset=1');
 
     // verify status
@@ -194,4 +178,4 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
     $this->waitForElementPresent("_qf_ActivityView_next");
     $this->assertElementContainsText('help', "Bulk Email Sent.", "Status message didn't show up after saving!");
   }
-}
\ No newline at end of file
+}