3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Contribute_UpdatePendingContributionTest
32 class WebTest_Contribute_UpdatePendingContributionTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testUpdatePendingContribution() {
39 $this->webtestLogin();
41 //Offline Pay Later Contribution
42 $contact = $this->_testOfflineContribution();
44 //Online Pay Later Contribution
45 $this->_testOnlineContribution($contact);
46 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
47 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
48 $this->type("sort_name", $contact['sort_name']);
49 $this->click("_qf_Search_refresh");
51 $this->waitForPageToLoad($this->getTimeoutMsec());
52 $this->click('radio_ts', 'ts_all');
53 $contriIDOff = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr[1]/td[11]/span/a@href"));
54 $contriIDOn = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr[2]/td[11]/span/a@href"));
55 if (!empty($contriIDOff)) {
56 $contriIDOff = substr($contriIDOff[1], (strrpos($contriIDOff[1], '=') +
1));
58 if (!empty($contriIDOn)) {
59 $contriIDOn = substr($contriIDOn[1], (strrpos($contriIDOn[1], '=') +
1));
61 $this->select('task', "label=Update Pending Contribution Status");
62 $this->click("_qf_Search_next_action");
63 $this->waitForPageToLoad($this->getTimeoutMsec());
64 $this->select('contribution_status_id', 'label=Completed');
65 $this->type("trxn_id_{$contriIDOff}", substr(sha1(rand()), 0, 5));
66 $this->type("trxn_id_{$contriIDOn}", substr(sha1(rand()), 0, 5));
67 $this->click('_qf_Status_next');
68 $this->waitForElementPresent("_qf_Result_done");
69 $this->click("_qf_Result_done");
70 $this->waitForPageToLoad($this->getTimeoutMsec());
71 $status = 'Completed';
72 $this->verifyText("xpath=id('contributionSearch')/table[1]/tbody/tr[1]/td[9]", preg_quote($status));
73 $this->verifyText("xpath=id('contributionSearch')/table[1]/tbody/tr[2]/td[9]", preg_quote($status));
78 * Array of contact details
80 public function _testOfflineContribution() {
81 // Create a contact to be used as soft creditor
82 $softCreditFname = substr(sha1(rand()), 0, 7);
83 $softCreditLname = substr(sha1(rand()), 0, 7);
84 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
86 $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
88 // create new contact using dialog
89 $contact = $this->createDialogContact();
91 // select financial type
92 $this->select("financial_type_id", "value=1");
94 // fill in Received Date
95 $this->webtestFillDate('receive_date');
98 $this->select("contribution_status_id", "label=Pending");
101 $this->type("source", "Mailer 1");
104 $this->type("total_amount", "100");
106 // select payment instrument type = Check and enter chk number
107 $this->select("payment_instrument_id", "value=4");
108 $this->waitForElementPresent("check_number");
109 $this->type("check_number", "check #1041");
111 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
114 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_id_1');
115 $this->type("soft_credit_amount_1", "100");
117 //$this->click('CIVICRM_QFID_3_6');
119 //Additional Detail section
120 $this->click("AdditionalDetail");
121 $this->waitForElementPresent("thankyou_date");
123 $this->type("note", "This is a test note.");
124 $this->type("non_deductible_amount", "10");
125 $this->type("fee_amount", "0");
126 $this->type("net_amount", "0");
127 $this->type("invoice_id", time());
128 $this->webtestFillDate('thankyou_date');
131 $this->click("Premium");
132 $this->waitForElementPresent("fulfilled_date");
133 $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )");
134 $this->select("product_name[1]", "label=Black");
135 $this->webtestFillDate('fulfilled_date');
138 $this->click("_qf_Contribution_upload");
139 $this->waitForPageToLoad($this->getTimeoutMsec());
141 // Is status message correct?
142 $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!");
144 // verify if Contribution is created
145 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[2]//tbody/tr[1]/td[8]/span/a[text()='View']");
147 //click through to the Contribution view screen
148 $this->click("xpath=//div[@class='view-content']//table[2]/tbody/tr[1]/td[8]/span/a[text()='View']");
149 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
151 // View Contribution Record and test for expected values
153 'Financial Type' => 'Donation',
154 'Total Amount' => '100.00',
155 'Contribution Status' => 'Pending',
156 'Payment Method' => 'Check',
157 'Check Number' => 'check #1041',
159 $this->webtestVerifyTabularData($expected);
161 // go to soft creditor contact view page - this also does the soft credit check
162 $this->click("xpath=id('ContributionView')/div[2]/div/div[1][contains(text(), 'Soft Credit')]/../div[2]/table[1]/tbody//tr/td[1]/a[contains(text(), '{$softCreditFname} {$softCreditLname}')]");
164 $this->waitForPageToLoad($this->getTimeoutMsec());
165 // go to contribution tab
166 $this->waitForElementPresent("css=li#tab_contribute a");
167 $this->click("css=li#tab_contribute a");
168 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
170 // verify soft credit details
175 1 => $contact['display_name'],
177 foreach ($expected as $value => $label) {
178 $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));
184 * @param array $contact
186 public function _testOnlineContribution($contact) {
188 // Use default payment processor
189 $processorName = 'Test Processor';
190 $processorType = 'Dummy';
191 $pageTitle = substr(sha1(rand()), 0, 7);
192 $rand = 2 * rand(2, 50);
193 $hash = substr(sha1(rand()), 0, 7);
194 $amountSection = TRUE;
199 $memberships = FALSE;
202 $profilePostId = NULL;
206 $memPriceSetId = NULL;
208 // create a new online contribution page
209 // create contribution page with randomized title and default params
210 $pageId = $this->webtestAddContributionPage($hash,
213 array($processorName => $processorType),
230 $this->webtestLogout();
231 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
233 $this->type("email-5", $contact['email']);
235 $this->type("first_name", $contact['first_name']);
236 $this->type("last_name", $contact['last_name']);
238 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
239 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
240 $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']");
241 $streetAddress = "100 Main Street";
242 $this->type("street_address-1", $streetAddress);
243 $this->type("city-1", "San Francisco");
244 $this->type("postal_code-1", "94117");
245 $this->select("country-1", "value=1228");
246 $this->select("state_province-1", "value=1001");
248 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
250 $this->click("_qf_Confirm_next-bottom");
251 $this->waitForPageToLoad($this->getTimeoutMsec());
253 //login to check contribution
254 $this->webtestLogin();
257 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
258 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
259 $this->type("sort_name", $contact['sort_name']);
260 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']");
261 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
262 // View Contribution Record and test for expected values
264 'From' => $contact['display_name'],
265 'Financial Type' => 'Donation',
266 'Total Amount' => '100.00',
267 'Contribution Status' => 'Pending : Pay Later',
269 $this->webtestVerifyTabularData($expected);