From 80f3b91d38485d41399ab6fab7fa9c08bb6a701e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 19 Sep 2014 23:45:24 -0400 Subject: [PATCH] Refactor webtestNewDialogContact and other webtest cleanup --- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 35 +++++ .../WebTest/Case/ActivityToCaseTest.php | 52 +++---- tests/phpunit/WebTest/Case/AddCaseTest.php | 31 ++--- .../phpunit/WebTest/Case/AddCaseTypeTest.php | 7 +- .../WebTest/Case/CaseCustomFieldsTest.php | 128 +++++------------- .../WebTest/Case/CaseDashboardTest.php | 10 +- .../WebTest/Contact/SearchBuilderTest.php | 19 +-- .../WebTest/Contribute/AddPricesetTest.php | 9 +- .../WebTest/Contribute/StandaloneAddTest.php | 16 +-- .../UpdateBatchPendingContributionTest.php | 12 +- .../Contribute/UpdateContributionTest.php | 75 +++------- .../UpdatePendingContributionTest.php | 36 ++--- .../WebTest/Event/AddParticipationTest.php | 42 +++--- .../WebTest/Grant/CustomFieldsetTest.php | 6 +- .../WebTest/Grant/StandaloneAddTest.php | 3 +- .../WebTest/Pledge/AddCancelPaymentTest.php | 6 +- .../Pledge/StandaloneAddDeleteTest.php | 6 +- .../WebTest/Pledge/StandaloneAddTest.php | 6 +- 18 files changed, 179 insertions(+), 320 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index 77914c31f0..d6cbb6447d 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -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 = '') { diff --git a/tests/phpunit/WebTest/Case/ActivityToCaseTest.php b/tests/phpunit/WebTest/Case/ActivityToCaseTest.php index 37e15b1b0c..dc6b106d76 100644 --- a/tests/phpunit/WebTest/Case/ActivityToCaseTest.php +++ b/tests/phpunit/WebTest/Case/ActivityToCaseTest.php @@ -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, diff --git a/tests/phpunit/WebTest/Case/AddCaseTest.php b/tests/phpunit/WebTest/Case/AddCaseTest.php index bab7a97ec2..6198e25f6f 100644 --- a/tests/phpunit/WebTest/Case/AddCaseTest.php +++ b/tests/phpunit/WebTest/Case/AddCaseTest.php @@ -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"); } } diff --git a/tests/phpunit/WebTest/Case/AddCaseTypeTest.php b/tests/phpunit/WebTest/Case/AddCaseTypeTest.php index dda1b0c47d..51e01932cb 100644 --- a/tests/phpunit/WebTest/Case/AddCaseTypeTest.php +++ b/tests/phpunit/WebTest/Case/AddCaseTypeTest.php @@ -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"; diff --git a/tests/phpunit/WebTest/Case/CaseCustomFieldsTest.php b/tests/phpunit/WebTest/Case/CaseCustomFieldsTest.php index 71c68e7bb9..e454dfa94e 100644 --- a/tests/phpunit/WebTest/Case/CaseCustomFieldsTest.php +++ b/tests/phpunit/WebTest/Case/CaseCustomFieldsTest.php @@ -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"); diff --git a/tests/phpunit/WebTest/Case/CaseDashboardTest.php b/tests/phpunit/WebTest/Case/CaseDashboardTest.php index 86d5d93bba..a6cba882b8 100644 --- a/tests/phpunit/WebTest/Case/CaseDashboardTest.php +++ b/tests/phpunit/WebTest/Case/CaseDashboardTest.php @@ -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"; diff --git a/tests/phpunit/WebTest/Contact/SearchBuilderTest.php b/tests/phpunit/WebTest/Contact/SearchBuilderTest.php index e6009b1096..16f37032e3 100644 --- a/tests/phpunit/WebTest/Contact/SearchBuilderTest.php +++ b/tests/phpunit/WebTest/Contact/SearchBuilderTest.php @@ -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'); } diff --git a/tests/phpunit/WebTest/Contribute/AddPricesetTest.php b/tests/phpunit/WebTest/Contribute/AddPricesetTest.php index 89f4ce23c5..8721b711d7 100644 --- a/tests/phpunit/WebTest/Contribute/AddPricesetTest.php +++ b/tests/phpunit/WebTest/Contribute/AddPricesetTest.php @@ -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']; diff --git a/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php b/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php index fdf129dd83..c539717886 100644 --- a/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php +++ b/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php @@ -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']"); diff --git a/tests/phpunit/WebTest/Contribute/UpdateBatchPendingContributionTest.php b/tests/phpunit/WebTest/Contribute/UpdateBatchPendingContributionTest.php index e5ec62e8f2..e3e8b77a8d 100644 --- a/tests/phpunit/WebTest/Contribute/UpdateBatchPendingContributionTest.php +++ b/tests/phpunit/WebTest/Contribute/UpdateBatchPendingContributionTest.php @@ -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" ); diff --git a/tests/phpunit/WebTest/Contribute/UpdateContributionTest.php b/tests/phpunit/WebTest/Contribute/UpdateContributionTest.php index 7be86e808d..244c06c72c 100755 --- a/tests/phpunit/WebTest/Contribute/UpdateContributionTest.php +++ b/tests/phpunit/WebTest/Contribute/UpdateContributionTest.php @@ -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; } } diff --git a/tests/phpunit/WebTest/Contribute/UpdatePendingContributionTest.php b/tests/phpunit/WebTest/Contribute/UpdatePendingContributionTest.php index 21b9dccfbe..3560ee2b90 100644 --- a/tests/phpunit/WebTest/Contribute/UpdatePendingContributionTest.php +++ b/tests/phpunit/WebTest/Contribute/UpdatePendingContributionTest.php @@ -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', diff --git a/tests/phpunit/WebTest/Event/AddParticipationTest.php b/tests/phpunit/WebTest/Event/AddParticipationTest.php index 1e919e1528..71227d0c1a 100644 --- a/tests/phpunit/WebTest/Event/AddParticipationTest.php +++ b/tests/phpunit/WebTest/Event/AddParticipationTest.php @@ -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; } } diff --git a/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php b/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php index e722ef3c42..a31208d653 100644 --- a/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php +++ b/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php @@ -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', diff --git a/tests/phpunit/WebTest/Grant/StandaloneAddTest.php b/tests/phpunit/WebTest/Grant/StandaloneAddTest.php index 1c0de7fffe..a18b265958 100644 --- a/tests/phpunit/WebTest/Grant/StandaloneAddTest.php +++ b/tests/phpunit/WebTest/Grant/StandaloneAddTest.php @@ -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"); diff --git a/tests/phpunit/WebTest/Pledge/AddCancelPaymentTest.php b/tests/phpunit/WebTest/Pledge/AddCancelPaymentTest.php index efa7b239a7..32e12ec53c 100644 --- a/tests/phpunit/WebTest/Pledge/AddCancelPaymentTest.php +++ b/tests/phpunit/WebTest/Pledge/AddCancelPaymentTest.php @@ -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', diff --git a/tests/phpunit/WebTest/Pledge/StandaloneAddDeleteTest.php b/tests/phpunit/WebTest/Pledge/StandaloneAddDeleteTest.php index dd16d80a39..0fc7f3a3cc 100644 --- a/tests/phpunit/WebTest/Pledge/StandaloneAddDeleteTest.php +++ b/tests/phpunit/WebTest/Pledge/StandaloneAddDeleteTest.php @@ -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', diff --git a/tests/phpunit/WebTest/Pledge/StandaloneAddTest.php b/tests/phpunit/WebTest/Pledge/StandaloneAddTest.php index a2368ec270..68bad2f335 100644 --- a/tests/phpunit/WebTest/Pledge/StandaloneAddTest.php +++ b/tests/phpunit/WebTest/Pledge/StandaloneAddTest.php @@ -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', -- 2.25.1