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