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_ParticipantCountTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Event_ParticipantCountTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testParticipantCountWithFeelevel() { | |
6a488035 TO |
39 | // Log in using webtestLogin() method |
40 | $this->webtestLogin(); | |
41 | ||
42 | // We need a payment processor | |
43 | $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7); | |
44 | $this->webtestAddPaymentProcessor($processorName); | |
45 | ||
46 | // create an event | |
47 | $eventTitle = 'A Conference - ' . substr(sha1(rand()), 0, 7); | |
48 | $paramsEvent = array( | |
49 | 'title' => $eventTitle, | |
50 | 'template_id' => 6, | |
51 | 'event_type_id' => 4, | |
52 | 'payment_processor' => $processorName, | |
53 | 'fee_level' => array( | |
54 | 'Member' => '250.00', | |
55 | 'Non-Member' => '325.00', | |
56 | ), | |
57 | ); | |
58 | ||
59 | $infoEvent = $this->_testAddEvent($paramsEvent); | |
60 | ||
61 | // logout to register for event. | |
42daf119 | 62 | $this->webtestLogout(); |
6a488035 TO |
63 | |
64 | // Register Participant 1 | |
65 | // visit event info page | |
66 | $this->open($infoEvent); | |
67 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
68 | ||
69 | // register for event | |
70 | $this->click('link=Register Now'); | |
71 | $this->waitForElementPresent('_qf_Register_upload-bottom'); | |
ed174dea | 72 | $this->click("xpath=//input[@class='crm-form-radio']"); |
6a488035 TO |
73 | |
74 | $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org'; | |
1eb0391e | 75 | $this->type('first_name', 'Mary'); |
76 | $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5)); | |
6a488035 TO |
77 | $this->type('email-Primary', $email); |
78 | ||
79 | // fill billing details and register | |
80 | $this->_testRegisterWithBillingInfo(); | |
81 | ||
82 | // Register Participant 2 | |
83 | // visit event info page | |
84 | $this->open($infoEvent); | |
85 | ||
86 | // register for event | |
87 | $this->click('link=Register Now'); | |
88 | $this->waitForElementPresent('_qf_Register_upload-bottom'); | |
89 | ||
ed174dea | 90 | $this->click("xpath=//input[@class='crm-form-radio']"); |
6a488035 | 91 | $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org'; |
1eb0391e | 92 | $this->type('first_name', 'Mary'); |
93 | $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5)); | |
6a488035 TO |
94 | $this->type('email-Primary', $email); |
95 | ||
96 | // fill billing details and register | |
97 | $this->_testRegisterWithBillingInfo(); | |
98 | ||
99 | // login to check participant count | |
6a488035 TO |
100 | $this->webtestLogin(); |
101 | ||
102 | // Find Participant | |
42daf119 | 103 | $this->openCiviPage("event/search", "reset=1", 'participant_fee_amount_low'); |
ed174dea | 104 | $this->select2("event_id", $eventTitle); |
6a488035 TO |
105 | $this->click('_qf_Search_refresh'); |
106 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
107 | ||
108 | // verify number of registered participants | |
109 | $this->assertStringsPresent(array('2 Result')); | |
110 | } | |
111 | ||
112 | function testParticipantCountWithPriceset() { | |
6a488035 TO |
113 | // Log in using webtestLogin() method |
114 | $this->webtestLogin(); | |
115 | ||
116 | // We need a payment processor | |
117 | $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7); | |
118 | $this->webtestAddPaymentProcessor($processorName); | |
119 | ||
120 | // create priceset | |
121 | $priceset = 'Price - ' . substr(sha1(rand()), 0, 7); | |
122 | $this->_testAddSet($priceset); | |
123 | ||
124 | // create price fields | |
125 | $fields = array( | |
d17310e4 | 126 | 'Full Conference' => array( |
127 | 'type' => 'Text', | |
6a488035 TO |
128 | 'amount' => '525.00', |
129 | 'count' => '2', | |
130 | ), | |
131 | 'Meal Choice' => array( | |
132 | 'type' => 'Select', | |
133 | 'options' => array( | |
d17310e4 | 134 | 1 => array( |
135 | 'label' => 'Chicken', | |
6a488035 TO |
136 | 'amount' => '525.00', |
137 | 'count' => '2', | |
138 | ), | |
139 | 2 => array( | |
140 | 'label' => 'Vegetarian', | |
141 | 'amount' => '200.00', | |
142 | 'count' => '2', | |
143 | ), | |
144 | ), | |
145 | ), | |
146 | 'Pre-conference Meetup?' => array( | |
147 | 'type' => 'Radio', | |
148 | 'options' => array( | |
d17310e4 | 149 | 1 => array( |
150 | 'label' => 'Yes', | |
6a488035 TO |
151 | 'amount' => '50.00', |
152 | 'count' => '2', | |
153 | ), | |
154 | 2 => array( | |
155 | 'label' => 'No', | |
156 | 'amount' => '0', | |
157 | ), | |
158 | ), | |
159 | ), | |
160 | 'Evening Sessions' => array( | |
161 | 'type' => 'CheckBox', | |
162 | 'options' => array( | |
d17310e4 | 163 | 1 => array( |
164 | 'label' => 'First Five', | |
6a488035 TO |
165 | 'amount' => '100.00', |
166 | 'count' => '5', | |
167 | ), | |
168 | 2 => array( | |
169 | 'label' => 'Second Four', | |
170 | 'amount' => '50.00', | |
171 | 'count' => '4', | |
172 | ), | |
173 | ), | |
174 | ), | |
175 | ); | |
176 | ||
177 | foreach ($fields as $label => $field) { | |
6a488035 TO |
178 | $this->type('label', $label); |
179 | $this->select('html_type', "value={$field['type']}"); | |
180 | ||
181 | if ($field['type'] == 'Text') { | |
182 | $this->type('price', $field['amount']); | |
183 | //yash | |
184 | $this->waitForElementPresent('count'); | |
185 | $this->type('count', $field['count']); | |
186 | $this->check('is_required'); | |
187 | } | |
188 | else { | |
189 | $this->_testAddMultipleChoiceOptions($field['options']); | |
190 | } | |
225a8648 | 191 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom'); |
6a488035 TO |
192 | } |
193 | ||
194 | // create event. | |
195 | $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7); | |
196 | $paramsEvent = array( | |
197 | 'title' => $eventTitle, | |
198 | 'template_id' => 6, | |
199 | 'event_type_id' => 4, | |
200 | 'payment_processor' => $processorName, | |
201 | 'price_set' => $priceset, | |
202 | ); | |
203 | ||
204 | $infoEvent = $this->_testAddEvent($paramsEvent); | |
205 | ||
206 | // logout to register for event. | |
42daf119 | 207 | $this->webtestLogout(); |
6a488035 TO |
208 | |
209 | $priceFieldOptionCounts = $participants = array(); | |
210 | ||
211 | // Register Participant 1 | |
212 | // visit event info page | |
213 | $this->open($infoEvent); | |
214 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
215 | ||
216 | // register for event | |
217 | $this->click('link=Register Now'); | |
218 | $this->waitForElementPresent('_qf_Register_upload-bottom'); | |
219 | ||
ed174dea | 220 | $this->type("xpath=//input[@class='four crm-form-text required']", '1'); |
6a488035 TO |
221 | |
222 | $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org'; | |
6a488035 TO |
223 | $participants[1] = array( |
224 | 'email' => $email, | |
225 | 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5), | |
226 | 'last_name' => 'San_' . substr(sha1(rand()), 0, 5), | |
227 | ); | |
228 | ||
1eb0391e | 229 | $this->type('first_name', $participants[1]['first_name']); |
230 | $this->type('last_name', $participants[1]['last_name']); | |
231 | $this->type('email-Primary', $email); | |
232 | ||
6a488035 TO |
233 | // fill billing related info and register |
234 | $this->_testRegisterWithBillingInfo($participants[1]); | |
235 | ||
236 | // Options filled by 1st participants. | |
237 | $priceFieldOptionCounts[1] = array( | |
238 | 'Full Conference' => 1, | |
239 | 'Meal Choice - Chicken' => 1, | |
240 | 'Meal Choice - Vegetarian' => 0, | |
241 | 'Pre-conference Meetup? - Yes' => 1, | |
242 | 'Pre-conference Meetup? - No' => 0, | |
243 | 'Evening Sessions - First Five' => 1, | |
244 | 'Evening Sessions - Second Four' => 0, | |
245 | ); | |
246 | ||
247 | // Register Participant 1 | |
248 | // visit event info page | |
249 | $this->open($infoEvent); | |
250 | ||
251 | // register for event | |
252 | $this->click('link=Register Now'); | |
253 | $this->waitForElementPresent('_qf_Register_upload-bottom'); | |
254 | ||
ed174dea | 255 | $this->type("xpath=//input[@class='four crm-form-text required']", '2'); |
6a488035 | 256 | $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org'; |
6a488035 TO |
257 | |
258 | $participants[2] = array( | |
259 | 'email' => $email, | |
260 | 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5), | |
261 | 'last_name' => 'San_' . substr(sha1(rand()), 0, 5), | |
262 | ); | |
263 | ||
1eb0391e | 264 | $this->type('first_name', $participants[2]['first_name']); |
265 | $this->type('last_name', $participants[2]['last_name']); | |
266 | $this->type('email-Primary', $email); | |
267 | ||
6a488035 TO |
268 | // fill billing related info and register |
269 | $this->_testRegisterWithBillingInfo($participants[2]); | |
270 | ||
271 | // Options filled by 2nd participants. | |
272 | $priceFieldOptionCounts[2] = array( | |
273 | 'Full Conference' => 2, | |
274 | 'Meal Choice - Chicken' => 1, | |
275 | 'Meal Choice - Vegetarian' => 0, | |
276 | 'Pre-conference Meetup? - Yes' => 1, | |
277 | 'Pre-conference Meetup? - No' => 0, | |
278 | 'Evening Sessions - First Five' => 1, | |
279 | 'Evening Sessions - Second Four' => 0, | |
280 | ); | |
281 | ||
282 | // login to check participant count | |
6a488035 TO |
283 | $this->webtestLogin(); |
284 | ||
285 | // Find Participant | |
42daf119 | 286 | $this->openCiviPage('event/search', 'reset=1', 'participant_fee_amount_low'); |
ed174dea | 287 | $this->select2("event_id", $eventTitle); |
6a488035 TO |
288 | $this->click('_qf_Search_refresh'); |
289 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
290 | ||
291 | // verify number of participants records and total participant count | |
292 | $this->assertStringsPresent(array('2 Result', 'Actual participant count : 24')); | |
293 | ||
294 | // CRM-7953, check custom search Price Set Details for Event | |
295 | // Participants | |
296 | $this->_testPricesetDetailsCustomSearch($paramsEvent, $participants, $priceFieldOptionCounts); | |
297 | } | |
298 | ||
4cbe18b8 EM |
299 | /** |
300 | * @param $setTitle | |
301 | * @param string $financialType | |
302 | */ | |
6a488035 | 303 | function _testAddSet($setTitle, $financialType = 'Event Fee') { |
42daf119 | 304 | $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom'); |
6a488035 TO |
305 | |
306 | // Enter Priceset fields (Title, Used For ...) | |
307 | $this->type('title', $setTitle); | |
308 | $this->check('extends[1]'); | |
ed174dea | 309 | $this->select("css=select.crm-form-select", "label={$financialType}"); |
6a488035 TO |
310 | $this->type('help_pre', 'This is test priceset.'); |
311 | ||
312 | $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); | |
225a8648 | 313 | $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom'); |
6a488035 TO |
314 | } |
315 | ||
4cbe18b8 EM |
316 | /** |
317 | * @param $options | |
318 | */ | |
6a488035 TO |
319 | function _testAddMultipleChoiceOptions($options) { |
320 | foreach ($options as $oIndex => $oValue) { | |
321 | $this->type("option_label_{$oIndex}", $oValue['label']); | |
322 | $this->type("option_amount_{$oIndex}", $oValue['amount']); | |
323 | if (array_key_exists('count', $oValue)) { | |
324 | $this->waitForElementPresent("option_count_{$oIndex}"); | |
325 | $this->type("option_count_{$oIndex}", $oValue['count']); | |
326 | } | |
327 | $this->click('link=another choice'); | |
328 | } | |
329 | $this->click('CIVICRM_QFID_1_2'); | |
330 | } | |
331 | ||
4cbe18b8 EM |
332 | /** |
333 | * @param $params | |
334 | * | |
335 | * @return string | |
336 | */ | |
6a488035 | 337 | function _testAddEvent($params) { |
42daf119 | 338 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
6a488035 | 339 | |
6a488035 TO |
340 | $this->select('event_type_id', "value={$params['event_type_id']}"); |
341 | ||
342 | // Attendee role s/b selected now. | |
343 | $this->select('default_role_id', 'value=1'); | |
344 | ||
345 | // Enter Event Title, Summary and Description | |
346 | $this->type('title', $params['title']); | |
347 | $this->type('summary', 'This is a great conference. Sign up now!'); | |
348 | $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor'); | |
349 | ||
350 | // Choose Start and End dates. | |
351 | // Using helper webtestFillDate function. | |
352 | $this->webtestFillDateTime('start_date', '+1 week'); | |
353 | $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours '); | |
354 | ||
355 | $this->type('max_participants', '50'); | |
356 | $this->click('is_map'); | |
357 | $this->click('_qf_EventInfo_upload-bottom'); | |
358 | ||
359 | // Wait for Location tab form to load | |
360 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
361 | ||
362 | // Go to Fees tab | |
363 | $this->click('link=Fees'); | |
364 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); | |
365 | $this->click('CIVICRM_QFID_1_is_monetary'); | |
366 | $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='" . $params['payment_processor'] . "']"); | |
d17310e4 | 367 | $this->select('financial_type_id', 'Event Fee'); |
6a488035 TO |
368 | if (array_key_exists('price_set', $params)) { |
369 | $this->select('price_set_id', 'label=' . $params['price_set']); | |
370 | } | |
371 | if (array_key_exists('fee_level', $params)) { | |
372 | $counter = 1; | |
373 | foreach ($params['fee_level'] as $label => $amount) { | |
374 | $this->type("label_{$counter}", $label); | |
375 | $this->type("value_{$counter}", $amount); | |
376 | $counter++; | |
377 | } | |
378 | } | |
379 | ||
380 | $this->click('_qf_Fee_upload-bottom'); | |
ed174dea | 381 | $this->waitForElementPresent('_qf_Fee_cancel-top'); |
6a488035 TO |
382 | |
383 | // Go to Online Registration tab | |
384 | $this->click('link=Online Registration'); | |
385 | $this->waitForElementPresent('_qf_Registration_upload-bottom'); | |
386 | ||
387 | $this->check('is_online_registration'); | |
388 | $this->assertChecked('is_online_registration'); | |
389 | ||
60709d21 | 390 | $this->click('intro_text-plain'); |
6a488035 TO |
391 | $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.'); |
392 | ||
393 | // enable confirmation email | |
394 | $this->click('CIVICRM_QFID_1_is_email_confirm'); | |
395 | $this->type('confirm_from_name', 'Jane Doe'); | |
396 | $this->type('confirm_from_email', 'jane.doe@example.org'); | |
397 | ||
398 | $this->click('_qf_Registration_upload-bottom'); | |
ed174dea | 399 | $this->waitForElementPresent('_qf_Registration_upload-bottom'); |
400 | $this->waitForTextPresent("'Online Registration' information has been saved."); | |
6a488035 TO |
401 | |
402 | // verify event input on info page | |
403 | // start at Manage Events listing | |
42daf119 | 404 | $this->openCiviPage('event/manage', 'reset=1'); |
6a488035 TO |
405 | $this->click('link=' . $params['title']); |
406 | ||
407 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
408 | return $this->getLocation(); | |
409 | } | |
410 | ||
4cbe18b8 EM |
411 | /** |
412 | * @param array $participant | |
413 | */ | |
d17310e4 | 414 | function _testRegisterWithBillingInfo($participant = array()) { |
6a488035 TO |
415 | $this->waitForElementPresent("credit_card_type"); |
416 | $this->select('credit_card_type', 'value=Visa'); | |
417 | $this->type('credit_card_number', '4111111111111111'); | |
418 | $this->type('cvv2', '000'); | |
419 | $this->select('credit_card_exp_date[M]', 'value=1'); | |
420 | $this->select('credit_card_exp_date[Y]', 'value=2020'); | |
421 | $this->type('billing_first_name', isset($participant['first_name']) ? $participant['first_name'] : 'Jane_' . substr(sha1(rand()), 0, 5)); | |
422 | $this->type('billing_last_name', isset($participant['last_name']) ? $participant['last_name'] : 'San_' . substr(sha1(rand()), 0, 5)); | |
423 | $this->type('billing_street_address-5', '15 Main St.'); | |
424 | $this->type(' billing_city-5', 'San Jose'); | |
425 | $this->select('billing_country_id-5', 'value=1228'); | |
426 | $this->select('billing_state_province_id-5', 'value=1004'); | |
427 | $this->type('billing_postal_code-5', '94129'); | |
428 | ||
225a8648 | 429 | $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom'); |
6a488035 TO |
430 | $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information'); |
431 | $this->assertStringsPresent($confirmStrings); | |
432 | $this->click('_qf_Confirm_next-bottom'); | |
433 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
434 | $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date'); | |
435 | $this->assertStringsPresent($thankStrings); | |
436 | } | |
437 | ||
4cbe18b8 EM |
438 | /** |
439 | * @param $eventParams | |
440 | * @param $participants | |
441 | * @param $priceFieldOptionCounts | |
442 | */ | |
6a488035 | 443 | function _testPricesetDetailsCustomSearch($eventParams, $participants, $priceFieldOptionCounts) { |
42daf119 | 444 | $this->openCiviPage('contact/search/custom', 'csid=9&reset=1'); |
6a488035 TO |
445 | |
446 | $this->select('event_id', 'label=' . $eventParams['title']); | |
447 | $this->click('_qf_Custom_refresh-bottom'); | |
448 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
449 | ||
450 | $tableHeaders = array('Contact Id', 'Participant Id', 'Name'); | |
451 | $tableHeaders = array_merge($tableHeaders, array_keys(current($priceFieldOptionCounts))); | |
452 | ||
453 | $tdnum = 2; | |
454 | foreach ($tableHeaders as $header) { | |
ed174dea | 455 | $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/thead/tr[1]/th[$tdnum]", $header); |
6a488035 TO |
456 | $tdnum++; |
457 | } | |
458 | ||
459 | foreach ($participants as $participantNum => $participant) { | |
460 | $tdnum = 4; | |
ed174dea | 461 | $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote("{$participant['first_name']} {$participant['last_name']}")); |
6a488035 TO |
462 | foreach ($priceFieldOptionCounts[$participantNum] as $priceFieldOptionCount) { |
463 | $tdnum++; | |
ed174dea | 464 | $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount)); |
6a488035 TO |
465 | } |
466 | } | |
467 | } | |
468 | } | |
469 |