Merge pull request #469 from colemanw/versionUpdate
[civicrm-core.git] / tests / phpunit / WebTest / Report / LoggingReportTest.php
index 8195b1a3ae2c377f73b7ea786886c30c72557a5e..ff0d6115377ea870dc03be046d416186b8353551 100644 (file)
@@ -24,7 +24,6 @@
  +--------------------------------------------------------------------+
 */
 
-
 require_once 'CiviTest/CiviSeleniumTestCase.php';
 class WebTest_Report_LoggingReportTest extends CiviSeleniumTestCase {
 
@@ -39,7 +38,8 @@ class WebTest_Report_LoggingReportTest extends CiviSeleniumTestCase {
     $this->openCiviPage('admin/setting/misc', 'reset=1');
     $this->click("xpath=//tr[@class='crm-miscellaneous-form-block-logging']/td[2]/label[text()='Yes']");
     $this->click("_qf_Miscellaneous_next-top");
-    $this->waitForTextPresent("Changes Saved");
+    $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
+    // FIXME: good to do waitForText here but enabling log is time consuming and status may fade out by the time we do the check.
 
     //enable CiviCase component
     $this->enableComponents("CiviCase");
@@ -49,17 +49,17 @@ class WebTest_Report_LoggingReportTest extends CiviSeleniumTestCase {
     $lastName  = 'Anderson' . substr(sha1(rand()), 0, 7);
 
     $this->webtestAddContact($firstName, $lastName);
-    $cid = explode('&cid=', $this->getLocation());
+    $cid = $this->urlArg('cid');
 
     //add contact to group
     $this->waitForElementPresent("xpath=//li[@id='tab_group']/a");
     $this->click("xpath=//li[@id='tab_group']/a");
+    // 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(3);
     $this->select("group_id", "label=Case Resources");
-    $this->click("_qf_GroupContact_next");
-
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->waitForElementPresent("xpath=//form[@id='GroupContact']//div[@class='view-content']//div[@class='dataTables_wrapper']/table/tbody/tr/td[4]/a");
+    $this->clickLink("_qf_GroupContact_next", "xpath=//form[@id='GroupContact']//div[@class='view-content']//div[@class='dataTables_wrapper']/table/tbody/tr/td[4]/a");
     $this->click("xpath=//form[@id='GroupContact']//div[@class='view-content']//div[@class='dataTables_wrapper']/table/tbody/tr/td[4]/a");
 
     // Check confirmation alert.
@@ -72,6 +72,9 @@ class WebTest_Report_LoggingReportTest extends CiviSeleniumTestCase {
     //tag addition
     $this->waitForElementPresent("xpath=//li[@id='tab_tag']/a");
     $this->click("xpath=//li[@id='tab_tag']/a");
+    // 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(3);
     $this->click("xpath=//div[@id='tagtree']/ul//li/label[text()='Company']/../input");
     $this->waitForTextPresent("Saved");
@@ -83,6 +86,9 @@ class WebTest_Report_LoggingReportTest extends CiviSeleniumTestCase {
     //add new note
     $this->waitForElementPresent("xpath=//li[@id='tab_note']/a");
     $this->click("xpath=//li[@id='tab_note']/a");
+    // 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(3);
     $this->click("xpath=//div[@id='Notes']//div[@class='action-link']/a");
 
@@ -98,9 +104,8 @@ class WebTest_Report_LoggingReportTest extends CiviSeleniumTestCase {
     $this->waitForElementPresent("_qf_Note_upload-top");
     $this->type('subject', $noteSubject . "_edited");
     $this->type('note', $noteText . "_edited");
-    $this->click("_qf_Note_upload-top");
+    $this->clickLink("_qf_Note_upload-top", "xpath=//div[@class='crm-results-block']/div[@id='notes']/div/table/tbody/tr//td/span[2]/ul/li[2]/a[text()='Delete']");
 
-    $this->waitForElementPresent("xpath=//div[@class='crm-results-block']/div[@id='notes']/div/table/tbody/tr//td/span[2]/ul/li[2]/a[text()='Delete']");
     $this->click("xpath=//div[@class='crm-results-block']/div[@id='notes']/div/table/tbody/tr//td/span[2]/ul/li[2]/a[text()='Delete']");
     // Check confirmation alert.
     $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this note/",
@@ -108,19 +113,18 @@ class WebTest_Report_LoggingReportTest extends CiviSeleniumTestCase {
       ));
     $this->chooseOkOnNextConfirmation();
     $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForText('crm-notification-container', "deleted successfully");
 
     //add new relationship , disable it , delete it
     $this->waitForElementPresent("xpath=//li[@id='tab_rel']/a");
-    $this->click("xpath=//li[@id='tab_rel']/a");
-    sleep(3);
-    $this->click("xpath=//div[@id='Relationships']//div[@class='action-link']/a");
-    $this->waitForElementPresent("_qf_Relationship_refresh");
+    $this->click("css=li#tab_rel a");
+    $this->waitForElementPresent("link=Add Relationship");
+    $this->click("link=Add Relationship");
+    $this->waitForElementPresent("_qf_Relationship_cancel");
     $this->select("relationship_type_id", "label=Employee of");
-    $this->webtestFillAutocomplete("Default Organization");
+    $this->webtestFillAutocomplete("Default");
     $this->waitForElementPresent("quick-save");
-    $this->click("quick-save");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->waitForElementPresent("xpath=//div[@id='current-relationships']//a[text()='Disable']");
+    $this->clickLink("quick-save", "xpath=//div[@id='current-relationships']//a[text()='Disable']");
     $this->click("xpath=//div[@id='current-relationships']//a[text()='Disable']");
     $this->assertTrue((bool)preg_match("/^Are you sure you want to disable this relationship/",
       $this->getConfirmation()
@@ -249,7 +253,7 @@ class WebTest_Report_LoggingReportTest extends CiviSeleniumTestCase {
     $this->detailReportCheck($dataForReportDetail, $filters);
 
     //delete contact check
-    $this->openCiviPage('contact/view/delete', "reset=1&delete=1&cid={$cid[1]}");
+    $this->openCiviPage('contact/view/delete', "reset=1&delete=1&cid=$cid");
     $this->click("_qf_Delete_done");
     $this->waitForPageToLoad($this->getTimeoutMsec());