3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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_AddBatchesTest
32 class WebTest_Contribute_AddBatchesTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testBatchAddContribution() {
39 $this->webtestLogin();
44 //Open Live Contribution Page
45 $this->openCiviPage("batch", "reset=1");
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());
52 $softCreditTypes = CRM_Core_OptionGroup
::values("soft_credit_type", FALSE);
53 $softCreditAmount = array(1 => 50, 2 => 60, 3 => 40, 4 => 70, 5 => 35);
54 // Add Contact Details
56 for ($i = 1; $i <= $itemCount; $i++
) {
58 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7),
59 'last_name' => 'An' . substr(sha1(rand()), 0, 7),
60 'financial_type' => 'Donation',
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],
68 $this->_fillData($data[$i], $i, "Contribution");
71 $this->click("_qf_Entry_cancel");
72 $this->waitForPageToLoad($this->getTimeoutMsec());
73 $this->_verifyData($data, "Contribution");
76 function testBatchAddMembership() {
77 $this->webtestLogin();
79 $softCreditTypes = CRM_Core_OptionGroup
::values("soft_credit_type", FALSE);
80 $softCreditAmount = array(1 => 50, 2 => 60, 3 => 40, 4 => 70, 5 => 35);
83 $batchTitle = 'Batch-' . substr(sha1(rand()), 0, 7);
85 //Open Live Contribution Page
86 $this->openCiviPage("batch", "reset=1");
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());
97 // Add Contact Details
99 for ($i = 1; $i <= $itemCount; $i++
) {
101 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7),
102 'last_name' => 'An' . substr(sha1(rand()), 0, 7),
103 'membership_type' => 'General',
105 'financial_type' => 'Member Dues',
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],
111 $this->_fillData($data[$i], $i, "Membership");
113 $this->click("_qf_Entry_cancel");
114 $this->waitForPageToLoad($this->getTimeoutMsec());
116 $this->_verifyData($data, "Membership");
124 function _fillData($data, $row, $type) {
125 $email = $data['first_name'] . '@example.com';
126 $this->webtestNewDialogContact($data['first_name'], $data['last_name'], $email, 4,
127 "s2id_primary_contact_id_{$row}", $row, 'primary');
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));
139 $softcreditemail = $data['soft_credit_first_name'] . '@example.com';
140 $this->webtestNewDialogContact($data['soft_credit_first_name'],
141 $data['soft_credit_last_name'],
143 "s2id_soft_credit_contact_id_{$row}",
147 $this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']);
148 $this->select("field_{$row}_soft_credit_type", $data['soft_credit_type']);
151 elseif ($type == "Membership") {
152 $this->select("field[{$row}][membership_type][0]", "value=1");
153 $this->select("field[{$row}][membership_type][1]", $data['membership_type']);
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]");
159 $this->select("field_{$row}_financial_type", $data['financial_type']);
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");
165 $softcreditemail = $data['soft_credit_first_name'] . '@example.com';
166 $this->webtestNewDialogContact($data['soft_credit_first_name'],
167 $data['soft_credit_last_name'],
169 "s2id_soft_credit_contact_id_{$row}",
172 $this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']);
180 function _checkResult($data, $type) {
181 if ($type == "Contribution") {
182 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
183 $this->type("sort_name", "{$data['first_name']} {$data['last_name']}");
184 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
185 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
187 'From' => "{$data['first_name']} {$data['last_name']}",
188 'Financial Type' => $data['financial_type'],
189 'Total Amount' => $data['amount'],
190 'Contribution Status' => 'Completed',
193 $this->webtestVerifyTabularData($expected);
194 $expectedSoft = array(
195 'Soft Credit To' => "{$data['soft_credit_first_name']} {$data['soft_credit_last_name']}",
196 'Amount (Soft Credit Type)' => $data['soft_credit_amount'],
197 'Soft Credit Type' => $data['soft_credit_type'],
199 foreach ($expectedSoft as $value) {
200 $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value));
203 elseif ($type == "Membership") {
204 $this->openCiviPage("member/search", "reset=1", "member_join_date_low");
207 $this->type("sort_name", "{$data['first_name']} {$data['last_name']}");
208 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
209 $this->click("xpath=//div[@id='memberSearch']//table/tbody/tr[1]/td[11]/span/a[text()='View']");
210 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
215 foreach ($expected as $label => $value) {
216 $this->verifyText("xpath=id('MembershipView')/div[2]/div/table[1]/tbody/tr[$label]/td[2]", preg_quote($value));
219 $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/div[2]/div[2]/table/tbody/tr[1]/td[8]/span/a[1][text()='View']");
220 $this->click("xpath=//form[@id='MembershipView']/div[2]/div/div[2]/div[2]/table/tbody/tr[1]/td[8]/span/a[1][text()='View']");
221 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
223 'From' => "{$data['first_name']} {$data['last_name']}",
224 'Financial Type' => $data['financial_type'],
225 'Total Amount' => $data['amount'],
226 'Contribution Status' => 'Completed',
229 $this->webtestVerifyTabularData($expected);
230 $expectedSoft = array(
231 'Soft Credit To' => "{$data['soft_credit_first_name']} {$data['soft_credit_last_name']}",
232 'Amount (Soft Credit Type)' => $data['soft_credit_amount'],
234 foreach ($expectedSoft as $value) {
235 $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value));
244 function _verifyData($data, $type) {
245 $this->waitForElementPresent("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[7]/span/a[1][text()='Enter records']");
246 $this->click("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[7]/span/a[1][text()='Enter records']");
247 $this->waitForElementPresent('_qf_Entry_upload');
248 $this->click("_qf_Entry_upload");
249 $this->waitForPageToLoad($this->getTimeoutMsec());
250 foreach ($data as $value) {
251 $this->_checkResult($value, $type);