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