Commit | Line | Data |
---|---|---|
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 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contribute_AddPricesetTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
76e86fd8 | 37 | |
6a488035 | 38 | function testAddPriceSet() { |
6a488035 TO |
39 | // Log in using webtestLogin() method |
40 | $this->webtestLogin(); | |
41 | ||
42 | //add financial type of account type expense | |
76e86fd8 | 43 | |
6a488035 TO |
44 | $financialType = $this->_testAddFinancialType(); |
45 | ||
46 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); | |
42daf119 CW |
47 | $usedFor = 'Contribution'; |
48 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
49 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); |
50 | ||
51 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
52 | // which is where we are after adding Price Set. | |
a471a3b6 | 53 | $sid = $this->urlArg('sid'); |
6a488035 TO |
54 | $this->assertType('numeric', $sid); |
55 | ||
56 | $validStrings = array(); | |
57 | ||
58 | $fields = array( | |
59 | 'Full Conference' => 'Text', | |
60 | 'Meal Choice' => 'Select', | |
61 | 'Pre-conference Meetup?' => 'Radio', | |
62 | 'Evening Sessions' => 'CheckBox', | |
63 | ); | |
d1c1ddc7 | 64 | $this->_testAddPriceFields($fields, $validateStrings, $financialType); |
6a488035 TO |
65 | // var_dump($validateStrings); |
66 | ||
67 | // load the Price Set Preview and check for expected values | |
68 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
69 | } | |
70 | ||
4cbe18b8 EM |
71 | /** |
72 | * @param $setTitle | |
73 | * @param $usedFor | |
74 | * @param $setHelp | |
75 | * @param null $financialType | |
76 | */ | |
6a488035 | 77 | function _testAddSet($setTitle, $usedFor, $setHelp, $financialType = NULL) { |
42daf119 | 78 | $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom'); |
6a488035 TO |
79 | |
80 | // Enter Priceset fields (Title, Used For ...) | |
81 | $this->type('title', $setTitle); | |
82 | if ($usedFor == 'Event') { | |
83 | $this->check('extends_1'); | |
84 | } | |
85 | elseif ($usedFor == 'Contribution') { | |
86 | $this->check('extends_2'); | |
87 | } | |
88 | ||
89 | if ($financialType) { | |
6d5f1345 | 90 | $this->select("financial_type_id", "label={$financialType}"); |
6a488035 TO |
91 | } |
92 | $this->type('help_pre', $setHelp); | |
93 | ||
94 | $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); | |
ba6f320f | 95 | $this->clickLink('_qf_Set_next-bottom', 'newPriceField'); |
6a488035 TO |
96 | } |
97 | ||
4cbe18b8 EM |
98 | /** |
99 | * @param $fields | |
100 | * @param $validateString | |
101 | * @param $financialType | |
102 | * @param bool $dateSpecificFields | |
103 | */ | |
6a488035 TO |
104 | function _testAddPriceFields(&$fields, &$validateString, $financialType, $dateSpecificFields = FALSE) { |
105 | $validateStrings[] = $financialType; | |
ba6f320f JP |
106 | $this->click('newPriceField'); |
107 | $this->waitForElementPresent('label'); | |
6a488035 TO |
108 | foreach ($fields as $label => $type) { |
109 | $validateStrings[] = $label; | |
76e86fd8 | 110 | |
6a488035 TO |
111 | $this->type('label', $label); |
112 | $this->select('html_type', "value={$type}"); | |
113 | ||
114 | switch ($type) { | |
d1c1ddc7 | 115 | case 'Text': |
116 | $validateStrings[] = '525.00'; | |
117 | $this->type('price', '525.00'); | |
118 | if ($dateSpecificFields == TRUE) { | |
119 | $this->webtestFillDateTime('active_on', '+1 week'); | |
120 | } | |
121 | else { | |
122 | $this->check('is_required'); | |
123 | } | |
124 | break; | |
125 | ||
126 | case 'Select': | |
127 | $options = array( | |
128 | 1 => array( | |
129 | 'label' => 'Chicken', | |
130 | 'amount' => '30.00', | |
131 | ), | |
132 | 2 => array( | |
133 | 'label' => 'Vegetarian', | |
134 | 'amount' => '25.00', | |
135 | ), | |
136 | ); | |
137 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
138 | if ($dateSpecificFields == TRUE) { | |
139 | $this->webtestFillDateTime('expire_on', '-1 week'); | |
140 | } | |
141 | break; | |
142 | ||
143 | case 'Radio': | |
144 | $options = array( | |
145 | 1 => array( | |
146 | 'label' => 'Yes', | |
147 | 'amount' => '50.00', | |
148 | ), | |
149 | 2 => array( | |
150 | 'label' => 'No', | |
151 | 'amount' => '0', | |
152 | ), | |
153 | ); | |
154 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
6a488035 | 155 | $this->check('is_required'); |
d1c1ddc7 | 156 | if ($dateSpecificFields == TRUE) { |
157 | $this->webtestFillDateTime('active_on', '-1 week'); | |
158 | } | |
159 | break; | |
160 | ||
161 | case 'CheckBox': | |
162 | $options = array( | |
163 | 1 => array( | |
164 | 'label' => 'First Night', | |
165 | 'amount' => '15.00', | |
166 | ), | |
167 | 2 => array( | |
168 | 'label' => 'Second Night', | |
169 | 'amount' => '15.00', | |
170 | ), | |
171 | ); | |
172 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
173 | if ($dateSpecificFields == TRUE) { | |
174 | $this->webtestFillDateTime('expire_on', '+1 week'); | |
175 | } | |
176 | break; | |
177 | ||
178 | default: | |
179 | break; | |
6a488035 TO |
180 | } |
181 | $this->select('financial_type_id', "label={$financialType}"); | |
ba6f320f JP |
182 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE); |
183 | $this->waitForText('crm-notification-container', "Price Field '$label' has been saved."); | |
6a488035 TO |
184 | } |
185 | } | |
76e86fd8 | 186 | |
4cbe18b8 EM |
187 | /** |
188 | * @return string | |
189 | */ | |
6a488035 | 190 | function _testAddFinancialType() { |
6a488035 | 191 | //Add new Financial Type |
d1c1ddc7 | 192 | $financialType['name'] = 'FinancialType ' . substr(sha1(rand()), 0, 4); |
6a488035 TO |
193 | $financialType['is_deductible'] = TRUE; |
194 | $financialType['is_reserved'] = FALSE; | |
195 | $this->addeditFinancialType($financialType); | |
6a488035 TO |
196 | return $financialType['name']; |
197 | } | |
76e86fd8 | 198 | |
4cbe18b8 EM |
199 | /** |
200 | * @param $validateStrings | |
201 | * @param $sid | |
202 | */ | |
6a488035 TO |
203 | function _testVerifyPriceSet($validateStrings, $sid) { |
204 | // verify Price Set at Preview page | |
205 | // start at Manage Price Sets listing | |
071a6d2e | 206 | $this->openCiviPage("admin/price", "reset=1"); |
6a488035 TO |
207 | |
208 | // Use the price set id ($sid) to pick the correct row | |
c1d1bf14 | 209 | $this->clickLink("//*[@id='price_set-{$sid}']/td[4]/span[1]/a[1]", 'Link=Add Price Field'); |
6a488035 TO |
210 | // Check for expected price set field strings |
211 | $this->assertStringsPresent($validateStrings); | |
212 | } | |
213 | ||
214 | function testContributeOfflineWithPriceSet() { | |
6a488035 TO |
215 | // Log in using webtestLogin() method |
216 | $this->webtestLogin(); | |
217 | ||
218 | //add financial type of account type expense | |
219 | $financialType = $this->_testAddFinancialType(); | |
76e86fd8 | 220 | |
6a488035 | 221 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
222 | $usedFor = 'Contribution'; |
223 | $setHelp = 'Select your conference options.'; | |
6a488035 | 224 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); |
76e86fd8 | 225 | |
6a488035 TO |
226 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form |
227 | // which is where we are after adding Price Set. | |
a471a3b6 | 228 | $sid = $this->urlArg('sid'); |
6a488035 TO |
229 | $this->assertType('numeric', $sid); |
230 | ||
231 | $validStrings = array(); | |
232 | $fields = array( | |
233 | 'Full Conference' => 'Text', | |
234 | 'Meal Choice' => 'Select', | |
235 | 'Pre-conference Meetup?' => 'Radio', | |
236 | 'Evening Sessions' => 'CheckBox', | |
237 | ); | |
238 | $this->_testAddPriceFields($fields, $validateStrings, $financialType); | |
239 | ||
240 | // load the Price Set Preview and check for expected values | |
241 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
42daf119 | 242 | $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload'); |
6a488035 | 243 | |
6a488035 TO |
244 | // create new contact using dialog |
245 | $firstName = substr(sha1(rand()), 0, 7); | |
246 | $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com'); | |
247 | ||
248 | // select financial type | |
249 | $this->select('financial_type_id', "label={$financialType}"); | |
250 | ||
251 | // fill in Received Date | |
252 | $this->webtestFillDate('receive_date'); | |
253 | ||
254 | // source | |
255 | $this->type('source', 'Mailer 1'); | |
256 | ||
257 | // select price set items | |
258 | $this->select('price_set_id', "label=$setTitle"); | |
77a2a633 | 259 | $this->type("xpath=//input[@class='four crm-form-text required']", "1"); |
260 | $this->click("xpath=//input[@class='crm-form-radio']"); | |
261 | $this->click("xpath=//input[@class='crm-form-checkbox']"); | |
6a488035 TO |
262 | // select payment instrument type = Check and enter chk number |
263 | $this->select('payment_instrument_id', 'value=4'); | |
264 | $this->waitForElementPresent('check_number'); | |
265 | $this->type('check_number', 'check #1041'); | |
266 | ||
267 | $this->type('trxn_id', 'P20901X1' . rand(100, 10000)); | |
268 | ||
269 | //Additional Detail section | |
270 | $this->click('AdditionalDetail'); | |
271 | $this->waitForElementPresent('thankyou_date'); | |
272 | ||
273 | $this->type('note', 'This is a test note.'); | |
274 | $this->type('non_deductible_amount', '10'); | |
275 | $this->type('fee_amount', '0'); | |
276 | $this->type('net_amount', '0'); | |
277 | $this->type('invoice_id', time()); | |
278 | $this->webtestFillDate('thankyou_date'); | |
279 | ||
280 | // Clicking save. | |
281 | $this->click('_qf_Contribution_upload'); | |
282 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
283 | ||
284 | // Is status message correct? | |
285 | $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!"); | |
286 | ||
77a2a633 | 287 | $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']"); |
6a488035 TO |
288 | |
289 | //click through to the Membership view screen | |
77a2a633 | 290 | $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']"); |
6a488035 TO |
291 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); |
292 | $expected = array( | |
293 | 2 => $financialType, | |
294 | 3 => '590.00', | |
295 | 9 => 'Completed', | |
296 | 10 => 'Check', | |
297 | 11 => 'check #1041', | |
298 | ); | |
299 | foreach ($expected as $label => $value) { | |
300 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[$label]/td[2]", preg_quote($value)); | |
301 | } | |
302 | ||
303 | $exp = array( | |
304 | 2 => '$ 525.00', | |
305 | 3 => '$ 50.00', | |
306 | 4 => '$ 15.00', | |
307 | ); | |
308 | ||
309 | foreach ($exp as $lab => $val) { | |
310 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]", | |
311 | preg_quote($val) | |
312 | ); | |
313 | } | |
314 | } | |
315 | ||
6a488035 | 316 | function testContributeOnlineWithPriceSet() { |
6a488035 TO |
317 | $this->webtestLogin(); |
318 | ||
319 | //add financial type of account type expense | |
320 | $financialType = $this->_testAddFinancialType(); | |
6d5f1345 | 321 | |
6a488035 | 322 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
323 | $usedFor = 'Contribution'; |
324 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
325 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); |
326 | ||
327 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
328 | // which is where we are after adding Price Set. | |
a471a3b6 | 329 | $sid = $this->urlArg('sid'); |
6a488035 TO |
330 | $this->assertType('numeric', $sid); |
331 | ||
332 | $validStrings = array(); | |
333 | $fields = array( | |
334 | 'Full Conference' => 'Text', | |
335 | 'Meal Choice' => 'Select', | |
336 | 'Pre-conference Meetup?' => 'Radio', | |
337 | 'Evening Sessions' => 'CheckBox', | |
338 | ); | |
76e86fd8 | 339 | |
6a488035 | 340 | $this->_testAddPriceFields($fields, $validateStrings, $financialType); |
76e86fd8 | 341 | |
6a488035 TO |
342 | // load the Price Set Preview and check for expected values |
343 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
344 | ||
345 | // We need a payment processor | |
346 | $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7); | |
347 | $this->webtestAddPaymentProcessor($processorName); | |
348 | ||
071a6d2e | 349 | $this->openCiviPage("admin/contribute/add", "reset=1&action=add"); |
6a488035 TO |
350 | |
351 | $contributionTitle = substr(sha1(rand()), 0, 7); | |
352 | $rand = 2 * rand(2, 50); | |
353 | ||
354 | // fill in step 1 (Title and Settings) | |
355 | $contributionPageTitle = "Title $contributionTitle"; | |
356 | $this->type('title', $contributionPageTitle); | |
357 | $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor'); | |
358 | $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor'); | |
359 | ||
360 | $this->select('financial_type_id', "label={$financialType}"); | |
b45c587e CW |
361 | |
362 | // Submit form | |
363 | $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom"); | |
364 | ||
365 | // Get contribution page id | |
366 | $pageId = $this->urlArg('id'); | |
6a488035 TO |
367 | |
368 | //this contribution page for online contribution | |
6a488035 TO |
369 | $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']"); |
370 | $this->select('price_set_id', 'label=' . $setTitle); | |
371 | $this->click('_qf_Amount_next-bottom'); | |
372 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
373 | ||
6a488035 | 374 | //logout |
42daf119 | 375 | $this->webtestLogout(); |
6a488035 TO |
376 | |
377 | //Open Live Contribution Page | |
b45c587e | 378 | $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom'); |
6a488035 TO |
379 | |
380 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
381 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
382 | $this->waitForElementPresent('_qf_Main_upload-bottom'); | |
383 | $this->type('email-5', $firstName . '@example.com'); | |
77a2a633 | 384 | $this->type("xpath=//input[@class='four crm-form-text required']", "1"); |
385 | $this->click("xpath=//input[@class='crm-form-radio']"); | |
386 | $this->click("xpath=//input[@class='crm-form-checkbox']"); | |
6a488035 TO |
387 | |
388 | $streetAddress = '100 Main Street'; | |
389 | $this->type('billing_street_address-5', $streetAddress); | |
390 | $this->type('billing_city-5', 'San Francisco'); | |
391 | $this->type('billing_postal_code-5', '94117'); | |
392 | $this->select('billing_country_id-5', 'value=1228'); | |
393 | $this->select('billing_state_province_id-5', 'value=1001'); | |
394 | ||
395 | //Credit Card Info | |
396 | $this->select('credit_card_type', 'value=Visa'); | |
397 | $this->type('credit_card_number', '4111111111111111'); | |
398 | $this->type('cvv2', '000'); | |
399 | $this->select('credit_card_exp_date[M]', 'value=1'); | |
400 | $this->select('credit_card_exp_date[Y]', 'value=2020'); | |
401 | ||
402 | //Billing Info | |
0054ead7 DG |
403 | $this->type('billing_first_name', $firstName); |
404 | $this->type('billing_last_name', $lastName); | |
6a488035 TO |
405 | $this->type('billing_street_address-5', '15 Main St.'); |
406 | $this->type('billing_city-5', 'San Jose'); | |
407 | $this->select('billing_country_id-5', 'value=1228'); | |
408 | $this->select('billing_state_province_id-5', 'value=1004'); | |
409 | $this->type('billing_postal_code-5', '94129'); | |
225a8648 | 410 | $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom'); |
6a488035 TO |
411 | |
412 | $this->click('_qf_Confirm_next-bottom'); | |
413 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
414 | ||
415 | //login to check contribution | |
6a488035 TO |
416 | |
417 | // Log in using webtestLogin() method | |
418 | $this->webtestLogin(); | |
419 | ||
420 | //Find Contribution | |
42daf119 | 421 | $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low'); |
6a488035 TO |
422 | |
423 | $this->type('sort_name', "$firstName $lastName"); | |
225a8648 | 424 | $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
77a2a633 | 425 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); |
6a488035 | 426 | |
0054ead7 | 427 | // View Contribution Record and test for expected values |
6a488035 | 428 | $expected = array( |
42daf119 CW |
429 | 'From' => "{$firstName} {$lastName}", |
430 | 'Financial Type' => $financialType, | |
431 | 'Net Amount' => '$ 590.00', | |
0054ead7 | 432 | 'Contribution Status' => 'Completed', |
6a488035 | 433 | ); |
0054ead7 DG |
434 | $this->webtestVerifyTabularData($expected); |
435 | ||
6a488035 TO |
436 | } |
437 | ||
438 | function testContributeWithDateSpecificPriceSet() { | |
6a488035 TO |
439 | $this->webtestLogin(); |
440 | ||
441 | //add financial type of account type expense | |
d1c1ddc7 | 442 | $financialType = $this->_testAddFinancialType(); |
76e86fd8 | 443 | |
6a488035 | 444 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
445 | $usedFor = 'Contribution'; |
446 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
447 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); |
448 | ||
449 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
450 | // which is where we are after adding Price Set. | |
a471a3b6 | 451 | $sid = $this->urlArg('sid'); |
6a488035 TO |
452 | $this->assertType('numeric', $sid); |
453 | ||
454 | $validStrings = array(); | |
455 | $fields = array( | |
456 | 'Full Conference' => 'Text', | |
457 | 'Meal Choice' => 'Select', | |
458 | 'Pre-conference Meetup?' => 'Radio', | |
459 | 'Evening Sessions' => 'CheckBox', | |
460 | ); | |
461 | $this->_testAddPriceFields($fields, $validateStrings, $financialType, TRUE); | |
462 | ||
463 | // load the Price Set Preview and check for expected values | |
464 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
465 | ||
466 | // We need a payment processor | |
467 | $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7); | |
468 | $this->webtestAddPaymentProcessor($processorName); | |
469 | ||
071a6d2e | 470 | $this->openCiviPage("admin/contribute/add", "reset=1&action=add"); |
6a488035 TO |
471 | |
472 | $contributionTitle = substr(sha1(rand()), 0, 7); | |
473 | $rand = 2 * rand(2, 50); | |
474 | ||
475 | // fill in step 1 (Title and Settings) | |
476 | $contributionPageTitle = "Title $contributionTitle"; | |
477 | $this->type('title', $contributionPageTitle); | |
478 | $this->select('financial_type_id', "label={$financialType}"); | |
479 | $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor'); | |
480 | $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor'); | |
481 | ||
b45c587e CW |
482 | // Submit form |
483 | $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom"); | |
484 | ||
485 | // Get contribution page id | |
486 | $pageId = $this->urlArg('id'); | |
6a488035 TO |
487 | |
488 | //this contribution page for online contribution | |
6a488035 TO |
489 | $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']"); |
490 | $this->select('price_set_id', 'label=' . $setTitle); | |
b45c587e | 491 | $this->clickLink('_qf_Amount_next-bottom'); |
6a488035 TO |
492 | |
493 | //logout | |
42daf119 | 494 | $this->webtestLogout(); |
6a488035 TO |
495 | |
496 | //Open Live Contribution Page | |
b45c587e | 497 | $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom'); |
6a488035 TO |
498 | |
499 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
500 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
501 | $this->waitForElementPresent('_qf_Main_upload-bottom'); | |
502 | $this->type('email-5', $firstName . '@example.com'); | |
77a2a633 | 503 | $this->click("xpath=//input[@class='crm-form-radio']"); |
504 | $this->click("xpath=//input[@class='crm-form-checkbox']"); | |
6a488035 TO |
505 | |
506 | $streetAddress = '100 Main Street'; | |
507 | $this->type('billing_street_address-5', $streetAddress); | |
508 | $this->type('billing_city-5', 'San Francisco'); | |
509 | $this->type('billing_postal_code-5', '94117'); | |
510 | $this->select('billing_country_id-5', 'value=1228'); | |
511 | $this->select('billing_state_province_id-5', 'value=1001'); | |
512 | ||
513 | //Credit Card Info | |
514 | $this->select('credit_card_type', 'value=Visa'); | |
515 | $this->type('credit_card_number', '4111111111111111'); | |
516 | $this->type('cvv2', '000'); | |
517 | $this->select('credit_card_exp_date[M]', 'value=1'); | |
518 | $this->select('credit_card_exp_date[Y]', 'value=2020'); | |
519 | ||
520 | //Billing Info | |
0054ead7 DG |
521 | $this->type('billing_first_name', $firstName); |
522 | $this->type('billing_last_name', $lastName); | |
6a488035 TO |
523 | $this->type('billing_street_address-5', '15 Main St.'); |
524 | $this->type(' billing_city-5', 'San Jose'); | |
525 | $this->select('billing_country_id-5', 'value=1228'); | |
526 | $this->select('billing_state_province_id-5', 'value=1004'); | |
527 | $this->type('billing_postal_code-5', '94129'); | |
225a8648 | 528 | $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom'); |
6a488035 TO |
529 | |
530 | $this->click('_qf_Confirm_next-bottom'); | |
531 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
532 | ||
533 | //login to check contribution | |
6a488035 TO |
534 | $this->webtestLogin(); |
535 | ||
536 | //Find Contribution | |
42daf119 | 537 | $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low'); |
6a488035 TO |
538 | |
539 | $this->type('sort_name', "$firstName $lastName"); | |
77a2a633 | 540 | $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", FALSE); |
541 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom', FALSE); | |
6a488035 | 542 | |
0054ead7 | 543 | // View Contribution Record and test for expected values |
6a488035 | 544 | $expected = array( |
42daf119 CW |
545 | 'From' => "{$firstName} {$lastName}", |
546 | 'Financial Type' => $financialType, | |
547 | 'Net Amount' => '$ 65.00', | |
0054ead7 | 548 | 'Contribution Status' => 'Completed', |
6a488035 | 549 | ); |
0054ead7 | 550 | $this->webtestVerifyTabularData($expected); |
6a488035 TO |
551 | } |
552 | ||
553 | function testContributeOfflineforSoftcreditwithApi() { | |
6a488035 TO |
554 | // Log in using webtestLogin() method |
555 | $this->webtestLogin(); | |
76e86fd8 | 556 | |
6a488035 | 557 | //create a contact and return the contact id |
d1c1ddc7 | 558 | $firstNameSoft = "John_" . substr(sha1(rand()), 0, 5); |
559 | $lastNameSoft = "Doe_" . substr(sha1(rand()), 0, 5); | |
6a488035 TO |
560 | $this->webtestAddContact($firstNameSoft, $lastNameSoft); |
561 | $url = $this->parseURL(); | |
562 | $cid = $url['queryString']['cid']; | |
563 | $this->assertType('numeric', $cid); | |
76e86fd8 | 564 | |
6a488035 | 565 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
566 | $usedFor = 'Contribution'; |
567 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
568 | $financialType = $this->_testAddFinancialType(); |
569 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); | |
570 | ||
571 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
572 | // which is where we are after adding Price Set. | |
a471a3b6 | 573 | $sid = $this->urlArg('sid'); |
6a488035 TO |
574 | $this->assertType('numeric', $sid); |
575 | ||
576 | $validStrings = array(); | |
577 | $fields = array( | |
578 | 'Full Conference' => 'Text', | |
579 | 'Meal Choice' => 'Select', | |
580 | 'Pre-conference Meetup?' => 'Radio', | |
581 | 'Evening Sessions' => 'CheckBox', | |
582 | ); | |
583 | $this->_testAddPriceFields($fields, $validateStrings, $financialType); | |
584 | ||
585 | // load the Price Set Preview and check for expected values | |
586 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
587 | ||
42daf119 | 588 | $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload'); |
6a488035 | 589 | |
6a488035 TO |
590 | // create new contact using dialog |
591 | $firstName = substr(sha1(rand()), 0, 7); | |
592 | $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com'); | |
593 | ||
594 | // select contribution type | |
595 | $this->select('financial_type_id', "label={$financialType}"); | |
596 | ||
597 | // fill in Received Date | |
598 | $this->webtestFillDate('receive_date'); | |
599 | ||
600 | // source | |
601 | $this->type('source', 'Mailer 1'); | |
602 | ||
603 | // select price set items | |
604 | $this->select('price_set_id', "label=$setTitle"); | |
215ed9aa | 605 | $this->type("xpath=//input[@class='four crm-form-text required']", "1"); |
77a2a633 | 606 | $this->click("xpath=//input[@class='crm-form-radio']"); |
607 | $this->click("xpath=//input[@class='crm-form-checkbox']"); | |
6a488035 TO |
608 | // select payment instrument type = Check and enter chk number |
609 | $this->select('payment_instrument_id', 'value=4'); | |
610 | $this->waitForElementPresent('check_number'); | |
0054ead7 | 611 | $this->type('check_number', '1041'); |
6a488035 TO |
612 | |
613 | $this->type('trxn_id', 'P20901X1' . rand(100, 10000)); | |
76e86fd8 | 614 | |
77a2a633 | 615 | $this->webtestFillAutocomplete("{$lastNameSoft}, {$firstNameSoft}", 'soft_credit_contact_id_1'); |
13dff995 | 616 | |
215ed9aa | 617 | $this->type('soft_credit_amount_1', "65"); |
6a488035 TO |
618 | //Additional Detail section |
619 | $this->click('AdditionalDetail'); | |
620 | $this->waitForElementPresent('thankyou_date'); | |
621 | ||
622 | $this->type('note', 'This is a test note.'); | |
6a488035 TO |
623 | $this->type('invoice_id', time()); |
624 | $this->webtestFillDate('thankyou_date'); | |
625 | ||
626 | // Clicking save. | |
77a2a633 | 627 | $this->clickLink('_qf_Contribution_upload', "xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']", FALSE); |
0054ead7 | 628 | $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!"); |
6a488035 | 629 | |
0054ead7 | 630 | //click through to the Contribution view screen |
77a2a633 | 631 | $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']"); |
6a488035 TO |
632 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); |
633 | ||
0054ead7 | 634 | // View Contribution Record and test for expected values |
6a488035 | 635 | $expected = array( |
42daf119 CW |
636 | 'From' => "{$firstName} Contributor", |
637 | 'Financial Type' => $financialType, | |
0054ead7 | 638 | 'Contribution Amount' => 'Contribution Total: $ 590.00', |
42daf119 CW |
639 | 'Paid By' => 'Check', |
640 | 'Check Number' => '1041', | |
0054ead7 | 641 | 'Contribution Status' => 'Completed', |
6a488035 | 642 | ); |
0054ead7 | 643 | $this->webtestVerifyTabularData($expected); |
76e86fd8 | 644 | |
6a488035 TO |
645 | $exp = array( |
646 | 2 => '$ 525.00', | |
647 | 3 => '$ 50.00', | |
648 | 4 => '$ 15.00', | |
649 | ); | |
650 | ||
651 | foreach ($exp as $lab => $val) { | |
652 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]", | |
653 | preg_quote($val) | |
654 | ); | |
655 | } | |
0054ead7 | 656 | |
c2768486 | 657 | // verify if soft credit was created successfully |
658 | $softCreditValues = array( | |
659 | 'Soft Credit To' => "{$firstNameSoft} {$lastNameSoft}", | |
660 | 'Amount' => '65.00', | |
661 | ); | |
662 | ||
663 | foreach ($softCreditValues as $value) { | |
664 | $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value)); | |
665 | } | |
666 | ||
6a488035 TO |
667 | // Check for Soft contact created |
668 | $this->click("css=input#sort_name_navigation"); | |
669 | $this->type("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft"); | |
670 | $this->typeKeys("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft"); | |
671 | // wait for result list | |
77a2a633 | 672 | $this->waitForElementPresent("css=ul.ui-autocomplete li"); |
76e86fd8 | 673 | |
6a488035 | 674 | // visit contact summary page |
77a2a633 | 675 | $this->click("css=ul.ui-autocomplete li"); |
6a488035 | 676 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
d1c1ddc7 | 677 | $this->click('css=li#tab_contribute a'); |
6a488035 | 678 | $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)'); |
76e86fd8 | 679 | |
77a2a633 | 680 | $id = explode('id=', $this->getAttribute("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a[text()='View']@href")); |
6a488035 | 681 | $id = substr($id[1], 0, strpos($id[1], '&')); |
77a2a633 | 682 | $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a"); |
6a488035 | 683 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); |
76e86fd8 | 684 | |
0054ead7 | 685 | $this->webtestVerifyTabularData($expected); |
76e86fd8 | 686 | |
d1c1ddc7 | 687 | $params = array( |
688 | 'contribution_id' => $id, | |
6a488035 TO |
689 | 'version' => 3, |
690 | ); | |
76e86fd8 | 691 | |
0054ead7 | 692 | // Retrieve contribution from the DB via api and verify DB values against view contribution page |
6a488035 | 693 | require_once 'api/api.php'; |
d1c1ddc7 | 694 | $fields = $this->webtest_civicrm_api('contribution', 'get', $params); |
76e86fd8 | 695 | |
6a488035 | 696 | $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to']; |
0054ead7 DG |
697 | $softCreditContact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE); |
698 | ||
699 | // View Contribution Record and test for expected values | |
700 | $expected = array( | |
42daf119 CW |
701 | 'From' => $fields['values'][$fields['id']]['display_name'], |
702 | 'Financial Type' => $fields['values'][$fields['id']]['financial_type'], | |
0054ead7 DG |
703 | 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'], |
704 | 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'], | |
42daf119 CW |
705 | 'Paid By' => $fields['values'][$fields['id']]['contribution_payment_instrument'], |
706 | 'Check Number' => $fields['values'][$fields['id']]['contribution_check_number'], | |
6a488035 | 707 | ); |
c2768486 | 708 | |
0054ead7 | 709 | $this->webtestVerifyTabularData($expected); |
c2768486 | 710 | |
711 | // verify if soft credit | |
712 | $softCreditValues = array( | |
713 | 'Soft Credit To' => $softCreditContact->display_name, | |
714 | 'Amount' => '65.00', | |
715 | ); | |
716 | ||
717 | foreach ($softCreditValues as $value) { | |
718 | $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value)); | |
719 | } | |
6a488035 TO |
720 | } |
721 | } | |
722 |