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