3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Event_ParticipantCountTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testParticipantCountWithFeelevel() {
36 $this->open($this->sboxPath
);
38 // Log in using webtestLogin() method
39 $this->webtestLogin();
41 // We need a payment processor
42 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
43 $this->webtestAddPaymentProcessor($processorName);
46 $eventTitle = 'A Conference - ' . substr(sha1(rand()), 0, 7);
48 'title' => $eventTitle,
51 'payment_processor' => $processorName,
54 'Non-Member' => '325.00',
58 $infoEvent = $this->_testAddEvent($paramsEvent);
60 // logout to register for event.
61 $this->open($this->sboxPath
. 'civicrm/logout?reset=1');
62 $this->waitForPageToLoad($this->getTimeoutMsec());
64 // Register Participant 1
65 // visit event info page
66 $this->open($infoEvent);
67 $this->waitForPageToLoad($this->getTimeoutMsec());
70 $this->click('link=Register Now');
71 $this->waitForElementPresent('_qf_Register_upload-bottom');
72 $this->click("xpath=//input[@class='form-radio']");
74 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
75 $this->type('email-Primary', $email);
77 // fill billing details and register
78 $this->_testRegisterWithBillingInfo();
80 // Register Participant 2
81 // visit event info page
82 $this->open($infoEvent);
85 $this->click('link=Register Now');
86 $this->waitForElementPresent('_qf_Register_upload-bottom');
88 $this->click("xpath=//input[@class='form-radio']");
89 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
90 $this->type('email-Primary', $email);
92 // fill billing details and register
93 $this->_testRegisterWithBillingInfo();
95 // login to check participant count
96 $this->open($this->sboxPath
);
97 $this->webtestLogin();
100 $this->open($this->sboxPath
. 'civicrm/event/search?reset=1');
101 $this->waitForElementPresent('participant_fee_amount_low');
102 $this->click("event_name");
103 $this->type("event_name", $eventTitle);
104 $this->typeKeys("event_name", $eventTitle);
105 $this->waitForElementPresent("css=div.ac_results-inner li");
106 $this->click("css=div.ac_results-inner li");
107 $this->click('_qf_Search_refresh');
108 $this->waitForPageToLoad($this->getTimeoutMsec());
110 // verify number of registered participants
111 $this->assertStringsPresent(array('2 Result'));
114 function testParticipantCountWithPriceset() {
115 $this->open($this->sboxPath
);
117 // Log in using webtestLogin() method
118 $this->webtestLogin();
120 // We need a payment processor
121 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
122 $this->webtestAddPaymentProcessor($processorName);
125 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
126 $this->_testAddSet($priceset);
128 // create price fields
130 'Full Conference' => array('type' => 'Text',
131 'amount' => '525.00',
134 'Meal Choice' => array(
137 1 => array('label' => 'Chicken',
138 'amount' => '525.00',
142 'label' => 'Vegetarian',
143 'amount' => '200.00',
148 'Pre-conference Meetup?' => array(
151 1 => array('label' => 'Yes',
161 'Evening Sessions' => array(
162 'type' => 'CheckBox',
164 1 => array('label' => 'First Five',
165 'amount' => '100.00',
169 'label' => 'Second Four',
177 foreach ($fields as $label => $field) {
179 $this->type('label', $label);
180 $this->select('html_type', "value={$field['type']}");
182 if ($field['type'] == 'Text') {
183 $this->type('price', $field['amount']);
185 $this->waitForElementPresent('count');
186 $this->type('count', $field['count']);
187 $this->check('is_required');
190 $this->_testAddMultipleChoiceOptions($field['options']);
192 $this->click('_qf_Field_next_new-bottom');
193 $this->waitForPageToLoad($this->getTimeoutMsec());
194 $this->waitForElementPresent('_qf_Field_next-bottom');
198 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
199 $paramsEvent = array(
200 'title' => $eventTitle,
202 'event_type_id' => 4,
203 'payment_processor' => $processorName,
204 'price_set' => $priceset,
207 $infoEvent = $this->_testAddEvent($paramsEvent);
209 // logout to register for event.
210 $this->open($this->sboxPath
. 'civicrm/logout?reset=1');
211 $this->waitForPageToLoad($this->getTimeoutMsec());
213 $priceFieldOptionCounts = $participants = array();
215 // Register Participant 1
216 // visit event info page
217 $this->open($infoEvent);
218 $this->waitForPageToLoad($this->getTimeoutMsec());
220 // register for event
221 $this->click('link=Register Now');
222 $this->waitForElementPresent('_qf_Register_upload-bottom');
224 $this->type("xpath=//input[@class='form-text four required']", '1');
226 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
227 $this->type('email-Primary', $email);
229 $participants[1] = array(
231 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
232 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
235 // fill billing related info and register
236 $this->_testRegisterWithBillingInfo($participants[1]);
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,
249 // Register Participant 1
250 // visit event info page
251 $this->open($infoEvent);
253 // register for event
254 $this->click('link=Register Now');
255 $this->waitForElementPresent('_qf_Register_upload-bottom');
257 $this->type("xpath=//input[@class='form-text four required']", '2');
258 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
259 $this->type('email-Primary', $email);
261 $participants[2] = array(
263 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
264 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
267 // fill billing related info and register
268 $this->_testRegisterWithBillingInfo($participants[2]);
270 // Options filled by 2nd participants.
271 $priceFieldOptionCounts[2] = array(
272 'Full Conference' => 2,
273 'Meal Choice - Chicken' => 1,
274 'Meal Choice - Vegetarian' => 0,
275 'Pre-conference Meetup? - Yes' => 1,
276 'Pre-conference Meetup? - No' => 0,
277 'Evening Sessions - First Five' => 1,
278 'Evening Sessions - Second Four' => 0,
281 // login to check participant count
282 $this->open($this->sboxPath
);
283 $this->webtestLogin();
286 $this->open($this->sboxPath
. 'civicrm/event/search?reset=1');
287 $this->waitForElementPresent('participant_fee_amount_low');
288 $this->click("event_name");
289 $this->type("event_name", $eventTitle);
290 $this->typeKeys("event_name", $eventTitle);
291 $this->waitForElementPresent("css=div.ac_results-inner li");
292 $this->click("css=div.ac_results-inner li");
293 $this->click('_qf_Search_refresh');
294 $this->waitForPageToLoad($this->getTimeoutMsec());
296 // verify number of participants records and total participant count
297 $this->assertStringsPresent(array('2 Result', 'Actual participant count : 24'));
299 // CRM-7953, check custom search Price Set Details for Event
301 $this->_testPricesetDetailsCustomSearch($paramsEvent, $participants, $priceFieldOptionCounts);
304 function _testAddSet($setTitle, $financialType = 'Event Fee') {
305 $this->open($this->sboxPath
. 'civicrm/admin/price?reset=1&action=add');
306 $this->waitForPageToLoad($this->getTimeoutMsec());
307 $this->waitForElementPresent('_qf_Set_next-bottom');
309 // Enter Priceset fields (Title, Used For ...)
310 $this->type('title', $setTitle);
311 $this->check('extends[1]');
312 $this->select("css=select.form-select", "label={$financialType}");
313 $this->type('help_pre', 'This is test priceset.');
315 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
316 $this->click('_qf_Set_next-bottom');
318 $this->waitForPageToLoad($this->getTimeoutMsec());
319 $this->waitForElementPresent('_qf_Field_next-bottom');
322 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']);
330 $this->click('link=another choice');
332 $this->click('CIVICRM_QFID_1_2');
335 function _testAddEvent($params) {
336 $this->open($this->sboxPath
. 'civicrm/event/add?reset=1&action=add');
338 $this->waitForElementPresent('_qf_EventInfo_upload-bottom');
340 // Let's start filling the form with values.
341 $this->select('event_type_id', "value={$params['event_type_id']}");
343 // Attendee role s/b selected now.
344 $this->select('default_role_id', 'value=1');
346 // Enter Event Title, Summary and Description
347 $this->type('title', $params['title']);
348 $this->type('summary', 'This is a great conference. Sign up now!');
349 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
351 // Choose Start and End dates.
352 // Using helper webtestFillDate function.
353 $this->webtestFillDateTime('start_date', '+1 week');
354 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
356 $this->type('max_participants', '50');
357 $this->click('is_map');
358 $this->click('_qf_EventInfo_upload-bottom');
360 // Wait for Location tab form to load
361 $this->waitForPageToLoad($this->getTimeoutMsec());
364 $this->click('link=Fees');
365 $this->waitForElementPresent('_qf_Fee_upload-bottom');
366 $this->click('CIVICRM_QFID_1_is_monetary');
367 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='" . $params['payment_processor'] . "']");
368 $this->select('financial_type_id','Event Fee');
369 if (array_key_exists('price_set', $params)) {
370 $this->select('price_set_id', 'label=' . $params['price_set']);
372 if (array_key_exists('fee_level', $params)) {
374 foreach ($params['fee_level'] as $label => $amount) {
375 $this->type("label_{$counter}", $label);
376 $this->type("value_{$counter}", $amount);
381 $this->click('_qf_Fee_upload-bottom');
382 $this->waitForPageToLoad($this->getTimeoutMsec());
384 // Go to Online Registration tab
385 $this->click('link=Online Registration');
386 $this->waitForElementPresent('_qf_Registration_upload-bottom');
388 $this->check('is_online_registration');
389 $this->assertChecked('is_online_registration');
391 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
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');
398 $this->click('_qf_Registration_upload-bottom');
399 $this->waitForPageToLoad($this->getTimeoutMsec());
400 $this->waitForTextPresent("'Registration' information has been saved.");
402 // verify event input on info page
403 // start at Manage Events listing
404 $this->open($this->sboxPath
. 'civicrm/event/manage?reset=1');
405 $this->click('link=' . $params['title']);
407 $this->waitForPageToLoad($this->getTimeoutMsec());
408 return $this->getLocation();
411 function _testRegisterWithBillingInfo($participant = array(
413 $this->waitForElementPresent("credit_card_type");
414 $this->select('credit_card_type', 'value=Visa');
415 $this->type('credit_card_number', '4111111111111111');
416 $this->type('cvv2', '000');
417 $this->select('credit_card_exp_date[M]', 'value=1');
418 $this->select('credit_card_exp_date[Y]', 'value=2020');
419 $this->type('billing_first_name', isset($participant['first_name']) ?
$participant['first_name'] : 'Jane_' . substr(sha1(rand()), 0, 5));
420 $this->type('billing_last_name', isset($participant['last_name']) ?
$participant['last_name'] : 'San_' . substr(sha1(rand()), 0, 5));
421 $this->type('billing_street_address-5', '15 Main St.');
422 $this->type(' billing_city-5', 'San Jose');
423 $this->select('billing_country_id-5', 'value=1228');
424 $this->select('billing_state_province_id-5', 'value=1004');
425 $this->type('billing_postal_code-5', '94129');
427 $this->click('_qf_Register_upload-bottom');
428 $this->waitForPageToLoad($this->getTimeoutMsec());
429 $this->waitForElementPresent('_qf_Confirm_next-bottom');
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);
438 function _testPricesetDetailsCustomSearch($eventParams, $participants, $priceFieldOptionCounts) {
439 $this->open($this->sboxPath
. 'civicrm/contact/search/custom?csid=9&reset=1');
440 $this->waitForPageToLoad($this->getTimeoutMsec());
442 $this->select('event_id', 'label=' . $eventParams['title']);
443 $this->click('_qf_Custom_refresh-bottom');
444 $this->waitForPageToLoad($this->getTimeoutMsec());
446 $tableHeaders = array('Contact Id', 'Participant Id', 'Name');
447 $tableHeaders = array_merge($tableHeaders, array_keys(current($priceFieldOptionCounts)));
450 foreach ($tableHeaders as $header) {
451 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector']/thead/tr[1]/th[$tdnum]", $header);
455 foreach ($participants as $participantNum => $participant) {
457 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote("{$participant['first_name']} {$participant['last_name']}"));
458 foreach ($priceFieldOptionCounts[$participantNum] as $priceFieldOptionCount) {
460 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount));