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