Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-07-15-32-51
[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
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Contribute_AddBatchesTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testBatchAddContribution() {
6a488035
TO
35 $this->webtestLogin();
36 $itemCount = 5;
37 // create contact
38 $contact = array();
39
40 //Open Live Contribution Page
071a6d2e 41 $this->openCiviPage("batch", "reset=1");
6a488035
TO
42 $this->click("xpath=//div[@class='crm-submit-buttons']/a");
43 $this->waitForElementPresent("_qf_Batch_next");
44 $this->type("item_count", $itemCount);
45 $this->type("total", 500);
46 $this->click("_qf_Batch_next");
47 $this->waitForPageToLoad($this->getTimeoutMsec());
48 // Add Contact Details
49 $data = array();
09f61009 50 for ($i = 1; $i <= $itemCount; $i++) {
6a488035 51 $data[$i] = array(
09f61009 52 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7),
53 'last_name' => 'An' . substr(sha1(rand()), 0, 7),
6a488035 54 'financial_type' => 'Donation',
76e86fd8
CW
55 'amount' => 100,
56
6a488035
TO
57 );
58 $this->_fillData($data[$i], $i, "Contribution");
76e86fd8
CW
59 }
60
6a488035
TO
61 $this->click("_qf_Entry_cancel");
62 $this->waitForPageToLoad($this->getTimeoutMsec());
63 $this->_verifyData($data, "Contribution");
64 }
76e86fd8 65
6a488035 66 function testBatchAddMembership() {
6a488035
TO
67 $this->webtestLogin();
68 $itemCount = 5;
69 // create contact
70 $contact = array();
09f61009 71 $batchTitle = 'Batch-' . substr(sha1(rand()), 0, 7);
6a488035
TO
72
73 //Open Live Contribution Page
071a6d2e 74 $this->openCiviPage("batch", "reset=1");
6a488035
TO
75 $this->click("xpath=//div[@class='crm-submit-buttons']/a");
76 $this->waitForElementPresent("_qf_Batch_next");
77 $this->click("title");
78 $this->type("title", $batchTitle);
79 $this->select("type_id", "Membership");
80 $this->type("item_count", $itemCount);
81 $this->type("total", 500);
82 $this->click("_qf_Batch_next");
83 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 84
6a488035
TO
85 // Add Contact Details
86 $data = array();
09f61009 87 for ($i = 1; $i <= $itemCount; $i++) {
6a488035 88 $data[$i] = array(
09f61009 89 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7),
90 'last_name' => 'An' . substr(sha1(rand()), 0, 7),
141d3170 91 'membership_type' => 'General',
76e86fd8 92 'amount' => 100,
6a488035
TO
93 'financial_type' => 'Member Dues',
94 );
95 $this->_fillData($data[$i], $i, "Membership");
96 }
97 $this->click("_qf_Entry_cancel");
76e86fd8
CW
98 $this->waitForPageToLoad($this->getTimeoutMsec());
99
6a488035
TO
100 $this->_verifyData($data, "Membership");
101 }
6a488035 102
6a488035
TO
103 function _fillData($data, $row, $type) {
104 $email = $data['first_name'] . '@example.com';
648f9d79 105 $this->webtestNewDialogContact($data['first_name'], $data['last_name'], $email, 4,
106 "primary_profiles_{$row}", $row, 'primary');
76e86fd8 107
6a488035
TO
108 if ($type == "Contribution") {
109 $this->select("field_{$row}_financial_type", $data['financial_type']);
110 $this->type("field_{$row}_total_amount", $data['amount']);
111 $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week");
112 $this->type("field_{$row}_contribution_source", substr(sha1(rand()), 0, 10));
113 $this->select("field_{$row}_payment_instrument", "Check");
114 $this->type("field_{$row}_check_number", rand());
115 $this->click("field[{$row}][send_receipt]");
116 $this->click("field_{$row}_invoice_id");
117 $this->type("field_{$row}_invoice_id", substr(sha1(rand()), 0, 10));
76e86fd8 118
09f61009 119 }
120 elseif ($type == "Membership") {
bec97f75 121 $this->select("field[{$row}][membership_type][0]", "value=1");
141d3170 122 $this->select("field[{$row}][membership_type][1]", $data['membership_type']);
6a488035
TO
123 $this->webtestFillDate("field_{$row}_join_date", "now");
124 $this->webtestFillDate("field_{$row}_membership_start_date", "now");
125 $this->webtestFillDate("field_{$row}_membership_end_date", "+1 month");
126 $this->type("field_{$row}_membership_source", substr(sha1(rand()), 0, 10));
127 $this->click("field[{$row}][send_receipt]");
76e86fd8
CW
128 $this->select("field_{$row}_financial_type", $data['financial_type']);
129
6a488035
TO
130 $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week");
131 $this->select("field_{$row}_payment_instrument", "Check");
132 $this->type("field_{$row}_check_number", rand());
133 $this->select("field_{$row}_contribution_status_id", "Completed");
134 }
135 }
136
137 function _checkResult($data, $type) {
138 if ($type == "Contribution") {
42daf119 139 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
6a488035 140 $this->type("sort_name", "{$data['first_name']} {$data['last_name']}");
225a8648
CW
141 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
142 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
6a488035 143 $expected = array(
09f61009 144 'From' => "{$data['first_name']} {$data['last_name']}",
145 'Financial Type' => $data['financial_type'],
146 'Total Amount' => $data['amount'],
6a488035 147 'Contribution Status' => 'Completed',
76e86fd8
CW
148 );
149
6a488035
TO
150 $this->webtestVerifyTabularData($expected);
151 }
152 elseif ($type == "Membership") {
42daf119 153 $this->openCiviPage("member/search", "reset=1", "member_join_date_low");
76e86fd8 154
6a488035
TO
155 // select contact
156 $this->type("sort_name", "{$data['first_name']} {$data['last_name']}");
225a8648 157 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
6a488035
TO
158 $this->click("xpath=//div[@id='memberSearch']//table/tbody/tr[1]/td[11]/span/a[text()='View']");
159 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
160 $expected = array(
161 2 => 'General',
162 4 => 'New'
163 );
164 foreach ($expected as $label => $value) {
165 $this->verifyText("xpath=id('MembershipView')/div[2]/div/table[1]/tbody/tr[$label]/td[2]", preg_quote($value));
166 }
167 //View Contribution
168 $this->waitForElementPresent("xpath=//div[@class='crm-block crm-content-block crm-membership-view-form-block']/table[2]/tbody/tr[1]/td[8]/span/a[text()='View']");
169 $this->click("xpath=//div[@class='crm-block crm-content-block crm-membership-view-form-block']/table[2]/tbody/tr[1]/td[8]/span/a[text()='View']");
170 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
171 $expected = array(
09f61009 172 'From' => "{$data['first_name']} {$data['last_name']}",
173 'Financial Type' => $data['financial_type'],
174 'Total Amount' => $data['amount'],
6a488035 175 'Contribution Status' => 'Completed',
76e86fd8
CW
176 );
177
6a488035
TO
178 $this->webtestVerifyTabularData($expected);
179 }
180 }
76e86fd8 181
6a488035
TO
182 function _verifyData($data, $type) {
183 $this->waitForElementPresent("xpath=//div[@id='crm-batch-selector_wrapper']//table//tbody/tr[1]/td[7]/span/a[text()='Enter records']");
225a8648 184 $this->clickLink("xpath=//div[@id='crm-batch-selector_wrapper']//table//tbody/tr[1]/td[7]/span/a[text()='Enter records']", "_qf_Entry_upload");
6a488035
TO
185 $this->click("_qf_Entry_upload");
186 $this->waitForPageToLoad($this->getTimeoutMsec());
187 foreach ($data as $value) {
188 $this->_checkResult($value, $type);
189 }
190 }
6a488035 191}