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() {
37 // Log in using webtestLogin() method
38 $this->webtestLogin();
40 // We need a payment processor
41 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
42 $this->webtestAddPaymentProcessor($processorName);
45 $eventTitle = 'A Conference - ' . substr(sha1(rand()), 0, 7);
47 'title' => $eventTitle,
50 'payment_processor' => $processorName,
53 'Non-Member' => '325.00',
57 $infoEvent = $this->_testAddEvent($paramsEvent);
59 // logout to register for event.
60 $this->webtestLogout();
62 // Register Participant 1
63 // visit event info page
64 $this->open($infoEvent);
65 $this->waitForPageToLoad($this->getTimeoutMsec());
68 $this->click('link=Register Now');
69 $this->waitForElementPresent('_qf_Register_upload-bottom');
70 $this->click("xpath=//input[@class='form-radio']");
72 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
73 $this->type('email-Primary', $email);
75 // fill billing details and register
76 $this->_testRegisterWithBillingInfo();
78 // Register Participant 2
79 // visit event info page
80 $this->open($infoEvent);
83 $this->click('link=Register Now');
84 $this->waitForElementPresent('_qf_Register_upload-bottom');
86 $this->click("xpath=//input[@class='form-radio']");
87 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
88 $this->type('email-Primary', $email);
90 // fill billing details and register
91 $this->_testRegisterWithBillingInfo();
93 // login to check participant count
94 $this->webtestLogin();
97 $this->openCiviPage("event/search", "reset=1", 'participant_fee_amount_low');
98 $this->click("event_name");
99 $this->type("event_name", $eventTitle);
100 $this->typeKeys("event_name", $eventTitle);
101 $this->waitForElementPresent("css=div.ac_results-inner li");
102 $this->click("css=div.ac_results-inner li");
103 $this->click('_qf_Search_refresh');
104 $this->waitForPageToLoad($this->getTimeoutMsec());
106 // verify number of registered participants
107 $this->assertStringsPresent(array('2 Result'));
110 function testParticipantCountWithPriceset() {
112 // Log in using webtestLogin() method
113 $this->webtestLogin();
115 // We need a payment processor
116 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
117 $this->webtestAddPaymentProcessor($processorName);
120 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
121 $this->_testAddSet($priceset);
123 // create price fields
125 'Full Conference' => array('type' => 'Text',
126 'amount' => '525.00',
129 'Meal Choice' => array(
132 1 => array('label' => 'Chicken',
133 'amount' => '525.00',
137 'label' => 'Vegetarian',
138 'amount' => '200.00',
143 'Pre-conference Meetup?' => array(
146 1 => array('label' => 'Yes',
156 'Evening Sessions' => array(
157 'type' => 'CheckBox',
159 1 => array('label' => 'First Five',
160 'amount' => '100.00',
164 'label' => 'Second Four',
172 foreach ($fields as $label => $field) {
174 $this->type('label', $label);
175 $this->select('html_type', "value={$field['type']}");
177 if ($field['type'] == 'Text') {
178 $this->type('price', $field['amount']);
180 $this->waitForElementPresent('count');
181 $this->type('count', $field['count']);
182 $this->check('is_required');
185 $this->_testAddMultipleChoiceOptions($field['options']);
187 $this->click('_qf_Field_next_new-bottom');
188 $this->waitForPageToLoad($this->getTimeoutMsec());
189 $this->waitForElementPresent('_qf_Field_next-bottom');
193 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
194 $paramsEvent = array(
195 'title' => $eventTitle,
197 'event_type_id' => 4,
198 'payment_processor' => $processorName,
199 'price_set' => $priceset,
202 $infoEvent = $this->_testAddEvent($paramsEvent);
204 // logout to register for event.
205 $this->webtestLogout();
207 $priceFieldOptionCounts = $participants = array();
209 // Register Participant 1
210 // visit event info page
211 $this->open($infoEvent);
212 $this->waitForPageToLoad($this->getTimeoutMsec());
214 // register for event
215 $this->click('link=Register Now');
216 $this->waitForElementPresent('_qf_Register_upload-bottom');
218 $this->type("xpath=//input[@class='form-text four required']", '1');
220 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
221 $this->type('email-Primary', $email);
223 $participants[1] = array(
225 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
226 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
229 // fill billing related info and register
230 $this->_testRegisterWithBillingInfo($participants[1]);
232 // Options filled by 1st participants.
233 $priceFieldOptionCounts[1] = array(
234 'Full Conference' => 1,
235 'Meal Choice - Chicken' => 1,
236 'Meal Choice - Vegetarian' => 0,
237 'Pre-conference Meetup? - Yes' => 1,
238 'Pre-conference Meetup? - No' => 0,
239 'Evening Sessions - First Five' => 1,
240 'Evening Sessions - Second Four' => 0,
243 // Register Participant 1
244 // visit event info page
245 $this->open($infoEvent);
247 // register for event
248 $this->click('link=Register Now');
249 $this->waitForElementPresent('_qf_Register_upload-bottom');
251 $this->type("xpath=//input[@class='form-text four required']", '2');
252 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
253 $this->type('email-Primary', $email);
255 $participants[2] = array(
257 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
258 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
261 // fill billing related info and register
262 $this->_testRegisterWithBillingInfo($participants[2]);
264 // Options filled by 2nd participants.
265 $priceFieldOptionCounts[2] = array(
266 'Full Conference' => 2,
267 'Meal Choice - Chicken' => 1,
268 'Meal Choice - Vegetarian' => 0,
269 'Pre-conference Meetup? - Yes' => 1,
270 'Pre-conference Meetup? - No' => 0,
271 'Evening Sessions - First Five' => 1,
272 'Evening Sessions - Second Four' => 0,
275 // login to check participant count
276 $this->webtestLogin();
279 $this->openCiviPage('event/search', 'reset=1', 'participant_fee_amount_low');
280 $this->click("event_name");
281 $this->type("event_name", $eventTitle);
282 $this->typeKeys("event_name", $eventTitle);
283 $this->waitForElementPresent("css=div.ac_results-inner li");
284 $this->click("css=div.ac_results-inner li");
285 $this->click('_qf_Search_refresh');
286 $this->waitForPageToLoad($this->getTimeoutMsec());
288 // verify number of participants records and total participant count
289 $this->assertStringsPresent(array('2 Result', 'Actual participant count : 24'));
291 // CRM-7953, check custom search Price Set Details for Event
293 $this->_testPricesetDetailsCustomSearch($paramsEvent, $participants, $priceFieldOptionCounts);
296 function _testAddSet($setTitle, $financialType = 'Event Fee') {
297 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
299 // Enter Priceset fields (Title, Used For ...)
300 $this->type('title', $setTitle);
301 $this->check('extends[1]');
302 $this->select("css=select.form-select", "label={$financialType}");
303 $this->type('help_pre', 'This is test priceset.');
305 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
306 $this->click('_qf_Set_next-bottom');
308 $this->waitForPageToLoad($this->getTimeoutMsec());
309 $this->waitForElementPresent('_qf_Field_next-bottom');
312 function _testAddMultipleChoiceOptions($options) {
313 foreach ($options as $oIndex => $oValue) {
314 $this->type("option_label_{$oIndex}", $oValue['label']);
315 $this->type("option_amount_{$oIndex}", $oValue['amount']);
316 if (array_key_exists('count', $oValue)) {
317 $this->waitForElementPresent("option_count_{$oIndex}");
318 $this->type("option_count_{$oIndex}", $oValue['count']);
320 $this->click('link=another choice');
322 $this->click('CIVICRM_QFID_1_2');
325 function _testAddEvent($params) {
326 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
328 $this->select('event_type_id', "value={$params['event_type_id']}");
330 // Attendee role s/b selected now.
331 $this->select('default_role_id', 'value=1');
333 // Enter Event Title, Summary and Description
334 $this->type('title', $params['title']);
335 $this->type('summary', 'This is a great conference. Sign up now!');
336 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
338 // Choose Start and End dates.
339 // Using helper webtestFillDate function.
340 $this->webtestFillDateTime('start_date', '+1 week');
341 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
343 $this->type('max_participants', '50');
344 $this->click('is_map');
345 $this->click('_qf_EventInfo_upload-bottom');
347 // Wait for Location tab form to load
348 $this->waitForPageToLoad($this->getTimeoutMsec());
351 $this->click('link=Fees');
352 $this->waitForElementPresent('_qf_Fee_upload-bottom');
353 $this->click('CIVICRM_QFID_1_is_monetary');
354 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='" . $params['payment_processor'] . "']");
355 $this->select('financial_type_id','Event Fee');
356 if (array_key_exists('price_set', $params)) {
357 $this->select('price_set_id', 'label=' . $params['price_set']);
359 if (array_key_exists('fee_level', $params)) {
361 foreach ($params['fee_level'] as $label => $amount) {
362 $this->type("label_{$counter}", $label);
363 $this->type("value_{$counter}", $amount);
368 $this->click('_qf_Fee_upload-bottom');
369 $this->waitForPageToLoad($this->getTimeoutMsec());
371 // Go to Online Registration tab
372 $this->click('link=Online Registration');
373 $this->waitForElementPresent('_qf_Registration_upload-bottom');
375 $this->check('is_online_registration');
376 $this->assertChecked('is_online_registration');
378 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
380 // enable confirmation email
381 $this->click('CIVICRM_QFID_1_is_email_confirm');
382 $this->type('confirm_from_name', 'Jane Doe');
383 $this->type('confirm_from_email', 'jane.doe@example.org');
385 $this->click('_qf_Registration_upload-bottom');
386 $this->waitForPageToLoad($this->getTimeoutMsec());
387 $this->waitForTextPresent("'Registration' information has been saved.");
389 // verify event input on info page
390 // start at Manage Events listing
391 $this->openCiviPage('event/manage', 'reset=1');
392 $this->click('link=' . $params['title']);
394 $this->waitForPageToLoad($this->getTimeoutMsec());
395 return $this->getLocation();
398 function _testRegisterWithBillingInfo($participant = array(
400 $this->waitForElementPresent("credit_card_type");
401 $this->select('credit_card_type', 'value=Visa');
402 $this->type('credit_card_number', '4111111111111111');
403 $this->type('cvv2', '000');
404 $this->select('credit_card_exp_date[M]', 'value=1');
405 $this->select('credit_card_exp_date[Y]', 'value=2020');
406 $this->type('billing_first_name', isset($participant['first_name']) ?
$participant['first_name'] : 'Jane_' . substr(sha1(rand()), 0, 5));
407 $this->type('billing_last_name', isset($participant['last_name']) ?
$participant['last_name'] : 'San_' . substr(sha1(rand()), 0, 5));
408 $this->type('billing_street_address-5', '15 Main St.');
409 $this->type(' billing_city-5', 'San Jose');
410 $this->select('billing_country_id-5', 'value=1228');
411 $this->select('billing_state_province_id-5', 'value=1004');
412 $this->type('billing_postal_code-5', '94129');
414 $this->click('_qf_Register_upload-bottom');
415 $this->waitForPageToLoad($this->getTimeoutMsec());
416 $this->waitForElementPresent('_qf_Confirm_next-bottom');
417 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
418 $this->assertStringsPresent($confirmStrings);
419 $this->click('_qf_Confirm_next-bottom');
420 $this->waitForPageToLoad($this->getTimeoutMsec());
421 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
422 $this->assertStringsPresent($thankStrings);
425 function _testPricesetDetailsCustomSearch($eventParams, $participants, $priceFieldOptionCounts) {
426 $this->openCiviPage('contact/search/custom', 'csid=9&reset=1');
428 $this->select('event_id', 'label=' . $eventParams['title']);
429 $this->click('_qf_Custom_refresh-bottom');
430 $this->waitForPageToLoad($this->getTimeoutMsec());
432 $tableHeaders = array('Contact Id', 'Participant Id', 'Name');
433 $tableHeaders = array_merge($tableHeaders, array_keys(current($priceFieldOptionCounts)));
436 foreach ($tableHeaders as $header) {
437 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector']/thead/tr[1]/th[$tdnum]", $header);
441 foreach ($participants as $participantNum => $participant) {
443 $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']}"));
444 foreach ($priceFieldOptionCounts[$participantNum] as $priceFieldOptionCount) {
446 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount));