3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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';
28 class WebTest_Contribute_AddBatchesTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testBatchAddContribution() {
35 $this->webtestLogin();
40 //Open Live Contribution Page
41 $this->openCiviPage("batch", "reset=1");
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
50 for ($i=1; $i<=$itemCount; $i++
) {
52 'first_name' => 'Ma'.substr(sha1(rand()), 0, 7),
53 'last_name' => 'An'.substr(sha1(rand()), 0, 7),
54 'financial_type' => 'Donation',
58 $this->_fillData($data[$i], $i, "Contribution");
61 $this->click("_qf_Entry_cancel");
62 $this->waitForPageToLoad($this->getTimeoutMsec());
63 $this->_verifyData($data, "Contribution");
66 function testBatchAddMembership() {
67 $this->webtestLogin();
71 $batchTitle = 'Batch-'.substr(sha1(rand()), 0, 7);
73 //Open Live Contribution Page
74 $this->openCiviPage("batch", "reset=1");
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());
85 // Add Contact Details
87 for ($i=1; $i<=$itemCount; $i++
) {
89 'first_name' => 'Ma'.substr(sha1(rand()), 0, 7),
90 'last_name' => 'An'.substr(sha1(rand()), 0, 7),
91 'membership_type' => 'Default Organization',
94 'financial_type' => 'Member Dues',
96 $this->_fillData($data[$i], $i, "Membership");
98 $this->click("_qf_Entry_cancel");
99 $this->waitForPageToLoad($this->getTimeoutMsec());
101 $this->_verifyData($data, "Membership");
104 function _fillData($data, $row, $type) {
105 $email = $data['first_name'] . '@example.com';
106 $this->webtestNewDialogContact($data['first_name'], $data['last_name'], $email, 4, "primary_profiles_{$row}", "primary_{$row}");
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));
119 } elseif ($type == "Membership") {
120 $this->select("field[{$row}][membership_type][0]", $data['membership_type']);
121 $this->webtestFillDate("field_{$row}_join_date", "now");
122 $this->webtestFillDate("field_{$row}_membership_start_date", "now");
123 $this->webtestFillDate("field_{$row}_membership_end_date", "+1 month");
124 $this->type("field_{$row}_membership_source", substr(sha1(rand()), 0, 10));
125 $this->click("field[{$row}][send_receipt]");
126 $this->select("field_{$row}_financial_type", $data['financial_type']);
128 $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week");
129 $this->select("field_{$row}_payment_instrument", "Check");
130 $this->type("field_{$row}_check_number", rand());
131 $this->select("field_{$row}_contribution_status_id", "Completed");
135 function _checkResult($data, $type) {
136 if ($type == "Contribution") {
137 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
138 $this->type("sort_name", "{$data['first_name']} {$data['last_name']}");
139 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
140 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
142 'From' => "{$data['first_name']} {$data['last_name']}",
143 'Financial Type' => $data['financial_type'],
144 'Total Amount' => $data['amount'],
145 'Contribution Status' => 'Completed',
148 $this->webtestVerifyTabularData($expected);
150 elseif ($type == "Membership") {
151 $this->openCiviPage("member/search", "reset=1", "member_join_date_low");
154 $this->type("sort_name", "{$data['first_name']} {$data['last_name']}");
155 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
156 $this->click("xpath=//div[@id='memberSearch']//table/tbody/tr[1]/td[11]/span/a[text()='View']");
157 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
162 foreach ($expected as $label => $value) {
163 $this->verifyText("xpath=id('MembershipView')/div[2]/div/table[1]/tbody/tr[$label]/td[2]", preg_quote($value));
166 $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']");
167 $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']");
168 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
170 'From' => "{$data['first_name']} {$data['last_name']}",
171 'Financial Type' => $data['financial_type'],
172 'Total Amount' => $data['amount'],
173 'Contribution Status' => 'Completed',
176 $this->webtestVerifyTabularData($expected);
180 function _verifyData($data, $type) {
181 $this->waitForElementPresent("xpath=//div[@id='crm-batch-selector_wrapper']//table//tbody/tr[1]/td[7]/span/a[text()='Enter records']");
182 $this->clickLink("xpath=//div[@id='crm-batch-selector_wrapper']//table//tbody/tr[1]/td[7]/span/a[text()='Enter records']", "_qf_Entry_upload");
183 $this->click("_qf_Entry_upload");
184 $this->waitForPageToLoad($this->getTimeoutMsec());
185 foreach ($data as $value) {
186 $this->_checkResult($value, $type);
190 function webtestNewDialogContact($fname = 'Anthony', $lname = 'Anderson', $email = 'anthony@anderson.biz', $type = 4, $row) {
191 // 4 - Individual profile
192 // 5 - Organization profile
193 // 6 - Household profile
194 $this->select("{$row}", "value={$type}");
195 // create new contact using dialog
196 // $this->waitForElementPresent('#first_name');
197 $this->waitForElementPresent('_qf_Edit_next');
201 $this->type('first_name', $fname);
202 $this->type('last_name', $lname);
206 $this->type('organization_name', $fname);
210 $this->type('household_name', $fname);
214 $this->type('email-Primary', $email);
215 $this->click('_qf_Edit_next');
217 // Is new contact created?
218 $this->assertTrue($this->isTextPresent("{$lname}, {$fname} has been created."), "Status message didn't show up after saving!");