Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | class 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(); | |
50 | for ($i=1; $i<=$itemCount; $i++ ) { | |
51 | $data[$i] = array( | |
52 | 'first_name' => 'Ma'.substr(sha1(rand()), 0, 7), | |
53 | 'last_name' => 'An'.substr(sha1(rand()), 0, 7), | |
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(); | |
71 | $batchTitle = 'Batch-'.substr(sha1(rand()), 0, 7); | |
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(); | |
87 | for ($i=1; $i<=$itemCount; $i++ ) { | |
88 | $data[$i] = array( | |
89 | 'first_name' => 'Ma'.substr(sha1(rand()), 0, 7), | |
90 | 'last_name' => 'An'.substr(sha1(rand()), 0, 7), | |
91 | 'membership_type' => 'Default Organization', | |
76e86fd8 CW |
92 | 'amount' => 100, |
93 | ||
6a488035 TO |
94 | 'financial_type' => 'Member Dues', |
95 | ); | |
96 | $this->_fillData($data[$i], $i, "Membership"); | |
97 | } | |
98 | $this->click("_qf_Entry_cancel"); | |
76e86fd8 CW |
99 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
100 | ||
6a488035 TO |
101 | $this->_verifyData($data, "Membership"); |
102 | } | |
6a488035 | 103 | |
6a488035 TO |
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}"); | |
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 | |
6a488035 TO |
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]"); | |
76e86fd8 CW |
126 | $this->select("field_{$row}_financial_type", $data['financial_type']); |
127 | ||
6a488035 TO |
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"); | |
132 | } | |
133 | } | |
134 | ||
135 | function _checkResult($data, $type) { | |
136 | if ($type == "Contribution") { | |
42daf119 | 137 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
6a488035 | 138 | $this->type("sort_name", "{$data['first_name']} {$data['last_name']}"); |
225a8648 CW |
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"); | |
6a488035 TO |
141 | $expected = array( |
142 | 'From' => "{$data['first_name']} {$data['last_name']}", | |
143 | 'Financial Type' => $data['financial_type'], | |
144 | 'Total Amount' => $data['amount'], | |
145 | 'Contribution Status' => 'Completed', | |
76e86fd8 CW |
146 | ); |
147 | ||
6a488035 TO |
148 | $this->webtestVerifyTabularData($expected); |
149 | } | |
150 | elseif ($type == "Membership") { | |
42daf119 | 151 | $this->openCiviPage("member/search", "reset=1", "member_join_date_low"); |
76e86fd8 | 152 | |
6a488035 TO |
153 | // select contact |
154 | $this->type("sort_name", "{$data['first_name']} {$data['last_name']}"); | |
225a8648 | 155 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
6a488035 TO |
156 | $this->click("xpath=//div[@id='memberSearch']//table/tbody/tr[1]/td[11]/span/a[text()='View']"); |
157 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
158 | $expected = array( | |
159 | 2 => 'General', | |
160 | 4 => 'New' | |
161 | ); | |
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)); | |
164 | } | |
165 | //View Contribution | |
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"); | |
169 | $expected = array( | |
170 | 'From' => "{$data['first_name']} {$data['last_name']}", | |
171 | 'Financial Type' => $data['financial_type'], | |
172 | 'Total Amount' => $data['amount'], | |
173 | 'Contribution Status' => 'Completed', | |
76e86fd8 CW |
174 | ); |
175 | ||
6a488035 TO |
176 | $this->webtestVerifyTabularData($expected); |
177 | } | |
178 | } | |
76e86fd8 | 179 | |
6a488035 TO |
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']"); | |
225a8648 | 182 | $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 |
183 | $this->click("_qf_Entry_upload"); |
184 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
185 | foreach ($data as $value) { | |
186 | $this->_checkResult($value, $type); | |
187 | } | |
188 | } | |
189 | ||
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'); | |
198 | ||
199 | switch ($type) { | |
200 | case 4: | |
201 | $this->type('first_name', $fname); | |
202 | $this->type('last_name', $lname); | |
203 | break; | |
76e86fd8 | 204 | |
6a488035 TO |
205 | case 5: |
206 | $this->type('organization_name', $fname); | |
207 | break; | |
76e86fd8 | 208 | |
6a488035 TO |
209 | case 6: |
210 | $this->type('household_name', $fname); | |
211 | break; | |
212 | } | |
213 | ||
214 | $this->type('email-Primary', $email); | |
215 | $this->click('_qf_Edit_next'); | |
216 | ||
217 | // Is new contact created? | |
218 | $this->assertTrue($this->isTextPresent("{$lname}, {$fname} has been created."), "Status message didn't show up after saving!"); | |
219 | } | |
220 | } |