add a few remaining missing comment blocks (autogenerated)
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / OnlineContributionTest.php
index 5c1761ee74546e4d83ecd2e8d624c20f432ef8e3..e187783632dc5eaf4735608cf9649cda444bed32 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -24,7 +24,6 @@
  +--------------------------------------------------------------------+
 */
 
-
 require_once 'CiviTest/CiviSeleniumTestCase.php';
 class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
 
@@ -33,17 +32,7 @@ class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
   }
 
   function testCreateCampaign() {
-    // This is the path where our testing install resides.
-    // The rest of URL is defined in CiviSeleniumTestCase base class, in
-    // class attributes.
-    $this->open($this->sboxPath);
-
-    // 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();
+    $this->webtestLogin('admin');
 
     // Create new group
     $title = substr(sha1(rand()), 0, 7);
@@ -62,7 +51,7 @@ class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
     // add to group
     $this->select("group_id", "label=$groupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent('link=Remove');
 
     $firstName2 = substr(sha1(rand()), 0, 7);
     $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
@@ -75,12 +64,12 @@ class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
     // add to group
     $this->select("group_id", "label=$groupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent('link=Remove');
 
     // Enable CiviCampaign module if necessary
     $this->enableComponents(array('CiviCampaign'));
 
-    // add the required Drupal permission
+    // add the required permission
     $permissions = array(
       'edit-2-administer-civicampaign',
       'edit-1-make-online-contributions',
@@ -88,10 +77,10 @@ class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
     );
     $this->changePermissions($permissions);
 
-    // Go directly to the URL of the screen that you will be testing
+    // Log in as normal user
+    $this->webtestLogin();
     $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
 
-    // Let's start filling the form with values.
     $campaignTitle = "Campaign $title";
     $this->type("title", $campaignTitle);
 
@@ -116,16 +105,18 @@ class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
     $this->click("_qf_Campaign_upload-bottom");
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
-    $this->assertElementContainsText('crm-notification-container', "Campaign Campaign $title has been saved.",
-      "Status message didn't show up after saving campaign!"
-    );
+    $this->waitForText('crm-notification-container', "Campaign $title");
 
-    $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
-    $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
+    $this->waitForElementPresent("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
+    $id = (int) $this->getText("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
 
     $this->onlineContributionAddTest($campaignTitle, $id);
   }
 
+  /**
+   * @param $campaignTitle
+   * @param $id
+   */
   function onlineContributionAddTest($campaignTitle, $id) {
     // We need a payment processor
     $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
@@ -148,9 +139,11 @@ class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
     $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
     $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
 
-    // go to step 2
-    $this->click('_qf_Settings_next');
-    $this->waitForElementPresent("_qf_Amount_next-bottom");
+    // Submit form
+    $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
+
+    // Get contribution page id
+    $pageId = $this->urlArg('id');
 
     //this contribution page for online contribution
     $this->check("payment_processor[{$paymentProcessorId}]");
@@ -159,7 +152,7 @@ class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
     $this->type("value_1", "100");
     $this->type("label_2", "amount 2");
     $this->type("value_2", "200");
-    $this->click("CIVICRM_QFID_1_2");
+    $this->click("xpath=//*[@id='map-field-table']//tr[2]//input[1][@name='default']");
 
     $this->click("_qf_Amount_next-bottom");
     $this->waitForPageToLoad($this->getTimeoutMsec());
@@ -200,7 +193,7 @@ class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
     $this->waitForElementPresent("_qf_Custom_next-bottom");
 
     // fill in step 6 (Include Profiles)
-    $this->select('custom_pre_id', 'value=1');
+    $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_pre_id span.crm-profile-selector-select select', 'value=1');
 
     $this->click('_qf_Custom_next-bottom');
     $this->waitForPageToLoad($this->getTimeoutMsec());
@@ -250,22 +243,26 @@ class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
     $this->click('_qf_Contribute_next-bottom');
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
-    //get Url for Live Contribution Page
-    $registerUrl = $this->_testVerifyRegisterPage($contributionPageTitle);
+    // Make sure our page shows up in search results
+    $this->openCiviPage("admin/contribute", "reset=1", "_qf_SearchContribution_refresh");
+    $this->type('title', $contributionPageTitle);
+    $this->click("_qf_SearchContribution_refresh");
+    $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
+    $url = $this->assertElementContainsText("//div[@id='configure_contribution_page']//table/tbody", $contributionPageTitle);
 
     //logout
-    $this->openCiviPage("logout", "reset=1");
+    $this->webtestLogout();
 
     //Open Live Contribution Page
-    $this->openCiviPage($registerUrl['url'], $registerUrl['args']);
+    $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
+
     $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
     $lastName = 'An' . substr(sha1(rand()), 0, 7);
-
-    $this->type("email-5", $firstName . "@example.com");
-
     $this->type("first_name", $firstName);
     $this->type("last_name", $lastName);
 
+    $this->type("email-5", $firstName . "@example.com");
+
     $streetAddress = "100 Main Street";
     $this->type("street_address-1", $streetAddress);
     $this->type("city-1", "San Francisco");
@@ -288,45 +285,22 @@ class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
     $this->select("billing_country_id-5", "value=1228");
     $this->select("billing_state_province_id-5", "value=1004");
     $this->type("billing_postal_code-5", "94129");
-    $this->click("_qf_Main_upload-bottom");
+    $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
 
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->waitForElementPresent("_qf_Confirm_next-bottom");
-
-    $this->click("_qf_Confirm_next-bottom");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Confirm_next-bottom", NULL);
 
     //login to check contribution
-    $this->open($this->sboxPath);
-
-    // Log in using webtestLogin() method
     $this->webtestLogin();
 
     //Find Contribution
     $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
 
     $this->type("sort_name", "$firstName $lastName");
-    $this->click("_qf_Search_refresh");
-
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-
-    $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
-    $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
+    $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
+    $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
 
     //View Contribution Record
     $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[10]/td[2]", preg_quote($campaignTitle));
   }
 
-  function _testVerifyRegisterPage($contributionPageTitle) {
-    $this->openCiviPage("admin/contribute", "reset=1", "_qf_SearchContribution_refresh");
-    $this->type('title', $contributionPageTitle);
-    $this->click("_qf_SearchContribution_refresh");
-    $this->waitForPageToLoad('50000');
-    $id          = $this->getAttribute("//div[@id='configure_contribution_page']//table/tbody/tr/td/strong[text()='$contributionPageTitle']/../../td[5]/div/span/ul/li/a[text()='Title and Settings']@href");
-    $id          = explode('id=', $id);
-    $registerUrl = array('url' => 'contribute/transact', 'args' => "reset=1&id=$id[1]");
-    return $registerUrl;
-  }
 }