Start migrating to use clickLink method
[civicrm-core.git] / tests / phpunit / WebTest / Member / ContactContextAddTest.php
index 1d9f18af245031cbe3d0bfbf4e61fb6f888b152e..88d714891bcac020d34267de03f74e06ca26b2ef 100644 (file)
@@ -33,16 +33,13 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
   }
 
   function testContactMemberAdd() {
-
-    $this->open($this->sboxPath);
     $this->webtestLogin();
 
     // Create a membership type to use for this test (defaults for this helper function are rolling 1 year membership)
     $memTypeParams = $this->webtestAddMembershipType();
     $lifeTimeMemTypeParams = $this->webtestAddMembershipType('rolling', 1, 'lifetime');
 
-    // Go directly to the URL of the screen that you will be testing (New Individual).
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     $firstName = "John_" . substr(sha1(rand()), 0, 7);
 
@@ -50,7 +47,7 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
     $this->type("first_name", $firstName);
 
     //fill in last name
-    $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
+    $lastName = "Smith_" . substr(sha1(rand()), 0, 7);
     $this->type("last_name", $lastName);
 
     //fill in email
@@ -60,8 +57,7 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
     // Clicking save.
     $this->click("_qf_Contact_upload_view");
     $this->waitForPageToLoad($this->getTimeoutMsec());
-
-    $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
+    $this->assertElementContainsText('crm-notification-container', "$firstName $lastName has been created.");
 
     // click through to the membership view screen
     $this->click("css=li#tab_member a");
@@ -75,6 +71,9 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
     $this->select("membership_type_id[0]", "label={$memTypeParams['member_of_contact']}");
     // Wait for membership type select to reload
     $this->waitForTextPresent($memTypeParams['membership_type']);
+    // 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("membership_type_id[1]", "label={$memTypeParams['membership_type']}");
 
@@ -95,9 +94,8 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
     $this->waitForTextPresent($sourceText);
 
     // Is status message correct?
-    $this->assertTrue($this->isTextPresent("membership for $firstName $lastName has been added."),
-      "Status message didn't show up after saving!"
-    );
+    $this->assertElementContainsText('crm-notification-container', "membership for $firstName $lastName has been added.",
+      "Status message didn't show up after saving!");
 
     // click through to the membership view screen
     $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
@@ -108,11 +106,8 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
       'Status' => 'New',
       'Source' => $sourceText,
     );
-    foreach ($verifyData as $label => $value) {
-      $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
-        preg_quote($value)
-      );
-    }
+    $this->webtestVerifyTabularData($verifyData);
+
     $this->click("_qf_MembershipView_cancel-bottom");
     $this->waitForPageToLoad($this->getTimeoutMsec());
     // page was loaded
@@ -132,18 +127,9 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
       'Status' => 'New',
       'Source' => $sourceText,
     );
-    foreach ($verifyData as $label => $value) {
-      $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
-        preg_quote($value)
-      );
-    }
-
-    $this->click("_qf_MembershipView_cancel-bottom");
-
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->waitForElementPresent("xpath=//div[@id='memberships']/div/table/tbody//tr/td[1][text()='{$memTypeParams['membership_type']}']/../td[7]");
+    $this->webtestVerifyTabularData($verifyData);
+    $this->clickLink("_qf_MembershipView_cancel-bottom", "xpath=//div[@id='memberships']/div/table/tbody//tr/td[1][text()='{$memTypeParams['membership_type']}']/../td[7]");
     $this->click("xpath=//div[@id='memberships']/div/table/tbody//tr/td[1][text()='{$memTypeParams['membership_type']}']/../td[9]/span/a[2][text()='Edit']");
-
     $this->waitForElementPresent("_qf_Membership_cancel-bottom");
 
     // fill in Membership Organization and Type
@@ -168,22 +154,16 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
       'Source' => $sourceText,
       'End date' => '',
     );
-    foreach ($verifyData as $label => $value) {
-      $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
-        preg_quote($value)
-      );
-    }
+    $this->webtestVerifyTabularData($verifyData);
   }
 
   function testMemberAddWithLifeTimeMembershipType() {
-    $this->open($this->sboxPath);
     $this->webtestLogin();
 
     // Create a membership type to use for this test (defaults for this helper function are rolling 1 year membership)
     $lifeTimeMemTypeParams = $this->webtestAddMembershipType('rolling', 1, 'lifetime');
 
-    // Go directly to the URL of the screen that you will be testing (New Individual).
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     $firstName = "John_" . substr(sha1(rand()), 0, 7);
 
@@ -201,8 +181,7 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
     // Clicking save.
     $this->click("_qf_Contact_upload_view");
     $this->waitForPageToLoad($this->getTimeoutMsec());
-
-    $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
+    $this->assertElementContainsText('crm-notification-container', "$firstName $lastName has been created.");
 
     // click through to the membership view screen
     $this->click("css=li#tab_member a");
@@ -217,6 +196,9 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
 
     // Wait for membership type select to reload
     $this->waitForTextPresent($lifeTimeMemTypeParams['membership_type']);
+    // 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("membership_type_id[1]", "label={$lifeTimeMemTypeParams['membership_type']}");
 
@@ -237,9 +219,8 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
     $this->waitForTextPresent($sourceText);
 
     // Is status message correct?
-    $this->assertTrue($this->isTextPresent("membership for $firstName $lastName has been added."),
-      "Status message didn't show up after saving!"
-    );
+    $this->assertElementContainsText('crm-notification-container', "membership for $firstName $lastName has been added.",
+      "Status message didn't show up after saving!");
 
     // click through to the membership view screen
     $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
@@ -250,11 +231,7 @@ class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
       'Source' => $sourceText,
       'End date' => '',
     );
-    foreach ($verifyData as $label => $value) {
-      $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
-        preg_quote($value)
-      );
-    }
+    $this->webtestVerifyTabularData($verifyData);
     $this->click("_qf_MembershipView_cancel-bottom");
     $this->waitForPageToLoad($this->getTimeoutMsec());
   }