Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 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 | ||
00be9182 | 38 | public 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 | */ | |
00be9182 | 73 | public 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 | */ | |
00be9182 | 98 | public 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( | |
6c6e6187 | 121 | 1 => array( |
92915c55 | 122 | 'label' => 'Chicken', |
6a488035 | 123 | 'amount' => '30.00', |
21dfd5f5 | 124 | 'financial_type_id' => 'Donation', |
6a488035 TO |
125 | ), |
126 | 2 => array( | |
127 | 'label' => 'Vegetarian', | |
128 | 'amount' => '25.00', | |
21dfd5f5 | 129 | 'financial_type_id' => 'Donation', |
6a488035 TO |
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( | |
6c6e6187 | 140 | 1 => array( |
92915c55 | 141 | 'label' => 'Yes', |
6a488035 | 142 | 'amount' => '50.00', |
21dfd5f5 | 143 | 'financial_type_id' => 'Donation', |
76e86fd8 | 144 | |
92915c55 | 145 | ), |
6a488035 TO |
146 | 2 => array( |
147 | 'label' => 'No', | |
148 | 'amount' => '0', | |
21dfd5f5 | 149 | 'financial_type_id' => 'Donation', |
6a488035 TO |
150 | ), |
151 | ); | |
152 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
3e60ff7f | 153 | $this->click('is_required'); |
6a488035 TO |
154 | if ($dateSpecificFields == TRUE) { |
155 | $this->webtestFillDateTime('active_on', '-1 week'); | |
156 | } | |
157 | break; | |
158 | ||
159 | case 'CheckBox': | |
160 | $options = array( | |
6c6e6187 | 161 | 1 => array( |
92915c55 | 162 | 'label' => 'First Night', |
6a488035 | 163 | 'amount' => '15.00', |
21dfd5f5 | 164 | 'financial_type_id' => 'Donation', |
6a488035 TO |
165 | ), |
166 | 2 => array( | |
167 | 'label' => 'Second Night', | |
168 | 'amount' => '15.00', | |
21dfd5f5 | 169 | 'financial_type_id' => 'Donation', |
6a488035 TO |
170 | ), |
171 | ); | |
172 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
173 | if ($dateSpecificFields == TRUE) { | |
174 | $this->webtestFillDateTime('expire_on', '+1 week'); | |
175 | } | |
176 | break; | |
177 | ||
178 | default: | |
179 | break; | |
180 | } | |
52b7da1c | 181 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE); |
92fcb95f | 182 | $this->waitForText('crm-notification-container', "Price Field '" . $label . "' has been saved."); |
6a488035 TO |
183 | } |
184 | } | |
185 | ||
4cbe18b8 EM |
186 | /** |
187 | * @param $validateStrings | |
100fef9d | 188 | * @param int $sid |
4cbe18b8 | 189 | */ |
00be9182 | 190 | public function _testVerifyPriceSet($validateStrings, $sid) { |
6a488035 TO |
191 | // verify Price Set at Preview page |
192 | // start at Manage Price Sets listing | |
a9f5275d | 193 | $this->openCiviPage('admin/price', 'reset=1'); |
6a488035 TO |
194 | |
195 | // Use the price set id ($sid) to pick the correct row | |
52b7da1c | 196 | $this->clickLink("//*[@id='price_set-{$sid}']/td[4]/span[1]/a[2]", '_qf_Preview_cancel-bottom', FALSE); |
6a488035 TO |
197 | |
198 | // Check for expected price set field strings | |
b87dcbda | 199 | if ($this->isElementPresent("xpath=//*[@class ='select2-chosen']")) { |
200 | $this->clickAt("xpath=//*[@class ='select2-chosen']"); | |
201 | } | |
6a488035 TO |
202 | $this->assertStringsPresent($validateStrings); |
203 | } | |
204 | ||
00be9182 | 205 | public function testRegisterWithPriceSet() { |
6a488035 TO |
206 | // Log in using webtestLogin() method |
207 | $this->webtestLogin(); | |
208 | ||
209 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); | |
42daf119 CW |
210 | $usedFor = 'Event'; |
211 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
212 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
213 | ||
214 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
215 | // which is where we are after adding Price Set. | |
a471a3b6 | 216 | $sid = $this->urlArg('sid'); |
6a488035 TO |
217 | $this->assertType('numeric', $sid); |
218 | ||
219 | $validStrings = array(); | |
220 | $fields = array( | |
221 | 'Full Conference' => 'Text', | |
6a488035 TO |
222 | 'Pre-conference Meetup?' => 'Radio', |
223 | 'Evening Sessions' => 'CheckBox', | |
224 | ); | |
225 | $this->_testAddPriceFields($fields, $validateStrings); | |
226 | ||
227 | // load the Price Set Preview and check for expected values | |
228 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
229 | ||
c3ad8633 CW |
230 | // Use default payment processor |
231 | $processorName = 'Test Processor'; | |
6a488035 TO |
232 | $this->webtestAddPaymentProcessor($processorName); |
233 | ||
8b67c4d0 | 234 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
6a488035 | 235 | |
42daf119 CW |
236 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
237 | $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com'; | |
6a488035 TO |
238 | $eventDescription = 'Here is a description for this conference.'; |
239 | ||
6a488035 TO |
240 | $this->select('event_type_id', 'value=1'); |
241 | ||
242 | // Attendee role s/b selected now. | |
243 | $this->select('default_role_id', 'value=1'); | |
244 | ||
245 | // Enter Event Title, Summary and Description | |
246 | $this->type('title', $eventTitle); | |
247 | $this->type('summary', 'This is a great conference. Sign up now!'); | |
248 | ||
249 | // Type description in ckEditor (fieldname, text to type, editor) | |
250 | $this->fillRichTextField('description', $eventDescription); | |
251 | ||
252 | // Choose Start and End dates. | |
253 | // Using helper webtestFillDate function. | |
254 | $this->webtestFillDateTime("start_date", "+1 week"); | |
255 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); | |
256 | ||
257 | $this->type('max_participants', '50'); | |
258 | $this->click('is_map'); | |
259 | $this->click('_qf_EventInfo_upload-bottom'); | |
260 | ||
261 | // Wait for Location tab form to load | |
3379d026 | 262 | $this->waitForElementPresent('_qf_Location_upload_done-bottom'); |
6a488035 TO |
263 | |
264 | // Go to Fees tab | |
265 | $this->click('link=Fees'); | |
3379d026 | 266 | $this->waitForElementPresent('_qf_Fee_upload_done-bottom'); |
6a488035 | 267 | $this->click('CIVICRM_QFID_1_is_monetary'); |
a90dac23 | 268 | $this->select2('payment_processor', $processorName, TRUE); |
389bcebf | 269 | $this->select('financial_type_id', 'label=Event Fee'); |
6a488035 TO |
270 | $this->select('price_set_id', 'label=' . $setTitle); |
271 | ||
6a488035 TO |
272 | // intro text for registration page |
273 | $registerIntro = 'Fill in all the fields below and click Continue.'; | |
3379d026 | 274 | $this->clickLink('_qf_Fee_upload-bottom', 'link=Online Registration', FALSE); |
6a488035 TO |
275 | |
276 | // Go to Online Registration tab | |
277 | $this->click('link=Online Registration'); | |
278 | $this->waitForElementPresent('_qf_Registration_upload-bottom'); | |
279 | ||
280 | $this->check('is_online_registration'); | |
281 | $this->assertChecked('is_online_registration'); | |
282 | ||
e390a377 | 283 | $this->fillRichTextField('intro_text', $registerIntro, 'CKEditor', TRUE); |
6a488035 TO |
284 | |
285 | // enable confirmation email | |
286 | $this->click('CIVICRM_QFID_1_is_email_confirm'); | |
287 | $this->type('confirm_from_name', 'Jane Doe'); | |
288 | $this->type('confirm_from_email', 'jane.doe@example.org'); | |
289 | ||
290 | $this->click('_qf_Registration_upload-bottom'); | |
3379d026 | 291 | $this->waitForTextPresent("'Online Registration' information has been saved."); |
6a488035 TO |
292 | |
293 | // verify event input on info page | |
294 | // start at Manage Events listing | |
a9f5275d | 295 | $this->openCiviPage('event/manage', 'reset=1'); |
6a488035 TO |
296 | $this->click("link=$eventTitle"); |
297 | ||
298 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
299 | $eventInfoUrl = $this->getLocation(); | |
300 | ||
3379d026 | 301 | $permissions = array("edit-1-register-for-events"); |
302 | $this->changePermissions($permissions); | |
42daf119 | 303 | $this->webtestLogout(); |
6a488035 TO |
304 | $this->open($eventInfoUrl); |
305 | $this->click('link=Register Now'); | |
306 | $this->waitForElementPresent('_qf_Register_upload-bottom'); | |
307 | ||
3379d026 | 308 | $this->type("xpath=//input[@class='four crm-form-text required']", "1"); |
309 | $this->click("xpath=//input[@class='crm-form-radio']"); | |
310 | $this->click("xpath=//input[@class='crm-form-checkbox']"); | |
70452444 | 311 | $this->type("first_name", "Jane"); |
312 | $lastName = "Smith" . substr(sha1(rand()), 0, 7); | |
313 | $this->type("last_name", $lastName); | |
6a488035 TO |
314 | $this->type('email-Primary', $email); |
315 | ||
316 | $this->waitForElementPresent('credit_card_type'); | |
317 | $this->select('credit_card_type', 'value=Visa'); | |
318 | $this->type('credit_card_number', '4111111111111111'); | |
319 | $this->type('cvv2', '000'); | |
320 | $this->select('credit_card_exp_date[M]', 'value=1'); | |
321 | $this->select('credit_card_exp_date[Y]', 'value=2020'); | |
322 | $this->type('billing_first_name', 'Jane'); | |
70452444 | 323 | $this->type('billing_last_name', $lastName); |
6a488035 TO |
324 | $this->type('billing_street_address-5', '15 Main St.'); |
325 | $this->type(' billing_city-5', 'San Jose'); | |
326 | $this->select('billing_country_id-5', 'value=1228'); | |
327 | $this->select('billing_state_province_id-5', 'value=1004'); | |
328 | $this->type('billing_postal_code-5', '94129'); | |
329 | ||
225a8648 | 330 | $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom'); |
6a488035 TO |
331 | $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information'); |
332 | $this->assertStringsPresent($confirmStrings); | |
333 | $this->click('_qf_Confirm_next-bottom'); | |
334 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
335 | $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date'); | |
336 | $this->assertStringsPresent($thankStrings); | |
337 | ||
6a488035 TO |
338 | // Log in using webtestLogin() method |
339 | $this->webtestLogin(); | |
340 | ||
341 | //Find Participant | |
8b67c4d0 | 342 | $this->openCiviPage('event/search', 'reset=1', '_qf_Search_refresh'); |
6a488035 TO |
343 | |
344 | $this->type('sort_name', "$email"); | |
225a8648 | 345 | $this->clickLink('_qf_Search_refresh', "xpath=id('participantSearch')/table/tbody/tr/td[11]/span/a[text()='View']"); |
6a488035 TO |
346 | $this->click("xpath=id('participantSearch')/table/tbody/tr/td[11]/span/a[text()='View']"); |
347 | $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom'); | |
348 | ||
349 | $expected = array( | |
350 | 2 => 'Full Conference', | |
351 | 3 => 'Pre-conference Meetup? - Yes', | |
352 | 4 => 'Evening Sessions - First Night', | |
353 | ); | |
354 | foreach ($expected as $value => $label) { | |
3379d026 | 355 | $this->verifyText("xpath=id('ParticipantView')/div[2]/table[1]/tbody/tr[8]/td[2]/table/tbody/tr[$value]/td", $label); |
6a488035 TO |
356 | } |
357 | // Fixme: We can't asset full string like - "Event Total: $ 590.00" as it has special char | |
358 | $this->assertStringsPresent(' 590.00'); | |
359 | $this->click('_qf_ParticipantView_cancel-bottom'); | |
360 | } | |
361 | ||
00be9182 | 362 | public function testParticipantWithDateSpecificPriceSet() { |
6a488035 TO |
363 | |
364 | // Log in using webtestLogin() method | |
365 | $this->webtestLogin(); | |
366 | ||
367 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); | |
42daf119 CW |
368 | $usedFor = 'Event'; |
369 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
370 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
371 | ||
372 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
373 | // which is where we are after adding Price Set. | |
a471a3b6 | 374 | $sid = $this->urlArg('sid'); |
6a488035 TO |
375 | $this->assertType('numeric', $sid); |
376 | ||
377 | $validStrings = array(); | |
378 | $fields = array( | |
379 | 'Full Conference' => 'Text', | |
6a488035 TO |
380 | 'Pre-conference Meetup?' => 'Radio', |
381 | 'Evening Sessions' => 'CheckBox', | |
382 | ); | |
383 | $this->_testAddPriceFields($fields, $validateStrings, TRUE); | |
384 | ||
385 | // load the Price Set Preview and check for expected values | |
386 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
387 | ||
c3ad8633 CW |
388 | // Use default payment processor |
389 | $processorName = 'Test Processor'; | |
6a488035 TO |
390 | $this->webtestAddPaymentProcessor($processorName); |
391 | ||
8b67c4d0 | 392 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
6a488035 | 393 | |
42daf119 CW |
394 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
395 | $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com'; | |
6a488035 TO |
396 | $eventDescription = 'Here is a description for this conference.'; |
397 | ||
6a488035 TO |
398 | $this->select('event_type_id', 'value=1'); |
399 | ||
400 | // Attendee role s/b selected now. | |
401 | $this->select('default_role_id', 'value=1'); | |
402 | ||
403 | // Enter Event Title, Summary and Description | |
404 | $this->type('title', $eventTitle); | |
405 | $this->type('summary', 'This is a great conference. Sign up now!'); | |
406 | ||
407 | // Type description in ckEditor (fieldname, text to type, editor) | |
481a74f4 | 408 | $this->fillRichTextField('description', $eventDescription); |
6a488035 TO |
409 | |
410 | // Choose Start and End dates. | |
411 | // Using helper webtestFillDate function. | |
412 | $this->webtestFillDateTime("start_date", "+1 week"); | |
413 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); | |
414 | ||
415 | $this->type('max_participants', '50'); | |
416 | $this->click('is_map'); | |
417 | $this->click('_qf_EventInfo_upload-bottom'); | |
418 | ||
419 | // Wait for Location tab form to load | |
420 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
421 | ||
422 | // Go to Fees tab | |
423 | $this->click('link=Fees'); | |
424 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); | |
425 | $this->click('CIVICRM_QFID_1_is_monetary'); | |
a90dac23 | 426 | $this->select2('payment_processor', $processorName, TRUE); |
6c6e6187 | 427 | $this->select('financial_type_id', 'label=Event Fee'); |
6a488035 TO |
428 | $this->select('price_set_id', 'label=' . $setTitle); |
429 | ||
3379d026 | 430 | $this->clickLink('_qf_Fee_upload-bottom', 'link=Online Registration', FALSE); |
6a488035 TO |
431 | |
432 | // intro text for registration page | |
433 | $registerIntro = 'Fill in all the fields below and click Continue.'; | |
434 | ||
435 | // Go to Online Registration tab | |
436 | $this->click('link=Online Registration'); | |
437 | $this->waitForElementPresent('_qf_Registration_upload-bottom'); | |
438 | ||
439 | $this->check('is_online_registration'); | |
440 | $this->assertChecked('is_online_registration'); | |
441 | ||
e390a377 | 442 | $this->fillRichTextField('intro_text', $registerIntro, 'CKEditor', TRUE); |
6a488035 TO |
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); | |
86bfa4f6 | 461 | $lastName = 'Anderson' . substr(sha1(rand()), 0, 7); |
5f0e3af6 DG |
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 | |
ca0cdd20 | 494 | $this->waitForElementPresent("xpath=//form[@class='CRM_Event_Form_Search crm-search-form']/table//tbody/tr[1]/td[8]/span/a[text()='View']"); |
6a488035 TO |
495 | |
496 | //click through to the participant view screen | |
ca0cdd20 | 497 | $this->click("xpath=//form[@class='CRM_Event_Form_Search crm-search-form']/table/tbody/tr[1]/td[8]/span/a[text()='View']"); |
e7066c8e | 498 | $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]"); |
6a488035 | 499 | } |
7f587af0 PN |
500 | |
501 | /** | |
100fef9d | 502 | * Test to regiter participant for event with |
7f587af0 | 503 | * multiple price fields in price-set |
76e86fd8 CW |
504 | * CRM-11986 |
505 | ||
7f587af0 | 506 | */ |
00be9182 | 507 | public function testEventWithPriceSet() { |
7f587af0 PN |
508 | // Log in using webtestLogin() method |
509 | $this->webtestLogin(); | |
76e86fd8 | 510 | |
7f587af0 PN |
511 | // Adding contact with randomized first name (so we can then select that contact when creating event registration) |
512 | // We're using Quick Add block on the main page for this. | |
513 | $firstName = substr(sha1(rand()), 0, 7); | |
86bfa4f6 | 514 | $lastName = 'Anderson' . substr(sha1(rand()), 0, 7); |
5f0e3af6 DG |
515 | $this->webtestAddContact($firstName, $lastName, TRUE); |
516 | $contactName = "$lastName, $firstName"; | |
517 | $displayName = "$firstName $lastName"; | |
76e86fd8 | 518 | |
7f587af0 | 519 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
520 | $usedFor = 'Event'; |
521 | $setHelp = 'Select your conference options.'; | |
7f587af0 PN |
522 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
523 | ||
524 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
525 | // which is where we are after adding Price Set. | |
a471a3b6 | 526 | $sid = $this->urlArg('sid'); |
7f587af0 PN |
527 | $this->assertType('numeric', $sid); |
528 | ||
529 | $validStrings = array(); | |
530 | $fields = array( | |
531 | 'Full Conference' => 'Text', | |
532 | 'Pre-conference Meetup?' => 'Radio', | |
533 | 'Evening Sessions' => 'CheckBox', | |
534 | ); | |
535 | $this->_testAddPriceFields($fields, $validateStrings); | |
76e86fd8 | 536 | |
7f587af0 PN |
537 | // load the Price Set Preview and check for expected values |
538 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
42daf119 | 539 | |
8b67c4d0 | 540 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
80ba1424 | 541 | $this->waitForElementPresent("_qf_EventInfo_upload-bottom"); |
42daf119 CW |
542 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
543 | $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com'; | |
7f587af0 | 544 | $eventDescription = 'Here is a description for this conference.'; |
7f587af0 | 545 | |
7f587af0 | 546 | $this->select('event_type_id', 'value=1'); |
76e86fd8 | 547 | |
7f587af0 PN |
548 | // Attendee role s/b selected now. |
549 | $this->select('default_role_id', 'value=1'); | |
76e86fd8 | 550 | |
7f587af0 PN |
551 | // Enter Event Title, Summary and Description |
552 | $this->type('title', $eventTitle); | |
553 | $this->type('summary', 'This is a great conference. Sign up now!'); | |
76e86fd8 | 554 | |
7f587af0 PN |
555 | // Type description in ckEditor (fieldname, text to type, editor) |
556 | $this->fillRichTextField('description', $eventDescription); | |
76e86fd8 | 557 | |
7f587af0 PN |
558 | // Choose Start and End dates. |
559 | // Using helper webtestFillDate function. | |
560 | $this->webtestFillDateTime("start_date", "+1 week"); | |
561 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); | |
562 | ||
563 | $this->type('max_participants', '50'); | |
564 | $this->click('is_map'); | |
565 | $this->click('_qf_EventInfo_upload-bottom'); | |
566 | ||
567 | // Wait for Location tab form to load | |
568 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
569 | ||
570 | // Go to Fees tab | |
571 | $this->click('link=Fees'); | |
572 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); | |
573 | $this->click('CIVICRM_QFID_1_is_monetary'); | |
6c6e6187 | 574 | $this->select('financial_type_id', 'label=Event Fee'); |
7f587af0 | 575 | $this->select('price_set_id', 'label=' . $setTitle); |
76e86fd8 | 576 | |
7f587af0 | 577 | $this->click('_qf_Fee_upload-bottom'); |
6c6e6187 | 578 | $this->waitForText("crm-notification-container", "'Fees' information has been saved."); |
38653166 | 579 | $this->waitForAjaxContent(); |
7f587af0 | 580 | |
42daf119 | 581 | $this->openCiviPage('participant/add', 'reset=1&action=add&context=standalone', '_qf_Participant_upload-bottom'); |
7f587af0 | 582 | |
7f587af0 PN |
583 | // Type contact last name in contact auto-complete, wait for dropdown and click first result |
584 | $this->webtestFillAutocomplete($firstName); | |
9ffaaf79 | 585 | $this->select2('event_id', $eventTitle); |
7f587af0 | 586 | // Select role |
e6c6db94 | 587 | $this->multiselect2('role_id', array('Volunteer')); |
76e86fd8 | 588 | |
7f587af0 PN |
589 | // Choose Registration Date. |
590 | // Using helper webtestFillDate function. | |
591 | $this->webtestFillDate('register_date', 'now'); | |
592 | $today = date('F jS, Y', strtotime('now')); | |
593 | // May 5th, 2010 | |
76e86fd8 | 594 | |
7f587af0 PN |
595 | // Select participant status |
596 | $this->select('status_id', 'value=1'); | |
597 | ||
598 | // Setting registration source | |
599 | $this->type('source', 'Event StandaloneAddTest Webtest'); | |
76e86fd8 | 600 | |
7f587af0 | 601 | // Select an event fee |
4cbbec00 | 602 | $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/input"); |
60ad1b50 RK |
603 | $this->type("xpath=//div[@id='priceset']/div[2]/div[2]/input", '5'); |
604 | $this->fireEvent("xpath=//div[@id='priceset']/div[2]/div[2]/input", 'blur'); | |
605 | $this->waitForElementPresent("xpath=//div[@id='priceset']/div[3]/div[2]/div[1]/span/input"); | |
3bbf7318 | 606 | $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[1]/span/input"); |
607 | $this->click("xpath=//div[@id='priceset']/div[4]/div[2]/div[1]/span/input"); | |
608 | $this->click("xpath=//div[@id='priceset']/div[4]/div[2]/div[2]/span/input"); | |
76e86fd8 | 609 | |
7f587af0 PN |
610 | // Select payment method = Check and enter chk number |
611 | $this->select('payment_instrument_id', 'value=4'); | |
612 | $this->waitForElementPresent('check_number'); | |
76e86fd8 CW |
613 | $this->type('check_number', '1044'); |
614 | ||
7f587af0 PN |
615 | // Clicking save. |
616 | $this->click('_qf_Participant_upload-bottom'); | |
617 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
76e86fd8 | 618 | |
7f587af0 | 619 | // Is status message correct? |
7df6dc24 | 620 | $this->waitForText("crm-notification-container", "Event registration for $displayName has been added"); |
76e86fd8 | 621 | |
c543dff8 | 622 | $this->waitForElementPresent("xpath=//form[@id='Search']/table/tbody/tr[1]/td[8]/span//a[text()='View']"); |
7f587af0 | 623 | //click through to the participant view screen |
c543dff8 | 624 | $this->click("xpath=//form[@id='Search']/table/tbody/tr[1]/td[8]/span//a[text()='View']"); |
7f587af0 | 625 | $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom'); |
76e86fd8 | 626 | |
7f587af0 PN |
627 | $this->webtestVerifyTabularData( |
628 | array( | |
629 | 'Event' => $eventTitle, | |
630 | 'Participant Role' => 'Attendee', | |
631 | 'Status' => 'Registered', | |
632 | 'Event Source' => 'Event StandaloneAddTest Webtest', | |
7f587af0 PN |
633 | ) |
634 | ); | |
e6c6db94 | 635 | $this->waitForElementPresent("xpath=//table/tbody/tr/td[text()='Fees']/following-sibling::td"); |
ba4a1892 | 636 | $this->verifyText("xpath=//table/tbody/tr/td[text()='Fees']/following-sibling::td/table/tbody/tr[2]/td", preg_quote('$ 2,705.00')); |
7f587af0 PN |
637 | $expectedLineItems = array( |
638 | 2 => array( | |
c19f150e | 639 | 1 => 'Full Conference ', |
7f587af0 PN |
640 | 2 => '5', |
641 | 3 => '$ 525.00', | |
642 | 4 => '$ 2,625.00', | |
643 | ), | |
644 | 3 => array( | |
645 | 2 => '1', | |
646 | 3 => '$ 50.00', | |
647 | 4 => '$ 50.00', | |
648 | ), | |
649 | 4 => array( | |
c19f150e | 650 | 1 => 'Evening Sessions - First Night ', |
7f587af0 PN |
651 | 2 => '1', |
652 | 3 => '$ 15.00', | |
653 | 4 => '$ 15.00', | |
654 | ), | |
655 | 5 => array( | |
c19f150e | 656 | 1 => 'Evening Sessions - Second Night ', |
7f587af0 PN |
657 | 2 => '1', |
658 | 3 => '$ 15.00', | |
659 | 4 => '$ 15.00', | |
660 | ), | |
661 | ); | |
662 | $this->_checkLineItems($expectedLineItems); | |
663 | // check contribution record as well | |
664 | // click through to the contribution view screen | |
c543dff8 | 665 | $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span//a[text()='View']"); |
7f587af0 PN |
666 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); |
667 | ||
668 | $this->webtestVerifyTabularData( | |
669 | array( | |
670 | 'From' => $displayName, | |
671 | 'Financial Type' => 'Event Fee', | |
672 | 'Contribution Status' => 'Completed', | |
4db803dd | 673 | 'Payment Method' => 'Check', |
7f587af0 | 674 | 'Check Number' => '1044', |
7f587af0 PN |
675 | 'Received Into' => 'Deposit Bank Account', |
676 | ) | |
677 | ); | |
60709d21 | 678 | $this->verifyText("xpath=//td[text()='Contribution Amount']/following-sibling::td//div/div", preg_quote('Contribution Total: $ 2,705.00')); |
eb36fd7a | 679 | |
680 | // CRM-17182 - Rename the price option and check the same in Find Participants | |
681 | $this->openCiviPage('admin/price/field', "reset=1&action=browse&sid={$sid}", 'newPriceField'); | |
682 | $this->click("xpath=//table[@id='options']/tbody/tr[3]/td[8]/a[text()='Edit Price Options']"); | |
683 | $this->waitForElementPresent("xpath=//span[contains(text(), 'Done')]"); | |
c543dff8 | 684 | $this->click("xpath=//table[@id='options']/tbody/tr/td/div[text()='First Night']/../following-sibling::td[8]/span//a[text()='Edit Option']"); |
eb36fd7a | 685 | $this->waitForElementPresent("_qf_Option_cancel"); |
686 | $this->type('label', 'First Night Edited'); | |
687 | $this->click('_qf_Option_next'); | |
688 | $this->waitForText('crm-notification-container', "The option 'First Night Edited' has been saved."); | |
689 | ||
690 | $this->openCiviPage('event/search', "reset=1", '_qf_Search_refresh'); | |
691 | $this->select2('participant_fee_id', 'First Night Edited'); | |
c543dff8 | 692 | $this->click('_qf_Search_refresh'); |
4dc8abb7 WA |
693 | $this->waitForAjaxContent(); |
694 | $this->clickLink("xpath=//form[@class='CRM_Event_Form_Search crm-search-form']//div[3]/div/div[2]//table//tbody/tr[1]/td[11]/span//a[text()='View']", "xpath=//span[contains(text(), 'Done')]", FALSE); | |
eb36fd7a | 695 | $expectedLineItems[4][1] = 'Evening Sessions - First Night Edited'; |
696 | $this->_checkLineItems($expectedLineItems); | |
7f587af0 | 697 | } |
76e86fd8 | 698 | |
9669d0f3 | 699 | |
00be9182 | 700 | public function testDeletePriceSetforEventTemplate() { |
a49e5dea | 701 | $this->markTestSkipped('Skipping for now as it works fine locally.'); |
9669d0f3 RN |
702 | // Log in using webtestLogin() method |
703 | $this->webtestLogin(); | |
4cbe18b8 | 704 | |
9669d0f3 RN |
705 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
706 | $usedFor = 'Event'; | |
707 | $setHelp = 'Select your conference options.'; | |
708 | $this->_testAddSet($setTitle, $usedFor, $setHelp); | |
4cbe18b8 | 709 | |
9669d0f3 RN |
710 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form |
711 | // which is where we are after adding Price Set. | |
712 | $sid = $this->urlArg('sid'); | |
713 | $this->assertType('numeric', $sid); | |
4cbe18b8 | 714 | |
9669d0f3 RN |
715 | $validStrings = array(); |
716 | $fields = array( | |
717 | 'Test Field' => 'Text', | |
718 | ); | |
719 | $this->_testAddPriceFields($fields, $validateStrings); | |
720 | ||
721 | // load the Price Set Preview and check for expected values | |
722 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
723 | $this->openCiviPage('admin/eventTemplate', 'reset=1'); | |
724 | $this->clickLink('newEventTemplate'); | |
725 | $this->select("template_id", "value=6"); | |
726 | // Wait for event type to be filled in (since page reloads) | |
3379d026 | 727 | $this->waitForElementPresent("template_id"); |
9669d0f3 | 728 | // Enter Event Title, Summary and Description |
3379d026 | 729 | $this->select("event_type_id", "value=4"); |
730 | $this->select("default_role_id", "value=1"); | |
ea83a78e | 731 | $this->waitForAjaxContent(); |
0391e7ab | 732 | $this->type("title", "Test Event"); |
9669d0f3 | 733 | $this->type("summary", "This is a great conference. Sign up now!"); |
4cbe18b8 | 734 | |
3379d026 | 735 | $this->click("_qf_EventInfo_upload-bottom"); |
736 | $this->waitForElementPresent('link=Fees'); | |
9669d0f3 RN |
737 | // Go to Fees tab |
738 | $this->click('link=Fees'); | |
739 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); | |
740 | $this->click('CIVICRM_QFID_1_is_monetary'); | |
6c6e6187 | 741 | $this->select('financial_type_id', 'label=Event Fee'); |
9669d0f3 RN |
742 | $this->select('price_set_id', 'label=' . $setTitle); |
743 | $templateId = $this->urlArg('id'); | |
3379d026 | 744 | $this->click('_qf_Fee_upload-bottom'); |
4cbe18b8 | 745 | |
9669d0f3 RN |
746 | //check the delete for price field |
747 | $this->openCiviPage("admin/price/field", "reset=1&action=browse&sid={$sid}"); | |
4cbbec00 | 748 | $this->waitForElementPresent("xpath=//table[@id='options']/tbody/tr/td[9]/span[2]"); |
3c926399 | 749 | $this->click("xpath=//table[@id='options']/tbody/tr/td[9]/span[2]/ul[@class='panel']/li[2]//a[text()='Delete']"); |
9669d0f3 | 750 | //assert the message |
38653166 | 751 | $this->waitForText('price_set_used_by', "it is currently in use by one or more active events or contribution pages or contributions or event templates. If you no longer want to use this price set, click the event title below, and modify the fees for that event."); |
4cbe18b8 | 752 | |
9669d0f3 RN |
753 | //check the delete for priceset |
754 | $this->openCiviPage("admin/price", "reset=1"); | |
ca0cdd20 | 755 | $this->waitForElementPresent("xpath=//table[@class='display crm-price-set-listing dataTable no-footer']/tbody/tr/td[4]/span[2]"); |
3c926399 | 756 | $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[4]/span[2]/ul/li[3]//a[text()='Delete']"); |
9669d0f3 | 757 | // Check confirmation alert. |
6c6e6187 | 758 | $this->assertTrue((bool) preg_match("/^Are you sure you want to delete this price set?/", |
9669d0f3 RN |
759 | $this->getConfirmation() |
760 | )); | |
761 | $this->chooseOkOnNextConfirmation(); | |
762 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
763 | //assert the message | |
5be3afb2 | 764 | $this->waitForText('price_set_used_by', |
765 | "it is currently in use by one or more active events or contribution pages or contributions or event templates."); | |
9669d0f3 | 766 | } |
4cbe18b8 EM |
767 | |
768 | /** | |
100fef9d | 769 | * @param array $expectedLineItems |
4cbe18b8 | 770 | */ |
00be9182 | 771 | public function _checkLineItems($expectedLineItems) { |
76e86fd8 | 772 | foreach ($expectedLineItems as $lineKey => $lineValue) { |
76e86fd8 | 773 | foreach ($lineValue as $key => $value) { |
9ffaaf79 | 774 | $this->verifyText("xpath=//table/tbody//tr/td[text()='Selections']/following-sibling::td/table/tbody//tr[$lineKey]/td[$key]", preg_quote($value)); |
7f587af0 PN |
775 | } |
776 | } | |
777 | } | |
96025800 | 778 | |
6a488035 | 779 | } |