Refactor webtestNewDialogContact and other webtest cleanup
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / UpdatePendingContributionTest.php
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',