3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Event_ParticipantCountTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testParticipantCountWithFeelevel() {
35 // Log in using webtestLogin() method
36 $this->webtestLogin();
38 // We need a payment processor
39 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
40 $this->webtestAddPaymentProcessor($processorName);
43 $eventTitle = 'A Conference - ' . substr(sha1(rand()), 0, 7);
45 'title' => $eventTitle,
48 'payment_processor' => $processorName,
51 'Non-Member' => '325.00',
55 $infoEvent = $this->_testAddEvent($paramsEvent);
57 // logout to register for event.
58 $this->webtestLogout();
60 // Register Participant 1
61 // visit event info page
62 $this->open($infoEvent);
63 $this->waitForPageToLoad($this->getTimeoutMsec());
66 $this->click('link=Register Now');
67 $this->waitForElementPresent('_qf_Register_upload-bottom');
68 $this->click("xpath=//input[@class='form-radio']");
70 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
71 $this->type('first_name', 'Mary');
72 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
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('first_name', 'Mary');
89 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
90 $this->type('email-Primary', $email);
92 // fill billing details and register
93 $this->_testRegisterWithBillingInfo();
95 // login to check participant count
96 $this->webtestLogin();
99 $this->openCiviPage("event/search", "reset=1", 'participant_fee_amount_low');
100 $this->click("event_name");
101 $this->type("event_name", $eventTitle);
102 $this->typeKeys("event_name", $eventTitle);
103 $this->waitForElementPresent("css=div.ac_results-inner li");
104 $this->click("css=div.ac_results-inner li");
105 $this->click('_qf_Search_refresh');
106 $this->waitForPageToLoad($this->getTimeoutMsec());
108 // verify number of registered participants
109 $this->assertStringsPresent(array('2 Result'));
112 function testParticipantCountWithPriceset() {
113 // Log in using webtestLogin() method
114 $this->webtestLogin();
116 // We need a payment processor
117 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
118 $this->webtestAddPaymentProcessor($processorName);
121 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
122 $this->_testAddSet($priceset);
124 // create price fields
126 'Full Conference' => array(
128 'amount' => '525.00',
131 'Meal Choice' => array(
135 'label' => 'Chicken',
136 'amount' => '525.00',
140 'label' => 'Vegetarian',
141 'amount' => '200.00',
146 'Pre-conference Meetup?' => array(
160 'Evening Sessions' => array(
161 'type' => 'CheckBox',
164 'label' => 'First Five',
165 'amount' => '100.00',
169 'label' => 'Second Four',
177 foreach ($fields as $label => $field) {
178 $this->type('label', $label);
179 $this->select('html_type', "value={$field['type']}");
181 if ($field['type'] == 'Text') {
182 $this->type('price', $field['amount']);
184 $this->waitForElementPresent('count');
185 $this->type('count', $field['count']);
186 $this->check('is_required');
189 $this->_testAddMultipleChoiceOptions($field['options']);
191 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
195 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
196 $paramsEvent = array(
197 'title' => $eventTitle,
199 'event_type_id' => 4,
200 'payment_processor' => $processorName,
201 'price_set' => $priceset,
204 $infoEvent = $this->_testAddEvent($paramsEvent);
206 // logout to register for event.
207 $this->webtestLogout();
209 $priceFieldOptionCounts = $participants = array();
211 // Register Participant 1
212 // visit event info page
213 $this->open($infoEvent);
214 $this->waitForPageToLoad($this->getTimeoutMsec());
216 // register for event
217 $this->click('link=Register Now');
218 $this->waitForElementPresent('_qf_Register_upload-bottom');
220 $this->type("xpath=//input[@class='form-text four required']", '1');
222 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
223 $participants[1] = array(
225 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
226 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
229 $this->type('first_name', $participants[1]['first_name']);
230 $this->type('last_name', $participants[1]['last_name']);
231 $this->type('email-Primary', $email);
233 // fill billing related info and register
234 $this->_testRegisterWithBillingInfo($participants[1]);
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,
247 // Register Participant 1
248 // visit event info page
249 $this->open($infoEvent);
251 // register for event
252 $this->click('link=Register Now');
253 $this->waitForElementPresent('_qf_Register_upload-bottom');
255 $this->type("xpath=//input[@class='form-text four required']", '2');
256 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
258 $participants[2] = array(
260 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
261 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
264 $this->type('first_name', $participants[2]['first_name']);
265 $this->type('last_name', $participants[2]['last_name']);
266 $this->type('email-Primary', $email);
268 // fill billing related info and register
269 $this->_testRegisterWithBillingInfo($participants[2]);
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,
282 // login to check participant count
283 $this->webtestLogin();
286 $this->openCiviPage('event/search', 'reset=1', 'participant_fee_amount_low');
287 $this->click("event_name");
288 $this->type("event_name", $eventTitle);
289 $this->typeKeys("event_name", $eventTitle);
290 $this->waitForElementPresent("css=div.ac_results-inner li");
291 $this->click("css=div.ac_results-inner li");
292 $this->click('_qf_Search_refresh');
293 $this->waitForPageToLoad($this->getTimeoutMsec());
295 // verify number of participants records and total participant count
296 $this->assertStringsPresent(array('2 Result', 'Actual participant count : 24'));
298 // CRM-7953, check custom search Price Set Details for Event
300 $this->_testPricesetDetailsCustomSearch($paramsEvent, $participants, $priceFieldOptionCounts);
303 function _testAddSet($setTitle, $financialType = 'Event Fee') {
304 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
306 // Enter Priceset fields (Title, Used For ...)
307 $this->type('title', $setTitle);
308 $this->check('extends[1]');
309 $this->select("css=select.form-select", "label={$financialType}");
310 $this->type('help_pre', 'This is test priceset.');
312 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
313 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
316 function _testAddMultipleChoiceOptions($options) {
317 foreach ($options as $oIndex => $oValue) {
318 $this->type("option_label_{$oIndex}", $oValue['label']);
319 $this->type("option_amount_{$oIndex}", $oValue['amount']);
320 if (array_key_exists('count', $oValue)) {
321 $this->waitForElementPresent("option_count_{$oIndex}");
322 $this->type("option_count_{$oIndex}", $oValue['count']);
324 $this->click('link=another choice');
326 $this->click('CIVICRM_QFID_1_2');
329 function _testAddEvent($params) {
330 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
332 $this->select('event_type_id', "value={$params['event_type_id']}");
334 // Attendee role s/b selected now.
335 $this->select('default_role_id', 'value=1');
337 // Enter Event Title, Summary and Description
338 $this->type('title', $params['title']);
339 $this->type('summary', 'This is a great conference. Sign up now!');
340 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
342 // Choose Start and End dates.
343 // Using helper webtestFillDate function.
344 $this->webtestFillDateTime('start_date', '+1 week');
345 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
347 $this->type('max_participants', '50');
348 $this->click('is_map');
349 $this->click('_qf_EventInfo_upload-bottom');
351 // Wait for Location tab form to load
352 $this->waitForPageToLoad($this->getTimeoutMsec());
355 $this->click('link=Fees');
356 $this->waitForElementPresent('_qf_Fee_upload-bottom');
357 $this->click('CIVICRM_QFID_1_is_monetary');
358 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='" . $params['payment_processor'] . "']");
359 $this->select('financial_type_id', 'Event Fee');
360 if (array_key_exists('price_set', $params)) {
361 $this->select('price_set_id', 'label=' . $params['price_set']);
363 if (array_key_exists('fee_level', $params)) {
365 foreach ($params['fee_level'] as $label => $amount) {
366 $this->type("label_{$counter}", $label);
367 $this->type("value_{$counter}", $amount);
372 $this->click('_qf_Fee_upload-bottom');
373 $this->waitForPageToLoad($this->getTimeoutMsec());
375 // Go to Online Registration tab
376 $this->click('link=Online Registration');
377 $this->waitForElementPresent('_qf_Registration_upload-bottom');
379 $this->check('is_online_registration');
380 $this->assertChecked('is_online_registration');
382 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
384 // enable confirmation email
385 $this->click('CIVICRM_QFID_1_is_email_confirm');
386 $this->type('confirm_from_name', 'Jane Doe');
387 $this->type('confirm_from_email', 'jane.doe@example.org');
389 $this->click('_qf_Registration_upload-bottom');
390 $this->waitForPageToLoad($this->getTimeoutMsec());
391 $this->waitForTextPresent("'Registration' information has been saved.");
393 // verify event input on info page
394 // start at Manage Events listing
395 $this->openCiviPage('event/manage', 'reset=1');
396 $this->click('link=' . $params['title']);
398 $this->waitForPageToLoad($this->getTimeoutMsec());
399 return $this->getLocation();
402 function _testRegisterWithBillingInfo($participant = array()) {
403 $this->waitForElementPresent("credit_card_type");
404 $this->select('credit_card_type', 'value=Visa');
405 $this->type('credit_card_number', '4111111111111111');
406 $this->type('cvv2', '000');
407 $this->select('credit_card_exp_date[M]', 'value=1');
408 $this->select('credit_card_exp_date[Y]', 'value=2020');
409 $this->type('billing_first_name', isset($participant['first_name']) ?
$participant['first_name'] : 'Jane_' . substr(sha1(rand()), 0, 5));
410 $this->type('billing_last_name', isset($participant['last_name']) ?
$participant['last_name'] : 'San_' . substr(sha1(rand()), 0, 5));
411 $this->type('billing_street_address-5', '15 Main St.');
412 $this->type(' billing_city-5', 'San Jose');
413 $this->select('billing_country_id-5', 'value=1228');
414 $this->select('billing_state_province_id-5', 'value=1004');
415 $this->type('billing_postal_code-5', '94129');
417 $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom');
418 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
419 $this->assertStringsPresent($confirmStrings);
420 $this->click('_qf_Confirm_next-bottom');
421 $this->waitForPageToLoad($this->getTimeoutMsec());
422 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
423 $this->assertStringsPresent($thankStrings);
426 function _testPricesetDetailsCustomSearch($eventParams, $participants, $priceFieldOptionCounts) {
427 $this->openCiviPage('contact/search/custom', 'csid=9&reset=1');
429 $this->select('event_id', 'label=' . $eventParams['title']);
430 $this->click('_qf_Custom_refresh-bottom');
431 $this->waitForPageToLoad($this->getTimeoutMsec());
433 $tableHeaders = array('Contact Id', 'Participant Id', 'Name');
434 $tableHeaders = array_merge($tableHeaders, array_keys(current($priceFieldOptionCounts)));
437 foreach ($tableHeaders as $header) {
438 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector']/thead/tr[1]/th[$tdnum]", $header);
442 foreach ($participants as $participantNum => $participant) {
444 $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']}"));
445 foreach ($priceFieldOptionCounts[$participantNum] as $priceFieldOptionCount) {
447 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount));