Merge pull request #4274 from mrpaulc/CRM-14868
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / AddBatchesTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
25*/
26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contribute_AddBatchesTest
31 */
6a488035
TO
32class WebTest_Contribute_AddBatchesTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testBatchAddContribution() {
6a488035
TO
39 $this->webtestLogin();
40 $itemCount = 5;
41 // create contact
42 $contact = array();
43
44 //Open Live Contribution Page
071a6d2e 45 $this->openCiviPage("batch", "reset=1");
6a488035
TO
46 $this->click("xpath=//div[@class='crm-submit-buttons']/a");
47 $this->waitForElementPresent("_qf_Batch_next");
48 $this->type("item_count", $itemCount);
49 $this->type("total", 500);
50 $this->click("_qf_Batch_next");
51 $this->waitForPageToLoad($this->getTimeoutMsec());
e85b1a9c 52 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
53 $softCreditAmount = array(1 => 50, 2 => 60, 3 => 40, 4 => 70, 5 => 35);
6a488035
TO
54 // Add Contact Details
55 $data = array();
09f61009 56 for ($i = 1; $i <= $itemCount; $i++) {
6a488035 57 $data[$i] = array(
09f61009 58 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7),
59 'last_name' => 'An' . substr(sha1(rand()), 0, 7),
6a488035 60 'financial_type' => 'Donation',
76e86fd8 61 'amount' => 100,
e85b1a9c 62 'soft_credit_first_name' => 'Ar' . substr(sha1(rand()), 0, 7),
63 'soft_credit_last_name' => 'Ki' . substr(sha1(rand()), 0, 7),
64 'soft_credit_amount' => $softCreditAmount[$i],
65 'soft_credit_type' => $softCreditTypes[$i],
76e86fd8 66
6a488035
TO
67 );
68 $this->_fillData($data[$i], $i, "Contribution");
76e86fd8
CW
69 }
70
6a488035
TO
71 $this->click("_qf_Entry_cancel");
72 $this->waitForPageToLoad($this->getTimeoutMsec());
73 $this->_verifyData($data, "Contribution");
74 }
76e86fd8 75
6a488035 76 function testBatchAddMembership() {
6a488035
TO
77 $this->webtestLogin();
78 $itemCount = 5;
e85b1a9c 79 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
80 $softCreditAmount = array(1 => 50, 2 => 60, 3 => 40, 4 => 70, 5 => 35);
6a488035
TO
81 // create contact
82 $contact = array();
09f61009 83 $batchTitle = 'Batch-' . substr(sha1(rand()), 0, 7);
6a488035
TO
84
85 //Open Live Contribution Page
071a6d2e 86 $this->openCiviPage("batch", "reset=1");
6a488035
TO
87 $this->click("xpath=//div[@class='crm-submit-buttons']/a");
88 $this->waitForElementPresent("_qf_Batch_next");
89 $this->click("title");
90 $this->type("title", $batchTitle);
91 $this->select("type_id", "Membership");
92 $this->type("item_count", $itemCount);
93 $this->type("total", 500);
94 $this->click("_qf_Batch_next");
95 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 96
6a488035
TO
97 // Add Contact Details
98 $data = array();
09f61009 99 for ($i = 1; $i <= $itemCount; $i++) {
6a488035 100 $data[$i] = array(
09f61009 101 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7),
102 'last_name' => 'An' . substr(sha1(rand()), 0, 7),
141d3170 103 'membership_type' => 'General',
76e86fd8 104 'amount' => 100,
6a488035 105 'financial_type' => 'Member Dues',
e85b1a9c 106 'soft_credit_first_name' => 'Ar' . substr(sha1(rand()), 0, 7),
107 'soft_credit_last_name' => 'Ki' . substr(sha1(rand()), 0, 7),
108 'soft_credit_amount' => $softCreditAmount[$i],
109 'soft_credit_type' => $softCreditTypes[$i],
6a488035
TO
110 );
111 $this->_fillData($data[$i], $i, "Membership");
112 }
113 $this->click("_qf_Entry_cancel");
76e86fd8
CW
114 $this->waitForPageToLoad($this->getTimeoutMsec());
115
6a488035
TO
116 $this->_verifyData($data, "Membership");
117 }
6a488035 118
4cbe18b8
EM
119 /**
120 * @param $data
121 * @param $row
122 * @param $type
123 */
6a488035
TO
124 function _fillData($data, $row, $type) {
125 $email = $data['first_name'] . '@example.com';
648f9d79 126 $this->webtestNewDialogContact($data['first_name'], $data['last_name'], $email, 4,
e85b1a9c 127 "s2id_primary_contact_id_{$row}", $row, 'primary');
76e86fd8 128
6a488035
TO
129 if ($type == "Contribution") {
130 $this->select("field_{$row}_financial_type", $data['financial_type']);
131 $this->type("field_{$row}_total_amount", $data['amount']);
132 $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week");
133 $this->type("field_{$row}_contribution_source", substr(sha1(rand()), 0, 10));
134 $this->select("field_{$row}_payment_instrument", "Check");
135 $this->type("field_{$row}_check_number", rand());
136 $this->click("field[{$row}][send_receipt]");
137 $this->click("field_{$row}_invoice_id");
138 $this->type("field_{$row}_invoice_id", substr(sha1(rand()), 0, 10));
e85b1a9c 139 $softcreditemail = $data['soft_credit_first_name'] . '@example.com';
140 $this->webtestNewDialogContact($data['soft_credit_first_name'],
141 $data['soft_credit_last_name'],
142 $softcreditemail, 4,
143 "s2id_soft_credit_contact_id_{$row}",
144 $row,
145 'soft_credit'
146 );
147 $this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']);
9e1854a1 148 $this->select("soft_credit_type_{$row}", $data['soft_credit_type']);
76e86fd8 149
09f61009 150 }
151 elseif ($type == "Membership") {
bec97f75 152 $this->select("field[{$row}][membership_type][0]", "value=1");
141d3170 153 $this->select("field[{$row}][membership_type][1]", $data['membership_type']);
6a488035
TO
154 $this->webtestFillDate("field_{$row}_join_date", "now");
155 $this->webtestFillDate("field_{$row}_membership_start_date", "now");
156 $this->webtestFillDate("field_{$row}_membership_end_date", "+1 month");
157 $this->type("field_{$row}_membership_source", substr(sha1(rand()), 0, 10));
158 $this->click("field[{$row}][send_receipt]");
76e86fd8
CW
159 $this->select("field_{$row}_financial_type", $data['financial_type']);
160
6a488035
TO
161 $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week");
162 $this->select("field_{$row}_payment_instrument", "Check");
163 $this->type("field_{$row}_check_number", rand());
164 $this->select("field_{$row}_contribution_status_id", "Completed");
e85b1a9c 165 $softcreditemail = $data['soft_credit_first_name'] . '@example.com';
166 $this->webtestNewDialogContact($data['soft_credit_first_name'],
167 $data['soft_credit_last_name'],
168 $softcreditemail, 4,
169 "s2id_soft_credit_contact_id_{$row}",
170 $row, 'soft_credit'
171 );
172 $this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']);
9e1854a1 173 $this->select("soft_credit_type_{$row}", $data['soft_credit_type']);
6a488035
TO
174 }
175 }
176
4cbe18b8
EM
177 /**
178 * @param $data
179 * @param $type
180 */
6a488035
TO
181 function _checkResult($data, $type) {
182 if ($type == "Contribution") {
42daf119 183 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
6a488035 184 $this->type("sort_name", "{$data['first_name']} {$data['last_name']}");
225a8648 185 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
e85b1a9c 186 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
6a488035 187 $expected = array(
09f61009 188 'From' => "{$data['first_name']} {$data['last_name']}",
189 'Financial Type' => $data['financial_type'],
190 'Total Amount' => $data['amount'],
6a488035 191 'Contribution Status' => 'Completed',
76e86fd8
CW
192 );
193
6a488035 194 $this->webtestVerifyTabularData($expected);
e85b1a9c 195 $expectedSoft = array(
196 'Soft Credit To' => "{$data['soft_credit_first_name']} {$data['soft_credit_last_name']}",
197 'Amount (Soft Credit Type)' => $data['soft_credit_amount'],
198 'Soft Credit Type' => $data['soft_credit_type'],
199 );
200 foreach ($expectedSoft as $value) {
201 $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value));
202 }
6a488035
TO
203 }
204 elseif ($type == "Membership") {
42daf119 205 $this->openCiviPage("member/search", "reset=1", "member_join_date_low");
76e86fd8 206
6a488035
TO
207 // select contact
208 $this->type("sort_name", "{$data['first_name']} {$data['last_name']}");
225a8648 209 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
6a488035
TO
210 $this->click("xpath=//div[@id='memberSearch']//table/tbody/tr[1]/td[11]/span/a[text()='View']");
211 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
212 $expected = array(
213 2 => 'General',
214 4 => 'New'
215 );
216 foreach ($expected as $label => $value) {
217 $this->verifyText("xpath=id('MembershipView')/div[2]/div/table[1]/tbody/tr[$label]/td[2]", preg_quote($value));
218 }
219 //View Contribution
08f17a9f
RK
220 $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/div[2]/div[2]/table/tbody/tr[1]/td[8]/span/a[1][text()='View']");
221 $this->click("xpath=//form[@id='MembershipView']/div[2]/div/div[2]/div[2]/table/tbody/tr[1]/td[8]/span/a[1][text()='View']");
6a488035
TO
222 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
223 $expected = array(
09f61009 224 'From' => "{$data['first_name']} {$data['last_name']}",
225 'Financial Type' => $data['financial_type'],
226 'Total Amount' => $data['amount'],
6a488035 227 'Contribution Status' => 'Completed',
76e86fd8
CW
228 );
229
6a488035 230 $this->webtestVerifyTabularData($expected);
e85b1a9c 231 $expectedSoft = array(
232 'Soft Credit To' => "{$data['soft_credit_first_name']} {$data['soft_credit_last_name']}",
233 'Amount (Soft Credit Type)' => $data['soft_credit_amount'],
9e1854a1 234 'Soft Credit Type' => $data['soft_credit_type'],
e85b1a9c 235 );
236 foreach ($expectedSoft as $value) {
237 $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value));
238 }
6a488035
TO
239 }
240 }
76e86fd8 241
4cbe18b8
EM
242 /**
243 * @param $data
244 * @param $type
245 */
6a488035 246 function _verifyData($data, $type) {
47aea6bb
RK
247 $this->waitForElementPresent("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[7]/span/a[1][text()='Enter records']");
248 $this->click("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[7]/span/a[1][text()='Enter records']");
249 $this->waitForElementPresent('_qf_Entry_upload');
6a488035
TO
250 $this->click("_qf_Entry_upload");
251 $this->waitForPageToLoad($this->getTimeoutMsec());
252 foreach ($data as $value) {
253 $this->_checkResult($value, $type);
254 }
255 }
6a488035 256}