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_Event_AddPricesetTest extends CiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | function testAddPriceSet() { | |
6a488035 TO |
35 | |
36 | // Log in using webtestLogin() method | |
37 | $this->webtestLogin(); | |
38 | ||
39 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); | |
42daf119 CW |
40 | $usedFor = 'Event'; |
41 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
42 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
43 | ||
44 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
45 | // which is where we are after adding Price Set. | |
a471a3b6 | 46 | $sid = $this->urlArg('sid'); |
6a488035 TO |
47 | $this->assertType('numeric', $sid); |
48 | ||
49 | $validStrings = array(); | |
50 | ||
51 | $fields = array( | |
52 | 'Full Conference' => 'Text', | |
53 | 'Meal Choice' => 'Select', | |
54 | 'Pre-conference Meetup?' => 'Radio', | |
55 | 'Evening Sessions' => 'CheckBox', | |
56 | ); | |
57 | $this->_testAddPriceFields($fields, $validateStrings); | |
58 | // var_dump($validateStrings); | |
59 | ||
60 | // load the Price Set Preview and check for expected values | |
61 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
62 | } | |
63 | ||
64 | function _testAddSet($setTitle, $usedFor, $setHelp, $financialType = 'Event Fee') { | |
8b67c4d0 | 65 | $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom'); |
6a488035 TO |
66 | |
67 | // Enter Priceset fields (Title, Used For ...) | |
68 | $this->type('title', $setTitle); | |
69 | if ($usedFor == 'Event') { | |
70 | $this->check('extends[1]'); | |
71 | } | |
72 | elseif ($usedFor == 'Contribution') { | |
73 | $this->check('extends[2]'); | |
74 | } | |
75 | ||
76e86fd8 CW |
76 | $this->select("css=select.form-select", "label={$financialType}"); |
77 | ||
6a488035 TO |
78 | $this->type('help_pre', $setHelp); |
79 | ||
80 | $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); | |
225a8648 | 81 | $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom'); |
6a488035 TO |
82 | } |
83 | ||
84 | function _testAddPriceFields(&$fields, &$validateStrings, $dateSpecificFields = FALSE) { | |
85 | foreach ($fields as $label => $type) { | |
86 | $validateStrings[] = $label; | |
87 | ||
88 | $this->type('label', $label); | |
89 | $this->select('html_type', "value={$type}"); | |
90 | ||
91 | switch ($type) { | |
92 | case 'Text': | |
93 | $validateStrings[] = '525.00'; | |
94 | $this->type('price', '525.00'); | |
95 | $this->select('financial_type_id', 'Donation'); | |
96 | if ($dateSpecificFields == TRUE) { | |
97 | $this->webtestFillDateTime('active_on', '+1 week'); | |
98 | } | |
99 | else { | |
100 | $this->check('is_required'); | |
101 | } | |
102 | break; | |
103 | ||
104 | case 'Select': | |
105 | $options = array( | |
106 | 1 => array('label' => 'Chicken', | |
107 | 'amount' => '30.00', | |
108 | 'financial_type_id' => 'Donation' | |
109 | ), | |
110 | 2 => array( | |
111 | 'label' => 'Vegetarian', | |
112 | 'amount' => '25.00', | |
113 | 'financial_type_id' => 'Donation' | |
114 | ), | |
115 | ); | |
116 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
117 | if ($dateSpecificFields == TRUE) { | |
118 | $this->webtestFillDateTime('expire_on', '-1 week'); | |
119 | } | |
120 | break; | |
121 | ||
122 | case 'Radio': | |
123 | $options = array( | |
124 | 1 => array('label' => 'Yes', | |
125 | 'amount' => '50.00', | |
76e86fd8 CW |
126 | 'financial_type_id' => 'Donation' |
127 | ||
6a488035 TO |
128 | ), |
129 | 2 => array( | |
130 | 'label' => 'No', | |
131 | 'amount' => '0', | |
132 | 'financial_type_id' => 'Donation' | |
133 | ), | |
134 | ); | |
135 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
136 | $this->check('is_required'); | |
137 | if ($dateSpecificFields == TRUE) { | |
138 | $this->webtestFillDateTime('active_on', '-1 week'); | |
139 | } | |
140 | break; | |
141 | ||
142 | case 'CheckBox': | |
143 | $options = array( | |
144 | 1 => array('label' => 'First Night', | |
145 | 'amount' => '15.00', | |
146 | 'financial_type_id' => 'Donation' | |
147 | ), | |
148 | 2 => array( | |
149 | 'label' => 'Second Night', | |
150 | 'amount' => '15.00', | |
151 | 'financial_type_id' => 'Donation' | |
152 | ), | |
153 | ); | |
154 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
155 | if ($dateSpecificFields == TRUE) { | |
156 | $this->webtestFillDateTime('expire_on', '+1 week'); | |
157 | } | |
158 | break; | |
159 | ||
160 | default: | |
161 | break; | |
162 | } | |
225a8648 | 163 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom'); |
6a488035 TO |
164 | } |
165 | } | |
166 | ||
167 | function _testVerifyPriceSet($validateStrings, $sid) { | |
168 | // verify Price Set at Preview page | |
169 | // start at Manage Price Sets listing | |
a9f5275d | 170 | $this->openCiviPage('admin/price', 'reset=1'); |
6a488035 TO |
171 | |
172 | // Use the price set id ($sid) to pick the correct row | |
225a8648 | 173 | $this->clickLink("css=tr#row_{$sid} a[title='Preview Price Set']", '_qf_Preview_cancel-bottom'); |
6a488035 TO |
174 | |
175 | // Check for expected price set field strings | |
176 | $this->assertStringsPresent($validateStrings); | |
177 | } | |
178 | ||
179 | function testRegisterWithPriceSet() { | |
6a488035 TO |
180 | // Log in using webtestLogin() method |
181 | $this->webtestLogin(); | |
182 | ||
183 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); | |
42daf119 CW |
184 | $usedFor = 'Event'; |
185 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
186 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
187 | ||
188 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
189 | // which is where we are after adding Price Set. | |
a471a3b6 | 190 | $sid = $this->urlArg('sid'); |
6a488035 TO |
191 | $this->assertType('numeric', $sid); |
192 | ||
193 | $validStrings = array(); | |
194 | $fields = array( | |
195 | 'Full Conference' => 'Text', | |
196 | 'Meal Choice' => 'Select', | |
197 | 'Pre-conference Meetup?' => 'Radio', | |
198 | 'Evening Sessions' => 'CheckBox', | |
199 | ); | |
200 | $this->_testAddPriceFields($fields, $validateStrings); | |
201 | ||
202 | // load the Price Set Preview and check for expected values | |
203 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
204 | ||
205 | // We need a payment processor | |
206 | $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7); | |
207 | $this->webtestAddPaymentProcessor($processorName); | |
208 | ||
8b67c4d0 | 209 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
6a488035 | 210 | |
42daf119 CW |
211 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
212 | $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com'; | |
6a488035 TO |
213 | $eventDescription = 'Here is a description for this conference.'; |
214 | ||
6a488035 TO |
215 | $this->select('event_type_id', 'value=1'); |
216 | ||
217 | // Attendee role s/b selected now. | |
218 | $this->select('default_role_id', 'value=1'); | |
219 | ||
220 | // Enter Event Title, Summary and Description | |
221 | $this->type('title', $eventTitle); | |
222 | $this->type('summary', 'This is a great conference. Sign up now!'); | |
223 | ||
224 | // Type description in ckEditor (fieldname, text to type, editor) | |
225 | $this->fillRichTextField('description', $eventDescription); | |
226 | ||
227 | // Choose Start and End dates. | |
228 | // Using helper webtestFillDate function. | |
229 | $this->webtestFillDateTime("start_date", "+1 week"); | |
230 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); | |
231 | ||
232 | $this->type('max_participants', '50'); | |
233 | $this->click('is_map'); | |
234 | $this->click('_qf_EventInfo_upload-bottom'); | |
235 | ||
236 | // Wait for Location tab form to load | |
237 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
238 | ||
239 | // Go to Fees tab | |
240 | $this->click('link=Fees'); | |
241 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); | |
242 | $this->click('CIVICRM_QFID_1_is_monetary'); | |
243 | $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']"); | |
244 | $this->select('financial_type_id','label=Event Fee'); | |
245 | $this->select('price_set_id', 'label=' . $setTitle); | |
246 | ||
247 | $this->click('_qf_Fee_upload-bottom'); | |
248 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
249 | ||
250 | // intro text for registration page | |
251 | $registerIntro = 'Fill in all the fields below and click Continue.'; | |
252 | ||
253 | // Go to Online Registration tab | |
254 | $this->click('link=Online Registration'); | |
255 | $this->waitForElementPresent('_qf_Registration_upload-bottom'); | |
256 | ||
257 | $this->check('is_online_registration'); | |
258 | $this->assertChecked('is_online_registration'); | |
259 | ||
260 | $this->fillRichTextField('intro_text', $registerIntro); | |
261 | ||
262 | // enable confirmation email | |
263 | $this->click('CIVICRM_QFID_1_is_email_confirm'); | |
264 | $this->type('confirm_from_name', 'Jane Doe'); | |
265 | $this->type('confirm_from_email', 'jane.doe@example.org'); | |
266 | ||
267 | $this->click('_qf_Registration_upload-bottom'); | |
268 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
269 | $this->waitForTextPresent("'Registration' information has been saved."); | |
270 | ||
271 | // verify event input on info page | |
272 | // start at Manage Events listing | |
a9f5275d | 273 | $this->openCiviPage('event/manage', 'reset=1'); |
6a488035 TO |
274 | $this->click("link=$eventTitle"); |
275 | ||
276 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
277 | $eventInfoUrl = $this->getLocation(); | |
278 | ||
42daf119 | 279 | $this->webtestLogout(); |
6a488035 TO |
280 | $this->open($eventInfoUrl); |
281 | $this->click('link=Register Now'); | |
282 | $this->waitForElementPresent('_qf_Register_upload-bottom'); | |
283 | ||
284 | $this->type("xpath=//input[@class='form-text four required']", "1"); | |
285 | $this->click("xpath=//input[@class='form-radio']"); | |
286 | $this->click("xpath=//input[@class='form-checkbox']"); | |
70452444 | 287 | $this->type("first_name", "Jane"); |
288 | $lastName = "Smith" . substr(sha1(rand()), 0, 7); | |
289 | $this->type("last_name", $lastName); | |
6a488035 TO |
290 | $this->type('email-Primary', $email); |
291 | ||
292 | $this->waitForElementPresent('credit_card_type'); | |
293 | $this->select('credit_card_type', 'value=Visa'); | |
294 | $this->type('credit_card_number', '4111111111111111'); | |
295 | $this->type('cvv2', '000'); | |
296 | $this->select('credit_card_exp_date[M]', 'value=1'); | |
297 | $this->select('credit_card_exp_date[Y]', 'value=2020'); | |
298 | $this->type('billing_first_name', 'Jane'); | |
70452444 | 299 | $this->type('billing_last_name', $lastName); |
6a488035 TO |
300 | $this->type('billing_street_address-5', '15 Main St.'); |
301 | $this->type(' billing_city-5', 'San Jose'); | |
302 | $this->select('billing_country_id-5', 'value=1228'); | |
303 | $this->select('billing_state_province_id-5', 'value=1004'); | |
304 | $this->type('billing_postal_code-5', '94129'); | |
305 | ||
225a8648 | 306 | $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom'); |
6a488035 TO |
307 | $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information'); |
308 | $this->assertStringsPresent($confirmStrings); | |
309 | $this->click('_qf_Confirm_next-bottom'); | |
310 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
311 | $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date'); | |
312 | $this->assertStringsPresent($thankStrings); | |
313 | ||
6a488035 TO |
314 | // Log in using webtestLogin() method |
315 | $this->webtestLogin(); | |
316 | ||
317 | //Find Participant | |
8b67c4d0 | 318 | $this->openCiviPage('event/search', 'reset=1', '_qf_Search_refresh'); |
6a488035 TO |
319 | |
320 | $this->type('sort_name', "$email"); | |
225a8648 | 321 | $this->clickLink('_qf_Search_refresh', "xpath=id('participantSearch')/table/tbody/tr/td[11]/span/a[text()='View']"); |
6a488035 TO |
322 | $this->click("xpath=id('participantSearch')/table/tbody/tr/td[11]/span/a[text()='View']"); |
323 | $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom'); | |
324 | ||
325 | $expected = array( | |
326 | 2 => 'Full Conference', | |
327 | 3 => 'Pre-conference Meetup? - Yes', | |
328 | 4 => 'Evening Sessions - First Night', | |
329 | ); | |
330 | foreach ($expected as $value => $label) { | |
331 | $this->verifyText("xpath=id('ParticipantView')/div[2]/table[1]/tbody/tr[7]/td[2]/table/tbody/tr[$value]/td", $label); | |
332 | } | |
333 | // Fixme: We can't asset full string like - "Event Total: $ 590.00" as it has special char | |
334 | $this->assertStringsPresent(' 590.00'); | |
335 | $this->click('_qf_ParticipantView_cancel-bottom'); | |
336 | } | |
337 | ||
338 | function testParticipantWithDateSpecificPriceSet() { | |
6a488035 TO |
339 | |
340 | // Log in using webtestLogin() method | |
341 | $this->webtestLogin(); | |
342 | ||
343 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); | |
42daf119 CW |
344 | $usedFor = 'Event'; |
345 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
346 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
347 | ||
348 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
349 | // which is where we are after adding Price Set. | |
a471a3b6 | 350 | $sid = $this->urlArg('sid'); |
6a488035 TO |
351 | $this->assertType('numeric', $sid); |
352 | ||
353 | $validStrings = array(); | |
354 | $fields = array( | |
355 | 'Full Conference' => 'Text', | |
356 | 'Meal Choice' => 'Select', | |
357 | 'Pre-conference Meetup?' => 'Radio', | |
358 | 'Evening Sessions' => 'CheckBox', | |
359 | ); | |
360 | $this->_testAddPriceFields($fields, $validateStrings, TRUE); | |
361 | ||
362 | // load the Price Set Preview and check for expected values | |
363 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
364 | ||
365 | // We need a payment processor | |
366 | $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7); | |
367 | $this->webtestAddPaymentProcessor($processorName); | |
368 | ||
8b67c4d0 | 369 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
6a488035 | 370 | |
42daf119 CW |
371 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
372 | $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com'; | |
6a488035 TO |
373 | $eventDescription = 'Here is a description for this conference.'; |
374 | ||
6a488035 TO |
375 | $this->select('event_type_id', 'value=1'); |
376 | ||
377 | // Attendee role s/b selected now. | |
378 | $this->select('default_role_id', 'value=1'); | |
379 | ||
380 | // Enter Event Title, Summary and Description | |
381 | $this->type('title', $eventTitle); | |
382 | $this->type('summary', 'This is a great conference. Sign up now!'); | |
383 | ||
384 | // Type description in ckEditor (fieldname, text to type, editor) | |
385 | $this->fillRichTextField('description', $eventDescription ); | |
386 | ||
387 | // Choose Start and End dates. | |
388 | // Using helper webtestFillDate function. | |
389 | $this->webtestFillDateTime("start_date", "+1 week"); | |
390 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); | |
391 | ||
392 | $this->type('max_participants', '50'); | |
393 | $this->click('is_map'); | |
394 | $this->click('_qf_EventInfo_upload-bottom'); | |
395 | ||
396 | // Wait for Location tab form to load | |
397 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
398 | ||
399 | // Go to Fees tab | |
400 | $this->click('link=Fees'); | |
401 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); | |
402 | $this->click('CIVICRM_QFID_1_is_monetary'); | |
403 | $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']"); | |
404 | $this->select('financial_type_id','label=Event Fee'); | |
405 | $this->select('price_set_id', 'label=' . $setTitle); | |
406 | ||
407 | $this->click('_qf_Fee_upload-bottom'); | |
408 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
409 | ||
410 | // intro text for registration page | |
411 | $registerIntro = 'Fill in all the fields below and click Continue.'; | |
412 | ||
413 | // Go to Online Registration tab | |
414 | $this->click('link=Online Registration'); | |
415 | $this->waitForElementPresent('_qf_Registration_upload-bottom'); | |
416 | ||
417 | $this->check('is_online_registration'); | |
418 | $this->assertChecked('is_online_registration'); | |
419 | ||
420 | $this->fillRichTextField('intro_text', $registerIntro); | |
421 | ||
422 | // enable confirmation email | |
423 | $this->click('CIVICRM_QFID_1_is_email_confirm'); | |
424 | $this->type('confirm_from_name', 'Jane Doe'); | |
425 | $this->type('confirm_from_email', 'jane.doe@example.org'); | |
426 | ||
427 | $this->click('_qf_Registration_upload-bottom'); | |
428 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
429 | $this->waitForTextPresent("'Registration' information has been saved."); | |
430 | ||
431 | // verify event input on info page | |
432 | // start at Manage Events listing | |
a9f5275d | 433 | $this->openCiviPage('event/manage', 'reset=1'); |
6a488035 TO |
434 | $this->click("link=$eventTitle"); |
435 | ||
436 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
437 | // Adding contact with randomized first name (so we can then select that contact when creating event registration) | |
438 | // We're using Quick Add block on the main page for this. | |
439 | $firstName = substr(sha1(rand()), 0, 7); | |
440 | $this->webtestAddContact($firstName, 'Anderson', TRUE); | |
441 | $contactName = "Anderson, $firstName"; | |
442 | $displayName = "$firstName Anderson"; | |
443 | ||
8b67c4d0 | 444 | $this->openCiviPage('participant/add', 'reset=1&action=add&context=standalone', '_qf_Participant_upload-bottom'); |
6a488035 | 445 | |
6a488035 TO |
446 | // Type contact last name in contact auto-complete, wait for dropdown and click first result |
447 | $this->webtestFillAutocomplete($firstName); | |
448 | ||
449 | // Select event. Based on label for now. | |
450 | $this->select('event_id', "label=regexp:$eventTitle"); | |
451 | // Select role | |
452 | $this->click('role_id[2]'); | |
453 | ||
454 | $this->click("xpath=//input[@class='form-radio']"); | |
455 | $this->click("xpath=//input[@class='form-checkbox']"); | |
456 | ||
457 | // Choose Registration Date. | |
458 | // Using helper webtestFillDate function. | |
459 | $this->webtestFillDate('register_date', 'now'); | |
460 | $today = date('F jS, Y', strtotime('now')); | |
461 | ||
462 | // Select participant status | |
463 | $this->select('status_id', 'value=1'); | |
464 | ||
465 | // Clicking save. | |
466 | $this->click('_qf_Participant_upload-bottom'); | |
467 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
468 | // Is status message correct? | |
c038a4f0 | 469 | $this->assertElementContainsText("css=#crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!"); |
6a488035 TO |
470 | |
471 | $this->waitForElementPresent("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
472 | ||
473 | //click through to the participant view screen | |
474 | $this->click("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
475 | $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom'); | |
476 | } | |
7f587af0 PN |
477 | |
478 | /** | |
76e86fd8 CW |
479 | * Function to test to regiter participant for event with |
480 | ||
7f587af0 | 481 | * multiple price fields in price-set |
76e86fd8 CW |
482 | * CRM-11986 |
483 | ||
7f587af0 PN |
484 | * |
485 | */ | |
486 | function testEventWithPriceSet() { | |
76e86fd8 | 487 | |
7f587af0 PN |
488 | // Log in using webtestLogin() method |
489 | $this->webtestLogin(); | |
76e86fd8 | 490 | |
7f587af0 PN |
491 | // Adding contact with randomized first name (so we can then select that contact when creating event registration) |
492 | // We're using Quick Add block on the main page for this. | |
493 | $firstName = substr(sha1(rand()), 0, 7); | |
494 | $this->webtestAddContact($firstName, 'Anderson', TRUE); | |
495 | $contactName = "Anderson, $firstName"; | |
496 | $displayName = "$firstName Anderson"; | |
76e86fd8 | 497 | |
7f587af0 | 498 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
499 | $usedFor = 'Event'; |
500 | $setHelp = 'Select your conference options.'; | |
7f587af0 PN |
501 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
502 | ||
503 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
504 | // which is where we are after adding Price Set. | |
a471a3b6 | 505 | $sid = $this->urlArg('sid'); |
7f587af0 PN |
506 | $this->assertType('numeric', $sid); |
507 | ||
508 | $validStrings = array(); | |
509 | $fields = array( | |
510 | 'Full Conference' => 'Text', | |
511 | 'Pre-conference Meetup?' => 'Radio', | |
512 | 'Evening Sessions' => 'CheckBox', | |
513 | ); | |
514 | $this->_testAddPriceFields($fields, $validateStrings); | |
76e86fd8 | 515 | |
7f587af0 PN |
516 | // load the Price Set Preview and check for expected values |
517 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
42daf119 | 518 | |
8b67c4d0 | 519 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
7f587af0 | 520 | |
42daf119 CW |
521 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
522 | $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com'; | |
7f587af0 | 523 | $eventDescription = 'Here is a description for this conference.'; |
7f587af0 | 524 | |
7f587af0 | 525 | $this->select('event_type_id', 'value=1'); |
76e86fd8 | 526 | |
7f587af0 PN |
527 | // Attendee role s/b selected now. |
528 | $this->select('default_role_id', 'value=1'); | |
76e86fd8 | 529 | |
7f587af0 PN |
530 | // Enter Event Title, Summary and Description |
531 | $this->type('title', $eventTitle); | |
532 | $this->type('summary', 'This is a great conference. Sign up now!'); | |
76e86fd8 | 533 | |
7f587af0 PN |
534 | // Type description in ckEditor (fieldname, text to type, editor) |
535 | $this->fillRichTextField('description', $eventDescription); | |
76e86fd8 | 536 | |
7f587af0 PN |
537 | // Choose Start and End dates. |
538 | // Using helper webtestFillDate function. | |
539 | $this->webtestFillDateTime("start_date", "+1 week"); | |
540 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); | |
541 | ||
542 | $this->type('max_participants', '50'); | |
543 | $this->click('is_map'); | |
544 | $this->click('_qf_EventInfo_upload-bottom'); | |
545 | ||
546 | // Wait for Location tab form to load | |
547 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
548 | ||
549 | // Go to Fees tab | |
550 | $this->click('link=Fees'); | |
551 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); | |
552 | $this->click('CIVICRM_QFID_1_is_monetary'); | |
553 | $this->select('financial_type_id','label=Event Fee'); | |
554 | $this->select('price_set_id', 'label=' . $setTitle); | |
76e86fd8 | 555 | |
7f587af0 PN |
556 | $this->click('_qf_Fee_upload-bottom'); |
557 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
558 | ||
42daf119 | 559 | $this->openCiviPage('participant/add', 'reset=1&action=add&context=standalone', '_qf_Participant_upload-bottom'); |
7f587af0 | 560 | |
7f587af0 PN |
561 | // Type contact last name in contact auto-complete, wait for dropdown and click first result |
562 | $this->webtestFillAutocomplete($firstName); | |
563 | $this->select('event_id', "label=regexp:$eventTitle"); | |
564 | // Select role | |
565 | $this->click('role_id[2]'); | |
76e86fd8 | 566 | |
7f587af0 PN |
567 | // Choose Registration Date. |
568 | // Using helper webtestFillDate function. | |
569 | $this->webtestFillDate('register_date', 'now'); | |
570 | $today = date('F jS, Y', strtotime('now')); | |
571 | // May 5th, 2010 | |
76e86fd8 | 572 | |
7f587af0 PN |
573 | // Select participant status |
574 | $this->select('status_id', 'value=1'); | |
575 | ||
576 | // Setting registration source | |
577 | $this->type('source', 'Event StandaloneAddTest Webtest'); | |
76e86fd8 | 578 | |
7f587af0 PN |
579 | // Select an event fee |
580 | $this->waitForElementPresent('priceset'); | |
581 | $this->type("//div[@id='priceset']//div[@class='crm-section Full_Conference-section']/div[2]/input", '5'); | |
582 | $this->fireEvent("//div[@id='priceset']//div[@class='crm-section Full_Conference-section']/div[2]/input", 'blur'); | |
583 | $this->click("xpath=//div[@id='priceset']//div[@class='crm-section Pre_conference_Meetup_-section']/div[2]/div[1]/span/input"); | |
584 | $this->click("xpath=//div[@id='priceset']//div[@class='crm-section Evening_Sessions-section']/div[2]/div[1]/span/input"); | |
585 | $this->click("xpath=//div[@id='priceset']//div[@class='crm-section Evening_Sessions-section']/div[2]/div[2]/span/input"); | |
76e86fd8 | 586 | |
7f587af0 PN |
587 | // Select payment method = Check and enter chk number |
588 | $this->select('payment_instrument_id', 'value=4'); | |
589 | $this->waitForElementPresent('check_number'); | |
76e86fd8 CW |
590 | $this->type('check_number', '1044'); |
591 | ||
7f587af0 PN |
592 | // Clicking save. |
593 | $this->click('_qf_Participant_upload-bottom'); | |
594 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
76e86fd8 | 595 | |
7f587af0 | 596 | // Is status message correct? |
c038a4f0 | 597 | $this->assertElementContainsText("css=#crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!"); |
76e86fd8 | 598 | |
7f587af0 PN |
599 | $this->waitForElementPresent("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); |
600 | //click through to the participant view screen | |
601 | $this->click("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
602 | $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom'); | |
76e86fd8 | 603 | |
7f587af0 PN |
604 | $this->webtestVerifyTabularData( |
605 | array( | |
606 | 'Event' => $eventTitle, | |
607 | 'Participant Role' => 'Attendee', | |
608 | 'Status' => 'Registered', | |
609 | 'Event Source' => 'Event StandaloneAddTest Webtest', | |
610 | 'Event Fees' => 'Event Total: $ 2,705.00', | |
611 | ) | |
612 | ); | |
613 | $expectedLineItems = array( | |
614 | 2 => array( | |
615 | 1 => 'Full Conference', | |
616 | 2 => '5', | |
617 | 3 => '$ 525.00', | |
618 | 4 => '$ 2,625.00', | |
619 | ), | |
620 | 3 => array( | |
621 | 2 => '1', | |
622 | 3 => '$ 50.00', | |
623 | 4 => '$ 50.00', | |
624 | ), | |
625 | 4 => array( | |
626 | 1 => 'Evening Sessions - First Night', | |
627 | 2 => '1', | |
628 | 3 => '$ 15.00', | |
629 | 4 => '$ 15.00', | |
630 | ), | |
631 | 5 => array( | |
632 | 1 => 'Evening Sessions - Second Night', | |
633 | 2 => '1', | |
634 | 3 => '$ 15.00', | |
635 | 4 => '$ 15.00', | |
636 | ), | |
637 | ); | |
638 | $this->_checkLineItems($expectedLineItems); | |
639 | // check contribution record as well | |
640 | // click through to the contribution view screen | |
641 | $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']"); | |
642 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); | |
643 | ||
644 | $this->webtestVerifyTabularData( | |
645 | array( | |
646 | 'From' => $displayName, | |
647 | 'Financial Type' => 'Event Fee', | |
648 | 'Contribution Status' => 'Completed', | |
649 | 'Paid By' => 'Check', | |
650 | 'Check Number' => '1044', | |
651 | 'Total Amount' => '$ 2,705.00', | |
652 | 'Received Into' => 'Deposit Bank Account', | |
653 | ) | |
654 | ); | |
655 | } | |
76e86fd8 | 656 | |
9669d0f3 RN |
657 | |
658 | function testDeletePriceSetforEventTemplate() { | |
659 | // Log in using webtestLogin() method | |
660 | $this->webtestLogin(); | |
661 | ||
662 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); | |
663 | $usedFor = 'Event'; | |
664 | $setHelp = 'Select your conference options.'; | |
665 | $this->_testAddSet($setTitle, $usedFor, $setHelp); | |
666 | ||
667 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
668 | // which is where we are after adding Price Set. | |
669 | $sid = $this->urlArg('sid'); | |
670 | $this->assertType('numeric', $sid); | |
671 | ||
672 | $validStrings = array(); | |
673 | $fields = array( | |
674 | 'Test Field' => 'Text', | |
675 | ); | |
676 | $this->_testAddPriceFields($fields, $validateStrings); | |
677 | ||
678 | // load the Price Set Preview and check for expected values | |
679 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
680 | $this->openCiviPage('admin/eventTemplate', 'reset=1'); | |
681 | $this->clickLink('newEventTemplate'); | |
682 | $this->select("template_id", "value=6"); | |
683 | // Wait for event type to be filled in (since page reloads) | |
684 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
685 | // Enter Event Title, Summary and Description | |
686 | $this->type('template_title', "Test Template"); | |
687 | $this->type("title", "Test Event"); | |
688 | $this->type("summary", "This is a great conference. Sign up now!"); | |
689 | $this->clickLink("_qf_EventInfo_upload-bottom"); | |
690 | ||
691 | // Go to Fees tab | |
692 | $this->click('link=Fees'); | |
693 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); | |
694 | $this->click('CIVICRM_QFID_1_is_monetary'); | |
695 | $this->select('financial_type_id','label=Event Fee'); | |
696 | $this->select('price_set_id', 'label=' . $setTitle); | |
697 | $templateId = $this->urlArg('id'); | |
698 | $this->clickLink('_qf_Fee_upload-bottom'); | |
699 | ||
700 | //check the delete for price field | |
701 | $this->openCiviPage("admin/price/field", "reset=1&action=browse&sid={$sid}"); | |
702 | $this->click("xpath=//table[@id='option11']/tbody/tr/td[9]/span[2]/ul/li[2]/a"); | |
703 | // Check confirmation alert. | |
704 | $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this price field?/", | |
705 | $this->getConfirmation() | |
706 | )); | |
707 | $this->chooseOkOnNextConfirmation(); | |
708 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
709 | //assert the message | |
5be3afb2 | 710 | $this->waitForText('price_set_used_by', |
711 | "it is currently in use by one or more active events or contribution pages or contributions or event templates."); | |
9669d0f3 RN |
712 | |
713 | //check the delete for priceset | |
714 | $this->openCiviPage("admin/price", "reset=1"); | |
715 | $this->click("xpath=//table[@id='option11']/tbody/tr/td[4]/span[2]/ul/li[3]/a"); | |
716 | // Check confirmation alert. | |
717 | $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this price set?/", | |
718 | $this->getConfirmation() | |
719 | )); | |
720 | $this->chooseOkOnNextConfirmation(); | |
721 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
722 | //assert the message | |
5be3afb2 | 723 | $this->waitForText('price_set_used_by', |
724 | "it is currently in use by one or more active events or contribution pages or contributions or event templates."); | |
9669d0f3 RN |
725 | } |
726 | ||
7f587af0 | 727 | function _checkLineItems($expectedLineItems) { |
76e86fd8 | 728 | foreach ($expectedLineItems as $lineKey => $lineValue) { |
76e86fd8 | 729 | foreach ($lineValue as $key => $value) { |
7f587af0 PN |
730 | $this->verifyText("xpath=//table/tbody/tr/td[text()='Event Fees']/following-sibling::td/table/tbody/tr[$lineKey]/td[$key]", preg_quote($value)); |
731 | } | |
732 | } | |
733 | } | |
6a488035 TO |
734 | } |
735 |