Refactor webtestNewDialogContact and other webtest cleanup
authorColeman Watts <coleman@civicrm.org>
Sat, 20 Sep 2014 03:45:24 +0000 (23:45 -0400)
committerColeman Watts <coleman@civicrm.org>
Sat, 20 Sep 2014 03:45:24 +0000 (23:45 -0400)
18 files changed:
tests/phpunit/CiviTest/CiviSeleniumTestCase.php
tests/phpunit/WebTest/Case/ActivityToCaseTest.php
tests/phpunit/WebTest/Case/AddCaseTest.php
tests/phpunit/WebTest/Case/AddCaseTypeTest.php
tests/phpunit/WebTest/Case/CaseCustomFieldsTest.php
tests/phpunit/WebTest/Case/CaseDashboardTest.php
tests/phpunit/WebTest/Contact/SearchBuilderTest.php
tests/phpunit/WebTest/Contribute/AddPricesetTest.php
tests/phpunit/WebTest/Contribute/StandaloneAddTest.php
tests/phpunit/WebTest/Contribute/UpdateBatchPendingContributionTest.php
tests/phpunit/WebTest/Contribute/UpdateContributionTest.php
tests/phpunit/WebTest/Contribute/UpdatePendingContributionTest.php
tests/phpunit/WebTest/Event/AddParticipationTest.php
tests/phpunit/WebTest/Grant/CustomFieldsetTest.php
tests/phpunit/WebTest/Grant/StandaloneAddTest.php
tests/phpunit/WebTest/Pledge/AddCancelPaymentTest.php
tests/phpunit/WebTest/Pledge/StandaloneAddDeleteTest.php
tests/phpunit/WebTest/Pledge/StandaloneAddTest.php

index 77914c31f0f0d070e14c3591ac43954b1c576bd7..d6cbb6447d3b5325396617617459246a7ef32538 100644 (file)
@@ -621,6 +621,41 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
+   * Use a contact EntityRef field to add a new contact
+   * @param string $field selector
+   * @param string $contactType
+   * @return array of contact attributes (id, names, email)
+   */
+  function createDialogContact($field = 'contact_id', $contactType = 'Individual') {
+    $selectId = 's2id_' . $this->getAttribute($field . '@id');
+    $this->clickAt("xpath=//div[@id='$selectId']/a");
+    $this->clickAjaxLink("xpath=//li[@class='select2-no-results']//a[contains(text(), 'New $contactType')]", '_qf_Edit_next');
+
+    $name = substr(sha1(rand()), 0, rand(6, 8));
+    $params = array();
+    if ($contactType == 'Individual') {
+      $params['first_name'] = "$name $contactType";
+      $params['last_name'] = substr(sha1(rand()), 0, rand(5, 9));
+    }
+    else {
+      $params[strtolower($contactType) . '_name'] = "$name $contactType";
+    }
+    foreach($params as $param => $val) {
+      $this->type($param, $val);
+    }
+    $this->type('email-Primary', $params['email'] = "{$name}@example.com");
+    $this->clickAjaxLink('_qf_Edit_next');
+
+    $this->waitForText("xpath=//div[@id='$selectId']","$name");
+
+    $params['sort_name'] = $contactType == 'Individual' ? $params['last_name'] . ', ' . $params['first_name'] : "$name $contactType";
+    $params['display_name'] = $contactType == 'Individual' ? $params['first_name'] . ' ' . $params['last_name'] : $params['sort_name'];
+    $params['id'] = $this->getValue($field);
+    return $params;
+  }
+
+  /**
+   * @deprecated in favor of createDialogContact
    */
   function webtestNewDialogContact($fname = 'Anthony', $lname = 'Anderson', $email = 'anthony@anderson.biz',
                                    $type = 4, $selectId = 's2id_contact_id', $row = 1, $prefix = '') {
index 37e15b1b0c832702f4cc3d97d62a5076b33c84a6..dc6b106d76e652a192a24391f108404e4952da7f 100644 (file)
@@ -37,7 +37,7 @@ class WebTest_Case_ActivityToCaseTest extends CiviSeleniumTestCase {
 
   function testAddActivityToCase() {
     // Log in as admin first to verify permissions for CiviCase
-    $this->webtestLogin('true');
+    $this->webtestLogin('admin');
 
     // Enable CiviCase module if necessary
     $this->enableComponents("CiviCase");
@@ -53,12 +53,7 @@ class WebTest_Case_ActivityToCaseTest extends CiviSeleniumTestCase {
 
     // Adding contact with randomized first name (so we can then select that contact when creating case)
     // We're using pop-up New Contact dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $lastName = "Fraser";
-    $contactName = "{$lastName}, {$firstName}";
-    $displayName = "{$firstName} {$lastName}";
-    $email = "{$lastName}.{$firstName}@example.org";
-    $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4, "s2id_client_id");
+    $contact = $this->createDialogContact("client_id");
 
     // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
     $caseTypeLabel = "Adult Day Care Referral";
@@ -80,10 +75,10 @@ class WebTest_Case_ActivityToCaseTest extends CiviSeleniumTestCase {
     $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom', FALSE);
 
     // Is status message correct?
-    $this->waitForText('crm-notification-container', "Case opened successfully.");
+    $this->checkCRMAlert("Case opened successfully.");
     $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 7);
 
-    $this->_testAddNewActivity($firstName, $subject, $customGroupTitle, $contactName);
+    $this->_testAddNewActivity($contact['first_name'], $subject, $customGroupTitle, $contact['sort_name']);
   }
 
   function testLinkCases() {
@@ -97,12 +92,7 @@ class WebTest_Case_ActivityToCaseTest extends CiviSeleniumTestCase {
 
     // Adding contact with randomized first name (so we can then select that contact when creating case)
     // We're using pop-up New Contact dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $lastName = "Fraser";
-    $contactName = "{$lastName}, {$firstName}";
-    $displayName = "{$firstName} {$lastName}";
-    $email = "{$lastName}.{$firstName}@example.org";
-    $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4, "s2id_client_id");
+    $contact1 = $this->createDialogContact('client_id');
 
     // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
     $caseTypeLabel = "Adult Day Care Referral";
@@ -121,22 +111,17 @@ class WebTest_Case_ActivityToCaseTest extends CiviSeleniumTestCase {
     $today = date('F jS, Y', strtotime('now'));
 
     $this->type('duration', "20");
-    $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom', FALSE);
+    $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom');
 
     // Is status message correct?
-    $this->waitForText('crm-notification-container', "Case opened successfully.");
+    $this->checkCRMAlert("Case opened successfully.");
 
     //Add Case 2
     $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
 
     // Adding contact with randomized first name (so we can then select that contact when creating case)
     // We're using pop-up New Contact dialog
-    $firstName2 = substr(sha1(rand()), 0, 7);
-    $lastName2 = "Fraser";
-    $contactName2 = "{$lastName}, {$firstName}";
-    $displayName2 = "{$firstName} {$lastName}";
-    $email2 = "{$lastName2}.{$firstName2}@example.org";
-    $this->webtestNewDialogContact($firstName2, $lastName2, $email2, $type = 4, "s2id_client_id");
+    $contact2 = $this->createDialogContact('client_id');
 
     // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
     $caseTypeLabel2 = "Adult Day Care Referral";
@@ -155,34 +140,35 @@ class WebTest_Case_ActivityToCaseTest extends CiviSeleniumTestCase {
     $today = date('F jS, Y', strtotime('now'));
 
     $this->type('duration', "20");
-    $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom', FALSE);
+    $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom');
 
     // Is status message correct?
-    $this->waitForText('crm-notification-container', "Case opened successfully.");
+    $this->checkCRMAlert("Case opened successfully.");
 
-    //Add Link Case Activity
+    // We should now be on the "manage case" screen for case 2
+    //Add Link Case Activity to case 1
     $this->select('add_activity_type_id', 'Link Cases');
     $this->waitForElementPresent("_qf_Activity_cancel-bottom");
-    $this->select2('link_to_case_id', $firstName);
+    $this->select2('link_to_case_id', $contact1['sort_name']);
     $activitydetails = 'Details of Link Case Activity';
     $this->fillRichTextField("details", $activitydetails, 'CKEditor');
-    $this->click('activity-details');
-    $this->waitForElementPresent('subject');
+    $this->click('css=#activity-details .crm-accordion-header');
+    $this->waitForVisible('subject');
     $activitySubject = 'Link Case Activity between case 1 and case 2';
     $activitylocation = 'Main Office Building';
-    $this->select2('source_contact_id', $firstName2);
+    $this->select2('source_contact_id', $contact2['sort_name']);
     $this->type('subject', $activitySubject);
     $this->type('location', $activitylocation);
-    $this->click('_qf_Activity_upload-bottom');
+    $this->clickAjaxLink('_qf_Activity_upload-bottom');
     $id = $this->urlArg('id');
     $this->waitForText("case_id_$id", $activitySubject);
     $this->click("xpath=//a[contains(text(),'$activitySubject')]");
 
     $LinkCaseActivityData = array(
-      "Client" => $firstName2,
+      "Client" => $contact2['first_name'],
       "Activity Type" => "Link Cases",
       "Subject" => $activitySubject,
-      "Reported By" => "{$firstName2} {$lastName2}",
+      "Reported By" => $contact2['display_name'],
       "Medium" => "Phone",
       "Location" => $activitylocation,
       "Date and Time" => $today,
index bab7a97ec25356edb742dd45dc6e8dbf2dc734d6..6198e25f6f92d8332bf3f8ca76827c42266ce3fc 100644 (file)
@@ -69,12 +69,7 @@ class WebTest_Case_AddCaseTest extends CiviSeleniumTestCase {
 
     // Adding contact with randomized first name (so we can then select that contact when creating case)
     // We're using pop-up New Contact dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $lastName = "Fraser";
-    $contactName = "{$lastName}, {$firstName}";
-    $displayName = "{$firstName} {$lastName}";
-    $email = "{$lastName}.{$firstName}@example.org";
-    $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4, "s2id_client_id");
+    $client = $this->createDialogContact("client_id");
 
     // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
     $caseTypeLabel = "Adult Day Care Referral";
@@ -106,7 +101,7 @@ class WebTest_Case_AddCaseTest extends CiviSeleniumTestCase {
 
     $summaryStrings = array(
       "Summary",
-      $displayName,
+      $client['display_name'],
       "Type: {$caseTypeLabel}",
       "Open Date: {$today}",
       "Status: {$caseStatusLabel}",
@@ -117,7 +112,7 @@ class WebTest_Case_AddCaseTest extends CiviSeleniumTestCase {
     $this->_testVerifyCaseActivities($activityTypes);
 
     $openCaseData = array(
-      "Client" => $displayName,
+      "Client" => $client['display_name'],
       "Activity Type" => "Open Case",
       "Subject" => $subject,
       "Created By" => "{$testUserFirstName} {$testUserLastName}",
@@ -138,10 +133,10 @@ class WebTest_Case_AddCaseTest extends CiviSeleniumTestCase {
     $this->select("case_status_id","value=2");
     $this->click("_qf_Activity_upload-top");
 
-    $this->_testSearchbyDate($firstName, $lastName, "this.quarter");
-    $this->_testSearchbyDate($firstName, $lastName, "0");
-    $this->_testSearchbyDate($firstName, $lastName, "this.year");
-    $this->_testAssignToClient($firstName, $lastName, $caseTypeLabel);
+    $this->_testSearchbyDate($client['first_name'], $client['last_name'], "this.quarter");
+    $this->_testSearchbyDate($client['first_name'], $client['last_name'], "0");
+    $this->_testSearchbyDate($client['first_name'], $client['last_name'], "this.year");
+    $this->_testAssignToClient($client['first_name'], $client['last_name'], $caseTypeLabel);
   }
 
   function testAjaxCustomGroupLoad() {
@@ -279,17 +274,13 @@ class WebTest_Case_AddCaseTest extends CiviSeleniumTestCase {
    function _testAssignToClient($firstName, $lastName, $caseTypeLabel) {
     $this->openCiviPage('case/search', 'reset=1', '_qf_Search_refresh-bottom'); 
     $this->type('sort_name', $firstName);
-    $this->click('_qf_Search_refresh-bottom');
+    $this->clickLink('_qf_Search_refresh-bottom');
     $this->waitForElementPresent("xpath=//table[@class='caseSelector']/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']");
 
-    $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']/../../td[11]/span[2]/ul/li/a[contains(text(),'Assign to Another Client')]");
-    $clientFirstName = substr(sha1(rand()), 0, 7);
-    $clientLastName = "Fraser";
-    $clientEmail = "{$clientLastName}.{$clientFirstName}@example.org";
-    $this->waitForElementPresent('_qf_EditClient_done-bottom');
-    $this->webtestNewDialogContact($clientFirstName, $clientLastName, $clientEmail, $type = 4, "s2id_reassign_contact_id");
+    $this->clickAjaxLink("xpath=//table[@class='caseSelector']/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']/../../td[11]/span[2]/ul/li/a[contains(text(),'Assign to Another Client')]");
+    $client = $this->createDialogContact("reassign_contact_id");
     $this->clickLink('_qf_EditClient_done-bottom');
-    $this->assertElementContainsText('page-title', "$clientFirstName $clientLastName - $caseTypeLabel");
+    $this->assertElementContainsText('page-title', "{$client['display_name']} - $caseTypeLabel");
   }
 }
 
index dda1b0c47d060a61a3615fd65b3a411f1f60d491..51e01932cbfe41f86730d1f5efc4faf00ceac318 100644 (file)
@@ -74,12 +74,7 @@ class WebTest_Case_AddCaseTypeTest extends CiviSeleniumTestCase {
     $this->clickAjaxLink("xpath=//div[@class='crm-submit-buttons']/span/input[@value='Save']", NULL);
 
     $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
-    $firstName = substr(sha1(rand()), 0, 7);
-    $lastName = "Fraser";
-    $contactName = "{$lastName}, {$firstName}";
-    $displayName = "{$firstName} {$lastName}";
-    $email = "{$lastName}.{$firstName}@example.org";
-    $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4, "s2id_client_id");
+    $client = $this->createDialogContact("client_id");
 
     $caseStatusLabel = "Ongoing";
     $subject = "Safe daytime setting - senior female";
index 71c68e7bb9bd5a3ea56cb79e925f01aceae31d45..e454dfa94e7eef78da9938031361ff8357cf0303 100644 (file)
@@ -45,8 +45,7 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
 
     // create custom group1
     $this->openCiviPage('admin/custom/group', 'reset=1');
-    $this->click("newCustomDataGroup");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("newCustomDataGroup");
     $this->type("title", $customGrp1);
     $this->select("extends[0]", "value=Case");
     // Because it tends to cause problems, all uses of sleep() must be justified in comments
@@ -54,8 +53,7 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
     // Justification for this instance: FIXME
     sleep(1);
     $this->select("extends_1", "value=2");
-    $this->click("_qf_Group_next-bottom");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Group_next-bottom");
 
     // get custom group id
     $customGrpId1 = $this->urlArg('gid');
@@ -82,27 +80,16 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
 
     $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
 
-    // Try submitting the form without creating or selecting a contact (test for CRM-7971)
-    $this->clickLink("_qf_Case_upload-bottom", "css=span.crm-error");
-
     // Adding contact with randomized first name (so we can then select that contact when creating case)
-    // We're using pop-up New Contact dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $lastName = "Fraser";
-    $contactName = "{$lastName}, {$firstName}";
-    $displayName = "{$firstName} {$lastName}";
-    $email = "{$lastName}.{$firstName}@example.org";
     $custFname = "Mike" . substr(sha1(rand()), 0, 7);
     $custMname = "Dav" . substr(sha1(rand()), 0, 7);
     $custLname = "Krist" . substr(sha1(rand()), 0, 7);
-    $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4, "s2id_client_id");
+    // We're using pop-up New Contact dialog
+    $client = $this->createDialogContact("client_id");
 
     // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
     $caseTypeLabel = "Adult Day Care Referral";
 
-    // activity types we expect for this case type
-    $activityTypes = array("ADC referral", "Follow up", "Medical evaluation", "Mental health evaluation");
-    $caseRoles = array("Senior Services Coordinator", "Health Services Coordinator", "Benefits Specialist", "Client");
     $caseStatusLabel = "Ongoing";
     $subject = "Safe daytime setting - senior female";
     $this->select("medium_id", "value=1");
@@ -113,10 +100,7 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
     $this->type("activity_subject", $subject);
 
     $this->select("case_type_id", "label={$caseTypeLabel}");
-    // 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->waitForAjaxContent();
     $this->select("status_id", "label={$caseStatusLabel}");
 
     // Choose Case Start Date.
@@ -131,19 +115,13 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
     $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom");
 
     // Is status message correct?
-    $this->assertTextPresent("Case opened successfully.", "Save successful status message didn't show up after saving!");
-    $this->click("_qf_CaseView_cancel-bottom");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->openCiviPage('case', 'reset=1', "xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[8]/a[text()='Open Case']");
-    $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[8]/a[text()='Open Case']");
-    $this->waitForElementPresent("xpath=//span[@class='ui-button-icon-primary ui-icon ui-icon-closethick']");
-    // 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->checkCRMAlert("Case opened successfully.");
+    $this->clickLink("_qf_CaseView_cancel-bottom");
+    $this->openCiviPage('case', 'reset=1', "xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[8]/a[text()='Open Case']");
+    $this->clickAjaxLink("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[8]/a[text()='Open Case']");
 
     $openCaseData = array(
-      "Client" => $displayName,
+      "Client" => $client['display_name'],
       "Activity Type" => "Open Case",
       "Subject" => $subject,
       "Created By" => "{$testUserFirstName} {$testUserLastName}",
@@ -159,38 +137,27 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
 
     // verify if custom data is present
     $this->openCiviPage('case', 'reset=1');
-    $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->click("css=#{$customGrp1} .crm-accordion-header");
-    $this->waitForElementPresent("css=#{$customGrp1} a.button");
+    $this->clickLink("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[9]/span/a[text()='Manage']");
+
+    $this->clickAjaxLink("css=#{$customGrp1} .crm-accordion-header", "css=#{$customGrp1} a.button");
     $cusId_1 = 'custom_' . $customId[0] . '_1';
     $cusId_2 = 'custom_' . $customId[1] . '_1';
     $cusId_3 = 'custom_' . $customId[2] . '_1';
-    $this->click("css=#{$customGrp1} a.button");
-    // 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(2);
-    $this->waitForElementPresent("{$cusId_1}");
+    $this->clickAjaxLink("css=#{$customGrp1} a.button", $cusId_1);
+
     $custFname = "Miky" . substr(sha1(rand()), 0, 7);
     $custMname = "Davy" . substr(sha1(rand()), 0, 7);
     $custLname = "Kristy" . substr(sha1(rand()), 0, 7);
     $this->type("{$cusId_1}", $custFname);
     $this->type("{$cusId_2}", $custMname);
     $this->type("{$cusId_3}", $custLname);
-    $this->click("_qf_CustomData_upload");
-    // 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(2);
+    $this->clickAjaxLink("_qf_CustomData_upload");
+
     $this->openCiviPage('case', 'reset=1');
-    $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[8]/a[text()='Change Custom Data']");
-    // 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->clickAjaxLink("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[8]/a[text()='Change Custom Data']");
+
     $openCaseChangeData = array(
-      "Client" => $displayName,
+      "Client" => $client['display_name'],
       "Activity Type" => "Change Custom Data",
       "Subject" => $customGrp1 . " : change data",
       "Created By" => "{$testUserFirstName} {$testUserLastName}",
@@ -200,28 +167,10 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
       "Priority" => "Normal",
     );
     $this->webtestVerifyTabularData($openCaseChangeData);
-    $this->click("xpath=//span[@class='ui-button-icon-primary ui-icon ui-icon-closethick']");
-    // 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(2);
     $this->_testAdvansearchCaseData($customId, $custFname, $custMname, $custLname);
     $this->_testDeleteCustomData($customGrpId1, $customId);
   }
 
-  /**
-   * @param $validateStrings
-   * @param $activityTypes
-   */
-  function _testVerifyCaseSummary($validateStrings, $activityTypes) {
-    $this->assertStringsPresent($validateStrings);
-    foreach ($activityTypes as $aType) {
-      $this->assertText("activity_type_id", $aType);
-    }
-    $this->assertElementPresent("link=Assign to Another Client", "Assign to Another Client link is missing.");
-    $this->assertElementPresent("name=case_report_all", "Print Case Summary button is missing.");
-  }
-
   /**
    * @param $customGrpId1
    * @param bool $noteRichEditor
@@ -230,6 +179,7 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
    */
   function _testGetCustomFieldId($customGrpId1, $noteRichEditor=FALSE) {
     $customId = array();
+    $this->openCiviPage('admin/custom/group/field/add', array('reset' => 1, 'action' => 'add', 'gid' => $customGrpId1));
 
     if ($noteRichEditor) {
       // Create a custom data to add in profile
@@ -237,7 +187,6 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
       $field2 = "Note_Richtexteditor" . substr(sha1(rand()), 0, 7);
 
       // add custom fields for group 1
-      $this->openCiviPage('admin/custom/group/field/add', array('reset' => 1, 'action' => 'add', 'gid' => $customGrpId1));
       $this->type("label", $field1);
       $this->select("data_type_0", "value=4");
       $this->select("data_type_1", "value=TextArea");
@@ -267,21 +216,17 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
       $field3 = "Lname" . substr(sha1(rand()), 0, 7);
 
       // add custom fields for group 1
-      $this->openCiviPage('admin/custom/group/field/add', array('reset' => 1, 'action' => 'add', 'gid' => $customGrpId1));
       $this->type("label", $field1);
       $this->check("is_searchable");
-      $this->click("_qf_Field_next_new-bottom");
-      $this->waitForPageToLoad($this->getTimeoutMsec());
+      $this->clickLink("_qf_Field_next_new-bottom");
 
       $this->type("label", $field2);
       $this->check("is_searchable");
-      $this->click("_qf_Field_next_new-bottom");
-      $this->waitForPageToLoad($this->getTimeoutMsec());
+      $this->clickLink("_qf_Field_next_new-bottom");
 
       $this->type("label", $field3);
       $this->check("is_searchable");
-      $this->click("_qf_Field_done-bottom");
-      $this->waitForPageToLoad($this->getTimeoutMsec());
+      $this->clickLink("_qf_Field_done-bottom");
 
       // get id of custom fields
       $this->openCiviPage("admin/custom/group/field", array('reset' => 1, 'action' => 'browse', 'gid' => $customGrpId1));
@@ -363,26 +308,15 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
 
     $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
 
-    // Try submitting the form without creating or selecting a contact (test for CRM-7971)
-    $this->clickLink("_qf_Case_upload-bottom", "css=span.crm-error");
-
     // Adding contact with randomized first name (so we can then select that contact when creating case)
-    // We're using pop-up New Contact dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $lastName = "Fraser";
-    $contactName = "{$lastName}, {$firstName}";
-    $displayName = "{$firstName} {$lastName}";
-    $email = "{$lastName}.{$firstName}@example.org";
     $custFname = "Mike" . substr(sha1(rand()), 0, 7);
     $custLname = "Krist" . substr(sha1(rand()), 0, 7);
-    $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4, "s2id_client_id");
+    // We're using pop-up New Contact dialog
+    $client = $this->createDialogContact("client_id");
 
     // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
     $caseTypeLabel = "Adult Day Care Referral";
 
-    // activity types we expect for this case type
-    $activityTypes = array("ADC referral", "Follow up", "Medical evaluation", "Mental health evaluation");
-    $caseRoles = array("Senior Services Coordinator", "Health Services Coordinator", "Benefits Specialist", "Client");
     $caseStatusLabel = "Ongoing";
     $subject = "Safe daytime setting - senior female";
     $this->select("medium_id", "value=1");
@@ -406,16 +340,16 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
     $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom");
 
     // Is status message correct?
-    $this->assertTextPresent("Case opened successfully.", "Save successful status message didn't show up after saving!");
+    $this->checkCRMAlert("Case opened successfully.");
     $this->clickLink("_qf_CaseView_cancel-bottom");
 
     $this->openCiviPage('case', 'reset=1');
-    $this->waitForElementPresent("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[8]/a[text()='Open Case']");
+    $this->waitForElementPresent("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[8]/a[text()='Open Case']");
 
-    $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[8]/a[text()='Open Case']");
+    $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[8]/a[text()='Open Case']");
 
     $openCaseData = array(
-      "Client" => $displayName,
+      "Client" => $client['display_name'],
       "Activity Type" => "Open Case",
       "Subject" => $subject,
       "Created By" => "{$testUserFirstName} {$testUserLastName}",
@@ -434,7 +368,7 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase {
 
     // verify if custom data is present
     $this->openCiviPage('case', 'reset=1');
-    $this->clickLink("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']", "css=#{$customGrp1} .crm-accordion-header");
+    $this->clickLink("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[9]/span/a[text()='Manage']", "css=#{$customGrp1} .crm-accordion-header");
 
     $this->click("css=#{$customGrp1} .crm-accordion-header");
 
index 86d5d93bba9d072305e15d8beb7a3561440fdcbc..a6cba882b89cf9a1e95d1bcf19f2619ff661a284 100644 (file)
@@ -37,7 +37,7 @@ class WebTest_Case_CaseDashboardTest extends CiviSeleniumTestCase {
 
   function testAllOrMyCases() {
     // Log in as admin first to verify permissions for CiviCase
-    $this->webtestLogin('true');
+    $this->webtestLogin('admin');
 
     // Enable CiviCase module if necessary
     $this->enableComponents("CiviCase");
@@ -71,14 +71,8 @@ class WebTest_Case_CaseDashboardTest extends CiviSeleniumTestCase {
     //Add case to get drilldown cell on Case dashboard
     $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
 
-    // Adding contact with randomized first name (so we can then select that contact when creating case)
     // We're using pop-up New Contact dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $lastName = "Fraser";
-    $contactName = "{$lastName}, {$firstName}";
-    $displayName = "{$firstName} {$lastName}";
-    $email = "{$lastName}.{$firstName}@example.org";
-    $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4, "s2id_client_id");
+    $this->createDialogContact('client_id');
 
     // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
     $caseTypeLabel = "Adult Day Care Referral";
index e6009b1096fbd743db2f9d3fff9303d34f8124fd..16f37032e3eb7f6a2fd389b4f368651b7a181389 100644 (file)
@@ -376,11 +376,6 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
    *
    */
   function testSearchBuilderfinancialType() {
-    // Logging in. Remember to wait for page to load. In most cases,
-    // you can rely on 30000 as the value that allows your test to pass, however,
-    // sometimes your test might fail because of this. In such cases, it's better to pick one element
-    // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
-    // page contents loaded and you can continue your test execution.
     $this->webtestLogin();
 
     // add financial type
@@ -404,8 +399,7 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
         $financialType = $financialTypeName2;
       }
       // create new contact using dialog
-      $firstName = substr(sha1(rand()), 0, 7);
-      $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
+      $this->createDialogContact();
       $this->select('financial_type_id', $financialType);
       $this->type('total_amount', 100 * $i);
       $this->clickLink('_qf_Contribution_upload_new', '_qf_Contribution_upload_new');
@@ -413,15 +407,14 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     $this->openCiviPage("contact/search/builder", "reset=1", "_qf_Builder_refresh");
 
     $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName1));
-    $this->click('_qf_Builder_refresh');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink('_qf_Builder_refresh');
 
     $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
 
     $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
     $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName2));
-    $this->click('_qf_Builder_refresh');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink('_qf_Builder_refresh');
+
     $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
 
     $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
@@ -429,8 +422,8 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
       $financialTypeName1,
       $financialTypeName2
     ));
-    $this->click('_qf_Builder_refresh');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink('_qf_Builder_refresh');
+
     $this->assertTrue($this->isTextPresent('6 Contacts'), 'Missing text: ' . '6 Contacts');
   }
 
index 89f4ce23c5306846cf6b77bf926cc502dc378c9f..8721b711d77df4038f2b329bac9d9a00f83e12a2 100644 (file)
@@ -242,8 +242,7 @@ class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase {
     $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
 
     // create new contact using dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
+    $this->createDialogContact();
 
     // select financial type
     $this->select('financial_type_id', "label={$financialType}");
@@ -588,8 +587,7 @@ class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase {
     $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
 
     // create new contact using dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
+    $contact = $this->createDialogContact();
 
     // select contribution type
     $this->select('financial_type_id', "label={$financialType}");
@@ -633,7 +631,7 @@ class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase {
 
     // View Contribution Record and test for expected values
     $expected = array(
-      'From' => "{$firstName} Contributor",
+      'From' => $contact['display_name'],
       'Financial Type' => $financialType,
       'Contribution Amount' => 'Contribution Total: $ 590.00',
       'Paid By' => 'Check',
@@ -690,7 +688,6 @@ class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase {
     );
 
     // Retrieve contribution from the DB via api and verify DB values against view contribution page
-    require_once 'api/api.php';
     $fields = $this->webtest_civicrm_api('contribution', 'get', $params);
 
     $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to'];
index fdf129dd8372b17348198ac51e1518a4a5fe3225..c539717886cf0689785f50435008db6f4fd628c3 100644 (file)
@@ -75,8 +75,7 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
     $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
 
     // create new contact using dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $this->webtestNewDialogContact($firstName, "Contributor", $firstName . "@example.com");
+    $contact = $this->createDialogContact();
 
     // select financial type
     $this->select("financial_type_id", "value=1");
@@ -173,7 +172,7 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
 
     // verify soft credit details
     $expected = array(
-      1 => "{$firstName} Contributor",
+      1 => $contact['display_name'],
       2 => 'Donation',
       1 => '100.00',
       6 => 'Completed',
@@ -204,8 +203,7 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
     $this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[2]", "Financial Type IN {$financialType['name']}");
 
     $this->openCiviPage("contact/search/advanced", "reset=1", "_qf_Advanced_refresh-top");
-    $this->click('CiviContribute');
-    $this->waitForElementPresent("financial_type_id");
+    $this->clickAjaxLink('CiviContribute', "financial_type_id");
 
     // select group
     $this->select("financial_type_id", "label={$financialType['name']}");
@@ -222,8 +220,7 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
     $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
 
     // create new contact using dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $this->webtestNewDialogContact($firstName, "Contributor", $firstName . "@example.com");
+    $this->createDialogContact();
 
     // select financial type
     $this->select("financial_type_id", "label={$financialType['name']}");
@@ -256,11 +253,10 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
     $this->webtestFillDate('thankyou_date');
 
     // Clicking save.
-    $this->click("_qf_Contribution_upload");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Contribution_upload");
 
     // Is status message correct?
-    $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!");
+    $this->checkCRMAlert("The contribution record has been saved.");
 
     // verify if Membership is created
     $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
index e5ec62e8f2b0c9702ac5ae7dbb124cfb7baa1263..e3e8b77a8d665120e577cfcd9b501f699ec892f2 100644 (file)
@@ -45,14 +45,12 @@ class WebTest_Contribute_UpdateBatchPendingContributionTest extends CiviSelenium
 
     $this->type("sort_name", "Contributor");
     $this->click('contribution_status_id_2');
-    $this->click("_qf_Search_refresh");
+    $this->clickLink("_qf_Search_refresh");
 
-    $this->waitForPageToLoad($this->getTimeoutMsec());
     $this->click('radio_ts', 'ts_all');
 
     $this->select('task', "label=Update Pending Contribution Status");
-    $this->click("_qf_Search_next_action");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Search_next_action");
     $this->select('contribution_status_id', 'label=Completed');
     $this->click('_qf_Status_next');
     $this->waitForElementPresent("_qf_Result_done");
@@ -191,14 +189,10 @@ class WebTest_Contribute_UpdateBatchPendingContributionTest extends CiviSelenium
   }
 
   function _testOfflineContribution() {
-    $firstName = substr(sha1(rand()), 0, 7);
-    $lastName  = 'Contributor';
-    $email     = $firstName . "@example.com";
-
     $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
 
     // create new contact using dialog
-    $this->webtestNewDialogContact($firstName, "Contributor", $email);
+    $this->createDialogContact();
 
     // select financial type
     $this->select( "financial_type_id", "value=1" );
index 7be86e808d669a5312f0b00febaa45a9ded974e5..244c06c72ca0c06f6dd91c2af17d7607f3f9be97 100755 (executable)
@@ -38,16 +38,13 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
 
  function testChangeContributionAmount() {
    $this->webtestLogin();
-   $firstName = substr(sha1(rand()), 0, 7);
-   $lastName  = 'Contributor';
-   $email     = $firstName . "@example.com";
    $amount = 100;
    //Offline Pay Later Contribution
-   $this->_testOfflineContribution($firstName, $lastName, $email, $amount, "Pending");
+   $contact = $this->_testOfflineContribution($amount, "Pending");
 
    $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
 
-   $this->type("sort_name", "$lastName, $firstName");
+   $this->type("sort_name", $contact['sort_name']);
    $this->click("_qf_Search_refresh");
 
    $this->waitForElementPresent("xpath=//*[@id='Search']//div[@id='contributionSearch']");
@@ -88,20 +85,15 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
 
  function testPayLater() {
    $this->webtestLogin();
-   $firstName = substr(sha1(rand()), 0, 7);
-   $lastName  = 'Contributor';
-   $email     = $firstName . "@example.com";
    $amount = 100.00;
    //Offline Pay Later Contribution
-   $this->_testOfflineContribution($firstName, $lastName, $email, $amount, "Pending");
+   $this->_testOfflineContribution($amount, "Pending");
    $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
-   $contId = explode('&id=', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
-   $contId = explode('&', $contId[1]);
-   $contId = $contId[0];
-   $this->clickLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom', FALSE);
+   $contId = $this->urlArg('id', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
+   $this->clickAjaxLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom');
    $this->select("contribution_status_id", "label=Completed");
-   $this->clickLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", FALSE);
-   $this->waitForText('crm-notification-container', "The contribution record has been saved.");
+   $this->clickAjaxLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
+   $this->checkCRMAlert("The contribution record has been saved.");
 
    //Assertions
    $search = array('id' => $contId);
@@ -119,9 +111,6 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
 
  function testChangePremium() {
    $this->webtestLogin();
-   $firstName = substr(sha1(rand()), 0, 7);
-   $lastName  = 'Contributor';
-   $email     = $firstName . "@example.com";
    $from = 'Premiums';
    $to = 'Premiums inventory';
    $financialType = array(
@@ -161,7 +150,7 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
    $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone");
 
    // create new contact using dialog
-   $this->webtestNewDialogContact($firstName, $lastName, $email);
+   $this->createDialogContact();
    // select financial type
    $this->select( "financial_type_id", "value=1" );
    // total amount
@@ -175,11 +164,9 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
    $this->checkCRMAlert("The contribution record has been saved.");
    // verify if Contribution is created
    //click through to the Contribution edit screen
-   $contId = explode('&id=', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
-   $contId = explode('&', $contId[1]);
-   $contId = $contId[0];
-   $this->clickAjaxLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", "_qf_Contribution_upload-bottom");
-   $this->waitForElementPresent("product_name_0");
+   $contId = $this->urlArg('id', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
+   $this->clickAjaxLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", "product_name_0");
+   
    $this->select('product_name_0', "label=$premiumName2 ( $sku2 )");
    // Clicking save.
    $this->clickAjaxLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[7][text()='$premiumName2']");
@@ -195,9 +182,6 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
 
  function testDeletePremium() {
    $this->webtestLogin();
-   $firstName = substr(sha1(rand()), 0, 7);
-   $lastName  = 'Contributor';
-   $email     = $firstName . "@example.com";
    $from = 'Premiums';
    $to = 'Premiums inventory';
    $financialType = array(
@@ -228,7 +212,7 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
    $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone");
 
    // create new contact using dialog
-   $this->webtestNewDialogContact($firstName, $lastName, $email);
+   $this->createDialogContact();
    // select financial type
    $this->select("financial_type_id", "value=1");
    // total amount
@@ -260,16 +244,13 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
 
  function testChangePaymentInstrument() {
    $this->webtestLogin();
-   $firstName = substr(sha1(rand()), 0, 7);
-   $lastName  = 'Contributor';
-   $email     = $firstName . "@example.com";
    $label = 'TEST'.substr(sha1(rand()), 0, 7);
    $amount = 100.00;
    $financialAccount = CRM_Contribute_PseudoConstant::financialAccount();
    $to = array_search('Accounts Receivable', $financialAccount);
    $from = array_search('Deposit Bank Account', $financialAccount);
    $this->addPaymentInstrument($label, $to);
-   $this->_testOfflineContribution($firstName, $lastName, $email, $amount);
+   $this->_testOfflineContribution($amount);
    $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
    $this->clickLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom', FALSE);
    $contId = explode('&id=', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
@@ -288,12 +269,8 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
 
  function testRefundContribution() {
    $this->webtestLogin();
-   $firstName = substr(sha1(rand()), 0, 7);
-   $lastName  = 'Contributor';
-   $email     = $firstName . "@example.com";
-   $label = 'TEST'.substr(sha1(rand()), 0, 7);
    $amount = 100.00;
-   $this->_testOfflineContribution($firstName, $lastName, $email, $amount);
+   $this->_testOfflineContribution($amount);
    $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
    $this->clickAjaxLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom');
    //Contribution status
@@ -317,12 +294,8 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
 
  function testCancelPayLater() {
    $this->webtestLogin();
-   $firstName = substr(sha1(rand()), 0, 7);
-   $lastName  = 'Contributor';
-   $email     = $firstName . "@example.com";
-   $label = 'TEST'.substr(sha1(rand()), 0, 7);
    $amount = 100.00;
-   $this->_testOfflineContribution($firstName, $lastName, $email, $amount, "Pending");
+   $this->_testOfflineContribution($amount, "Pending");
    $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
    $this->clickLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom', FALSE);
    //Contribution status
@@ -353,12 +326,8 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
 
  function testChangeFinancialType() {
    $this->webtestLogin();
-   $firstName = substr(sha1(rand()), 0, 7);
-   $lastName  = 'Contributor';
-   $email     = $firstName . "@example.com";
-   $label = 'TEST'.substr(sha1(rand()), 0, 7);
    $amount = 100.00;
-   $this->_testOfflineContribution($firstName, $lastName, $email, $amount);
+   $this->_testOfflineContribution($amount);
    $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
    $this->clickLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom', FALSE);
    //Contribution status
@@ -475,18 +444,16 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
  }
 
   /**
-   * @param $firstName
-   * @param $lastName
-   * @param $email
    * @param $amount
    * @param string $status
+   * @return array
    */
-  function _testOfflineContribution($firstName, $lastName, $email, $amount, $status="Completed") {
+  function _testOfflineContribution($amount, $status="Completed") {
 
    $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
 
    // create new contact using dialog
-   $this->webtestNewDialogContact($firstName, $lastName, $email);
+   $contact = $this->createDialogContact();
 
    // select financial type
    $this->select( "financial_type_id", "value=1" );
@@ -511,7 +478,7 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
    $this->clickLink("_qf_Contribution_upload");
 
    // Is status message correct?
-   $this->waitForText('crm-notification-container', "The contribution record has been saved.");
+   $this->checkCRMAlert("The contribution record has been saved.");
 
    $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
    // verify if Membership is created
@@ -526,5 +493,7 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
    );
    $this->webtestVerifyTabularData($expected);
    $this->click("_qf_ContributionView_cancel-bottom");
+
+    return $contact;
  }
 }
index 21b9dccfbe7fb90a944c5b6830a5f2752cdaff56..3560ee2b9068e3019561db1f235b463f92f7ae4d 100644 (file)
@@ -37,18 +37,15 @@ class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestC
 
   function testUpdatePendingContribution() {
     $this->webtestLogin();
-    $firstName = substr(sha1(rand()), 0, 7);
-    $lastName = 'Contributor';
-    $email = $firstName . "@example.com";
 
     //Offline Pay Later Contribution
-    $this->_testOfflineContribution($firstName, $lastName, $email);
+    $contact = $this->_testOfflineContribution();
 
     //Online Pay Later Contribution
-    $this->_testOnlineContribution($firstName, $lastName, $email);
+    $this->_testOnlineContribution($contact);
     $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
 
-    $this->type("sort_name", "$lastName, $firstName");
+    $this->type("sort_name", $contact['sort_name']);
     $this->click("_qf_Search_refresh");
 
     $this->waitForPageToLoad($this->getTimeoutMsec());
@@ -77,11 +74,9 @@ class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestC
   }
 
   /**
-   * @param $firstName
-   * @param $lastName
-   * @param $email
+   * @return array of contact details
    */
-  function _testOfflineContribution($firstName, $lastName, $email) {
+  function _testOfflineContribution() {
     // Create a contact to be used as soft creditor
     $softCreditFname = substr(sha1(rand()), 0, 7);
     $softCreditLname = substr(sha1(rand()), 0, 7);
@@ -90,7 +85,7 @@ class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestC
     $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
 
     // create new contact using dialog
-    $this->webtestNewDialogContact($firstName, "Contributor", $email);
+    $contact = $this->createDialogContact();
 
     // select financial type
     $this->select( "financial_type_id", "value=1" );
@@ -177,19 +172,18 @@ class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestC
       4 => 'Donation',
       2 => '100.00',
       6 => 'Pending',
-      1 => "{$firstName} Contributor",
+      1 => $contact['display_name'],
     );
     foreach ($expected as $value => $label) {
       $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));
     }
+    return $contact;
   }
 
   /**
-   * @param $firstName
-   * @param $lastName
-   * @param $email
+   * @param array $contact
    */
-  function _testOnlineContribution($firstName, $lastName, $email) {
+  function _testOnlineContribution($contact) {
 
     // Use default payment processor
     $processorName = 'Test Processor';
@@ -236,10 +230,10 @@ class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestC
     $this->webtestLogout();
     $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
 
-    $this->type("email-5", $email);
+    $this->type("email-5", $contact['email']);
 
-    $this->type("first_name", $firstName);
-    $this->type("last_name", $lastName);
+    $this->type("first_name", $contact['first_name']);
+    $this->type("last_name", $contact['last_name']);
 
     $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
     $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
@@ -262,12 +256,12 @@ class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestC
     //Find Contribution
     $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
 
-    $this->type("sort_name", "$lastName, $firstName");
+    $this->type("sort_name", $contact['sort_name']);
     $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']");
     $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
     // View Contribution Record and test for expected values
     $expected = array(
-      'From' => "{$firstName} {$lastName}",
+      'From' => $contact['display_name'],
       'Financial Type' => 'Donation',
       'Total Amount' => '100.00',
       'Contribution Status' => 'Pending : Pay Later',
index 1e919e1528a9e074de75b92b44a8cc658f027b5b..71227d0c1ace083119a6b1202d1573433d9b7d17 100644 (file)
@@ -130,8 +130,6 @@ class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase {
   }
 
   function testEventParticipationAddWithMultipleRoles() {
-
-    // Log in using webtestLogin() method
     $this->webtestLogin();
 
     // Adding contact with randomized first name (so we can then select that contact when creating event registration)
@@ -327,47 +325,38 @@ class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase {
   }
 
   function testEventAddMultipleParticipants() {
-
-    // Log in using webtestLogin() method
     $this->webtestLogin();
 
-    $processorId = $this->webtestAddPaymentProcessor('dummy' . substr(sha1(rand()), 0, 7));
-    $rand = substr(sha1(rand()), 0, 7);
-    $firstName = 'First' . $rand;
-    $lastName = 'Last' . $rand;
-    $rand = substr(sha1(rand()), 0, 7);
-    $lastName2 = 'Last' . $rand;
+    $processorId = $this->webtestAddPaymentProcessor();
 
     $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone&mode=test&eid=3");
 
+    $contacts = array();
+
     $this->assertTrue($this->isTextPresent("New Event Registration"), "Page title 'New Event Registration' missing");
     $this->assertTrue($this->isTextPresent("A TEST transaction will be submitted"), "test mode status 'A TEST transaction will be submitted' missing");
-    $this->_fillParticipantDetails($firstName, $lastName, $processorId);
-    $this->click('_qf_Participant_upload_new-bottom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $contacts[] = $this->_fillParticipantDetails($processorId);
+    $this->clickLink('_qf_Participant_upload_new-bottom');
 
     $this->assertTrue($this->isTextPresent("New Event Registration"), "Page title 'New Event Registration' missing");
     $this->assertTrue($this->isTextPresent("A TEST transaction will be submitted"), "test mode status 'A TEST transaction will be submitted' missing");
-    $this->_fillParticipantDetails($firstName, $lastName2, $processorId);
-    $this->click('_qf_Participant_upload_new-bottom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $contacts[] = $this->_fillParticipantDetails($processorId);
+    $this->clickLink('_qf_Participant_upload_new-bottom');
 
     //searching the paricipants
     $this->openCiviPage("event/search", "reset=1");
-    $this->type('sort_name', $firstName);
+    $this->type('sort_name', 'Individual');
     $eventName = "Rain-forest Cup Youth Soccer Tournament";
     $this->select2("event_id", $eventName, FALSE, FALSE);
     $this->check('participant_test');
-    $this->click("_qf_Search_refresh");
-    $this->waitForElementPresent("participantSearch");
+    $this->clickLink("_qf_Search_refresh", "participantSearch");
 
     //verifying the registered participants
-    $names = array( "{$lastName}, {$firstName}", "{$lastName2}, {$firstName}" );
     $status = "Registered (test)";
 
-    foreach($names as $name) {
-      $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$name}']/../../td[9]", preg_quote($status));
-      $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$name}']/../../td[4]/a", preg_quote($eventName));
+    foreach($contacts as $contact) {
+      $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$contact['sort_name']}']/../../td[9]", preg_quote($status));
+      $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$contact['sort_name']}']/../../td[4]/a", preg_quote($eventName));
 }
   }
 
@@ -411,7 +400,7 @@ class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase {
     // Select role.
     $this->multiselect2('role_id', array('Volunteer'));
 
-    foreach($return as $values) {
+    foreach ($return as $values) {
       foreach ($values as $entityType => $customData) {
         //checking for duplicate custom data present or not
         $this->assertElementPresent("xpath=//*[@class='crm-customData-block']/div[@class='custom-group custom-group-{$customData['cgtitle']} crm-accordion-wrapper ']");
@@ -425,8 +414,8 @@ class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase {
    * @param $lastName
    * @param $processorId
    */
-  function _fillParticipantDetails($firstName, $lastName, $processorId) {
-    $this->webtestNewDialogContact($firstName, $lastName);
+  function _fillParticipantDetails($processorId) {
+    $contact = $this->createDialogContact();
 
     $this->select('payment_processor_id', "value={$processorId}");
     $event_id = $this->getAttribute("xpath=//*[@id='event_id']@value");
@@ -435,5 +424,6 @@ class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase {
     $this->select("role_id", "value=1");
     $this->webtestAddCreditCardDetails();
     $this->webtestAddBillingDetails();
+    return $contact;
   }
 }
index e722ef3c4284f16503b50cd528dad03d58b9bd5a..a31208d653fe17c6fbdac0738922b4bbb4f9f934 100644 (file)
@@ -83,9 +83,7 @@ class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
 
     // Create new Grant
     $this->openCiviPage('grant/add', 'reset=1&action=add&context=standalone', '_qf_Grant_upload-bottom');
-    $firstName = 'First' . $rand;
-    $lastName = 'Last' . $rand;
-    $this->webtestNewDialogContact($firstName, $lastName);
+    $contact = $this->createDialogContact();
     $this->select('id=status_id', 'label=Approved for Payment');
     $this->select('id=grant_type_id', "label=$grantType");
     $this->waitForTextPresent($grantField);
@@ -100,7 +98,7 @@ class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
 
     // verify tabular data for grant view
     $this->webtestVerifyTabularData(array(
-      'Name' => "$firstName $lastName",
+      'Name' => $contact['display_name'],
       'Grant Status' => 'Approved',
       'Grant Type' => $grantType,
       $grantField => '$ 99.99',
index 1c0de7fffe3f43f83bdef8c7ad06cd905b53ddf3..a18b265958ed4de8a650606e54293232f4a49914 100644 (file)
@@ -52,8 +52,7 @@ class WebTest_Grant_StandaloneAddTest extends CiviSeleniumTestCase {
     $this->openCiviPage('grant/add', 'reset=1&context=standalone', '_qf_Grant_upload');
 
     // create new contact using dialog
-    $firstName = substr(sha1(rand()), 0, 7);
-    $this->webtestNewDialogContact($firstName, "Grantor", $firstName . "@example.com");
+    $contact = $this->createDialogContact();
 
     // select grant Status
     $this->select("status_id", "value=1");
index efa7b239a715e129aee626af72564dc28c25e336..32e12ec53cc2c7f997cc41ddf5bd1c58a2769b1b 100644 (file)
@@ -41,9 +41,7 @@ class WebTest_Pledge_AddCancelPaymentTest extends CiviSeleniumTestCase {
     $this->openCiviPage('pledge/add', 'reset=1&context=standalone', '_qf_Pledge_upload');
 
     // create new contact using dialog
-    $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
-    $lastName = 'Za' . substr(sha1(rand()), 0, 7);
-    $this->webtestNewDialogContact($firstName, $lastName, $firstName . '@example.com');
+    $contact = $this->createDialogContact();
 
     $this->type('amount', '1200');
     $this->type('installments', '12');
@@ -65,7 +63,7 @@ class WebTest_Pledge_AddCancelPaymentTest extends CiviSeleniumTestCase {
     $pledgeDate = date('F jS, Y', strtotime('now'));
 
     $this->webtestVerifyTabularData(array(
-        'Pledge By' => $firstName . ' ' . $lastName,
+        'Pledge By' => $contact['display_name'],
         'Total Pledge Amount' => '$ 1,200.00',
         'To be paid in' => '12 installments of $ 100.00 every 1 month(s)',
         'Payments are due on the' => '1 day of the period',
index dd16d80a39a16e4e469ca9271f9bc5fa77dff98c..0fc7f3a3cc632e6f60a0edf85bf5448889ea9202 100644 (file)
@@ -41,9 +41,7 @@ class WebTest_Pledge_StandaloneAddDeleteTest extends CiviSeleniumTestCase {
     $this->openCiviPage('pledge/add', 'reset=1&context=standalone', '_qf_Pledge_upload');
 
     // create new contact using dialog
-    $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
-    $lastName = 'Za' . substr(sha1(rand()), 0, 7);
-    $this->webtestNewDialogContact($firstName, $lastName, $firstName . '@example.com');
+    $contact = $this->createDialogContact();
 
     $this->type('amount', '2400');
     $this->type('installments', '10');
@@ -65,7 +63,7 @@ class WebTest_Pledge_StandaloneAddDeleteTest extends CiviSeleniumTestCase {
     $pledgeDate = date('F jS, Y', strtotime('now'));
 
     $this->webtestVerifyTabularData(array(
-        'Pledge By' => $firstName . ' ' . $lastName,
+        'Pledge By' => $contact['display_name'],
         'Total Pledge Amount' => '$ 2,400.00',
         'To be paid in' => '10 installments of $ 240.00 every 1 month(s)',
         'Payments are due on the' => '2 day of the period',
index a2368ec2707d4518a23a927b2d5f6288d52e8c24..68bad2f335ba30d80d53f78ce04036b75f29fe18 100644 (file)
@@ -41,9 +41,7 @@ class WebTest_Pledge_StandaloneAddTest extends CiviSeleniumTestCase {
     $this->openCiviPage('pledge/add', 'reset=1&context=standalone', '_qf_Pledge_upload');
 
     // create new contact using dialog
-    $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
-    $lastName = 'An' . substr(sha1(rand()), 0, 7);
-    $this->webtestNewDialogContact($firstName, $lastName, $firstName . '@example.com');
+    $contact = $this->createDialogContact();
 
     $this->type('amount', '100');
     $this->type('installments', '10');
@@ -75,7 +73,7 @@ class WebTest_Pledge_StandaloneAddTest extends CiviSeleniumTestCase {
     $pledgeDate = date('F jS, Y', strtotime('now'));
 
     $this->webtestVerifyTabularData(array(
-        'Pledge By' => $firstName . ' ' . $lastName,
+        'Pledge By' => $contact['display_name'],
         'Total Pledge Amount' => '$ 100.00',
         'To be paid in' => '10 installments of $ 10.00 every 1 week(s)',
         'Payments are due on the' => '2 day of the period',