Start migrating to use clickLink method
[civicrm-core.git] / tests / phpunit / WebTest / Contact / MergeContactsTest.php
index 3fd0e8a4a43dbdf69e91a15da413b9170b2caa0f..eaf96427137d58bf7224a64aaa0144fa575cf9dd 100644 (file)
@@ -35,8 +35,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
   function testIndividualAdd() {
     $this->webtestLogin();
 
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     // add contact1
     //select prefix
@@ -88,7 +87,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->addActivity($firstName, $lastName, $subject);
 
     // contact2: duplicate of contact1.
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     //fill in first name
     $this->type("first_name", $firstName);
@@ -115,8 +114,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->webtestAddContact($fname2, $lname2, $email2);
 
     // Can not use helper for 2nd contact since it is a dupe
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
     $this->type("first_name", $fname2);
     $this->type("last_name", $lname2);
     $this->type("email_1_email", $email2);
@@ -128,25 +126,19 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->assertElementContainsText('crm-notification-container', "Contact Saved");
 
     // Find and Merge Contacts with Supervised Rule
-    $this->open($this->sboxPath . 'civicrm/contact/dedupefind?reset=1&rgid=1&action=renew');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
 
     // reload the page
-    $this->open($this->sboxPath . 'civicrm/contact/dedupefind?reset=1&rgid=1&action=update');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=update");
 
     // Select the contacts to be merged
     $this->select("name=option51_length", "value=100");
-    $this->waitForTextPresent("$firstName $lastName");
 
-    // sleep seems to work here, not sure why
-    sleep(3);
+    $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
     $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
     $this->waitForElementPresent('_qf_Merge_cancel-bottom');
 
-    $this->click("css=div.crm-contact-merge-form-block div.action-link a");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->waitForElementPresent('_qf_Merge_cancel-bottom');
+    $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", '_qf_Merge_cancel-bottom');
 
     // Move the activities, groups, etc to the main contact and merge using Merge and Goto Next Pair
     $this->check('move_prefix_id');
@@ -154,9 +146,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->check('move_rel_table_activities');
     $this->check('move_rel_table_groups');
     $this->check('move_rel_table_tags');
-    $this->click('_qf_Merge_next-bottom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->waitForElementPresent('_qf_Merge_cancel-bottom');
+    $this->clickLink('_qf_Merge_next-bottom', '_qf_Merge_cancel-bottom');
     $this->assertTrue($this->isTextPresent('Contacts Merged'), "Contacts Merged text was not found after merge.");
 
     // Check that we are viewing the next Merge Pair (our 2nd contact, since the merge list is ordered by contact_id)
@@ -282,8 +272,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
   function testMergeTest() {
     $this->webtestLogin();
 
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     // add contact1
     //fill in first name
@@ -318,7 +307,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->assertElementContainsText('crm-notification-container', "Contact Saved");
 
     // contact2: duplicate of contact1.
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     //fill in first name
     $this->type("first_name", $firstName);
@@ -342,17 +331,14 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->assertElementContainsText('crm-notification-container', "Contact Saved");
 
     // Find and Merge Contacts with Supervised Rule
-    $this->open($this->sboxPath . 'civicrm/contact/dedupefind?reset=1&rgid=1&action=renew');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
 
     // Select the contacts to be merged
     $this->select("name=option51_length", "value=100");
     $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']");
     $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
     $this->waitForElementPresent('_qf_Merge_cancel-bottom');
-    $this->click("css=div.crm-contact-merge-form-block div.action-link a");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']");
+    $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", "xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']");
     $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']");
     $this->waitForElementPresent('_qf_Merge_cancel-bottom');
 
@@ -380,8 +366,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[2][contains(text(), '9876543120')]"));
 
     //Merge with the feature of (add)
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     // add contact1
     //fill in first name
@@ -411,7 +396,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->assertElementContainsText('crm-notification-container', "Contact Saved");
 
     // contact2: duplicate of contact1.
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     //fill in first name
     $this->type("first_name", $firstName1);
@@ -435,17 +420,14 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->assertElementContainsText('crm-notification-container', "Contact Saved");
 
     // Find and Merge Contacts with Supervised Rule
-    $this->open($this->sboxPath . 'civicrm/contact/dedupefind?reset=1&rgid=1&action=renew');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
 
     // Select the contacts to be merged
     $this->select("name=option51_length", "value=100");
     $this->waitForElementPresent("xpath=//table[@class='pagerDisplay']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']");
     $this->click("xpath=//table[@class='pagerDisplay']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']/../../td[4]/a[text()='merge']");
     $this->waitForElementPresent('_qf_Merge_cancel-bottom');
-    $this->click("css=div.crm-contact-merge-form-block div.action-link a");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']");
+    $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", "xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']");
     $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']");
     $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']");
     $this->select('location_email_1_locTypeId', 'value=3');
@@ -483,8 +465,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
 
     //add contact2 and its duplicate
     //These are the contacts with conflicts in communication preference.these contacts will be skipped during merge.
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     //fill in first name
     $firstName1 = "Kurt".substr(sha1(rand()), 0, 7);
@@ -521,7 +502,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->assertElementContainsText('crm-notification-container', "Contact Saved");
 
     //duplicate of contact2.
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     //fill in first name
     $this->type("first_name", $firstName1);
@@ -562,9 +543,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->_createContacts($firstName3,$lastName3);
 
     // Find and Merge Contacts with Supervised Rule
-    $this->open($this->sboxPath . 'civicrm/contact/dedupefind?reset=1&rgid=1&action=renew');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    sleep(3);
+    $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew", "css=#DedupeFind table.pagerDisplay tbody tr");
 
     $this->select("name=option51_length", "value=100");
     $totalContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
@@ -577,11 +556,20 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
                                        ));
     $this->chooseOkOnNextConfirmation();
     $this->waitForPageToLoad($this->getTimeoutMsec());
-    sleep(5);
+    $this->waitForElementPresent('civicrm-footer');
+    $this->assertElementContainsText('crm-notification-container', "safe mode");
+
+    // If we are still on the dedupe table page, count unmerged contacts
+    if ($this->isElementPresent("//table[@class='pagerDisplay']")) {
+      // Wait for datatable to load
+      $this->waitForElementPresent("//table[@class='pagerDisplay']/tbody/tr");
+      $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
+    }
+    else {
+      $unMergedContacts = 0;
+    }
 
-    $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
     $mergedContacts = $totalContacts - $unMergedContacts;
-    $this->assertElementContainsText('crm-notification-container', "safe mode");
 
     //check the existence of merged contacts
     $contactEmails = array(
@@ -590,7 +578,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
       3 => "{$firstName3}.{$lastName3}@example.com"
     );
 
-    foreach( $contactEmails as $key => $value ) {
+    foreach($contactEmails as $key => $value) {
       $this->click('sort_name_navigation');
       $this->type('css=input#sort_name_navigation', $value);
       $this->typeKeys('css=input#sort_name_navigation', $value);
@@ -598,9 +586,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
       $this->waitForElementPresent("css=div.ac_results-inner li");
 
       // Visit contact summary page.
-      $this->click("css=div.ac_results-inner li");
-      $this->waitForPageToLoad($this->getTimeoutMsec());
-      sleep(2);
+      $this->clickLink("css=div.ac_results-inner li", 'civicrm-footer');
     }
   }
 
@@ -609,7 +595,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
    */
   function _createContacts($firstName,$lastName){
     // add contact
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
     //fill in first name
     $this->type('first_name', $firstName);
 
@@ -631,7 +617,7 @@ class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
     $this->assertElementContainsText('crm-notification-container', "Contact Saved");
 
     //duplicate of above contact.
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     //fill in first name
     $this->type("first_name", $firstName);