3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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';
30 * Class WebTest_Event_ParticipantCountTest
32 class WebTest_Event_ParticipantCountTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testParticipantCountWithFeelevel() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
42 // Use default payment processor
43 $processorName = 'Test Processor';
44 $this->webtestAddPaymentProcessor($processorName);
47 $eventTitle = 'A Conference - ' . substr(sha1(rand()), 0, 7);
49 'title' => $eventTitle,
52 'payment_processor' => $processorName,
55 'Non-Member' => '325.00',
59 $infoEvent = $this->_testAddEvent($paramsEvent);
61 // logout to register for event.
62 $this->webtestLogout();
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='crm-form-radio']");
74 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
75 $this->type('first_name', 'Mary');
76 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
77 $this->type('email-Primary', $email);
79 // fill billing details and register
80 $this->_testRegisterWithBillingInfo();
82 // Register Participant 2
83 // visit event info page
84 $this->open($infoEvent);
87 $this->click('link=Register Now');
88 $this->waitForElementPresent('_qf_Register_upload-bottom');
90 $this->click("xpath=//input[@class='crm-form-radio']");
91 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
92 $this->type('first_name', 'Mary');
93 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
94 $this->type('email-Primary', $email);
96 // fill billing details and register
97 $this->_testRegisterWithBillingInfo();
99 // login to check participant count
100 $this->webtestLogin();
103 $this->openCiviPage("event/search", "reset=1", 'participant_fee_amount_low');
104 $this->select2("event_id", $eventTitle);
105 $this->click('_qf_Search_refresh');
106 $this->waitForPageToLoad($this->getTimeoutMsec());
108 // verify number of registered participants
109 $this->assertTrue($this->isTextPresent('2 Results'));
112 function testParticipantCountWithPriceset() {
113 // Log in using webtestLogin() method
114 $this->webtestLogin();
116 // Use default payment processor
117 $processorName = 'Test Processor';
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', FALSE);
192 $this->waitForText("crm-notification-container", "Price Field '$label' has been saved.");
196 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
197 $paramsEvent = array(
198 'title' => $eventTitle,
200 'event_type_id' => 4,
201 'payment_processor' => $processorName,
202 'price_set' => $priceset,
205 $infoEvent = $this->_testAddEvent($paramsEvent);
207 // logout to register for event.
208 $this->webtestLogout();
210 $priceFieldOptionCounts = $participants = array();
212 // Register Participant 1
213 // visit event info page
214 $this->open($infoEvent);
215 $this->waitForPageToLoad($this->getTimeoutMsec());
217 // register for event
218 $this->click('link=Register Now');
219 $this->waitForElementPresent('_qf_Register_upload-bottom');
221 $this->type("xpath=//input[@class='four crm-form-text required']", '1');
223 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
224 $participants[1] = array(
226 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
227 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
230 $this->type('first_name', $participants[1]['first_name']);
231 $this->type('last_name', $participants[1]['last_name']);
232 $this->type('email-Primary', $email);
234 // fill billing related info and register
235 $this->_testRegisterWithBillingInfo($participants[1]);
237 // Options filled by 1st participants.
238 $priceFieldOptionCounts[1] = array(
239 'Full Conference' => 1,
240 'Meal Choice - Chicken' => 1,
241 'Meal Choice - Vegetarian' => 0,
242 'Pre-conference Meetup? - Yes' => 1,
243 'Pre-conference Meetup? - No' => 0,
244 'Evening Sessions - First Five' => 1,
245 'Evening Sessions - Second Four' => 0,
248 // Register Participant 1
249 // visit event info page
250 $this->open($infoEvent);
252 // register for event
253 $this->click('link=Register Now');
254 $this->waitForElementPresent('_qf_Register_upload-bottom');
256 $this->type("xpath=//input[@class='four crm-form-text required']", '2');
257 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
259 $participants[2] = array(
261 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
262 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
265 $this->type('first_name', $participants[2]['first_name']);
266 $this->type('last_name', $participants[2]['last_name']);
267 $this->type('email-Primary', $email);
269 // fill billing related info and register
270 $this->_testRegisterWithBillingInfo($participants[2]);
272 // Options filled by 2nd participants.
273 $priceFieldOptionCounts[2] = array(
274 'Full Conference' => 2,
275 'Meal Choice - Chicken' => 1,
276 'Meal Choice - Vegetarian' => 0,
277 'Pre-conference Meetup? - Yes' => 1,
278 'Pre-conference Meetup? - No' => 0,
279 'Evening Sessions - First Five' => 1,
280 'Evening Sessions - Second Four' => 0,
283 // login to check participant count
284 $this->webtestLogin();
287 $this->openCiviPage('event/search', 'reset=1', 'participant_fee_amount_low');
288 $this->select2("event_id", $eventTitle);
289 $this->click('_qf_Search_refresh');
290 $this->waitForPageToLoad($this->getTimeoutMsec());
292 // verify number of participants records and total participant count
293 $this->assertStringsPresent(array('2 Results', 'Actual participant count : 24'));
295 // CRM-7953, check custom search Price Set Details for Event
297 $this->_testPricesetDetailsCustomSearch($paramsEvent, $participants, $priceFieldOptionCounts);
302 * @param string $financialType
304 function _testAddSet($setTitle, $financialType = 'Event Fee') {
305 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
307 // Enter Priceset fields (Title, Used For ...)
308 $this->type('title', $setTitle);
309 $this->check('extends[1]');
310 $this->select("css=select.crm-form-select", "label={$financialType}");
311 $this->type('help_pre', 'This is test priceset.');
313 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
314 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
320 function _testAddMultipleChoiceOptions($options) {
321 foreach ($options as $oIndex => $oValue) {
322 $this->type("option_label_{$oIndex}", $oValue['label']);
323 $this->type("option_amount_{$oIndex}", $oValue['amount']);
324 if (array_key_exists('count', $oValue)) {
325 $this->waitForElementPresent("option_count_{$oIndex}");
326 $this->type("option_count_{$oIndex}", $oValue['count']);
328 $this->click('link=another choice');
330 $this->click('CIVICRM_QFID_1_2');
338 function _testAddEvent($params) {
339 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
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->waitForElementPresent('_qf_Fee_cancel-top');
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->click('intro_text-plain');
392 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
394 // enable confirmation email
395 $this->click('CIVICRM_QFID_1_is_email_confirm');
396 $this->type('confirm_from_name', 'Jane Doe');
397 $this->type('confirm_from_email', 'jane.doe@example.org');
399 $this->click('_qf_Registration_upload-bottom');
400 $this->waitForElementPresent('_qf_Registration_upload-bottom');
401 $this->waitForTextPresent("'Online Registration' information has been saved.");
403 // verify event input on info page
404 // start at Manage Events listing
405 $this->openCiviPage('event/manage', 'reset=1');
406 $this->click('link=' . $params['title']);
408 $this->waitForPageToLoad($this->getTimeoutMsec());
409 return $this->getLocation();
413 * @param array $participant
415 function _testRegisterWithBillingInfo($participant = array()) {
416 $this->waitForElementPresent("credit_card_type");
417 $this->select('credit_card_type', 'value=Visa');
418 $this->type('credit_card_number', '4111111111111111');
419 $this->type('cvv2', '000');
420 $this->select('credit_card_exp_date[M]', 'value=1');
421 $this->select('credit_card_exp_date[Y]', 'value=2020');
422 $this->type('billing_first_name', isset($participant['first_name']) ?
$participant['first_name'] : 'Jane_' . substr(sha1(rand()), 0, 5));
423 $this->type('billing_last_name', isset($participant['last_name']) ?
$participant['last_name'] : 'San_' . substr(sha1(rand()), 0, 5));
424 $this->type('billing_street_address-5', '15 Main St.');
425 $this->type(' billing_city-5', 'San Jose');
426 $this->select('billing_country_id-5', 'value=1228');
427 $this->select('billing_state_province_id-5', 'value=1004');
428 $this->type('billing_postal_code-5', '94129');
430 $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom');
431 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
432 $this->assertStringsPresent($confirmStrings);
433 $this->click('_qf_Confirm_next-bottom');
434 $this->waitForPageToLoad($this->getTimeoutMsec());
435 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
436 $this->assertStringsPresent($thankStrings);
440 * @param $eventParams
441 * @param $participants
442 * @param $priceFieldOptionCounts
444 function _testPricesetDetailsCustomSearch($eventParams, $participants, $priceFieldOptionCounts) {
445 $this->openCiviPage('contact/search/custom', 'csid=9&reset=1');
447 $this->select('event_id', 'label=' . $eventParams['title']);
448 $this->click('_qf_Custom_refresh-bottom');
449 $this->waitForPageToLoad($this->getTimeoutMsec());
451 $tableHeaders = array('Contact ID', 'Participant Id', 'Name');
452 $tableHeaders = array_merge($tableHeaders, array_keys(current($priceFieldOptionCounts)));
455 foreach ($tableHeaders as $header) {
456 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/thead/tr[1]/th[$tdnum]", $header);
460 foreach ($participants as $participantNum => $participant) {
462 $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']}"));
463 foreach ($priceFieldOptionCounts[$participantNum] as $priceFieldOptionCount) {
465 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount));