| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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_AddParticipationTest |
| 31 | */ |
| 32 | class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testEventParticipationAdd() { |
| 39 | $this->webtestLogin(); |
| 40 | |
| 41 | // Adding contact with randomized first name (so we can then select that contact when creating event registration) |
| 42 | $firstName = substr(sha1(rand()), 0, 7); |
| 43 | $this->webtestAddContact($firstName, 'Anderson', TRUE); |
| 44 | $displayName = "$firstName Anderson"; |
| 45 | |
| 46 | $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom"); |
| 47 | |
| 48 | // Type contact last name in contact auto-complete, wait for dropdown and click first result |
| 49 | $this->webtestFillAutocomplete($firstName); |
| 50 | |
| 51 | // Select event. Based on label for now. |
| 52 | $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament"); |
| 53 | |
| 54 | // Select role |
| 55 | $this->multiselect2('role_id', array('Volunteer')); |
| 56 | |
| 57 | // Choose Registration Date. |
| 58 | // Using helper webtestFillDate function. |
| 59 | $this->webtestFillDate('register_date', 'now'); |
| 60 | $today = date('F jS, Y', strtotime('now')); |
| 61 | |
| 62 | // Select participant status |
| 63 | $this->select('status_id', 'value=1'); |
| 64 | |
| 65 | // Setting registration source |
| 66 | $this->type('source', 'Event StandaloneAddTest Webtest'); |
| 67 | |
| 68 | // Since we're here, let's check of screen help is being displayed properly |
| 69 | $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).')); |
| 70 | |
| 71 | // Select an event fee |
| 72 | $this->waitForElementPresent('priceset'); |
| 73 | |
| 74 | $this->click("xpath=//input[@class='crm-form-radio']"); |
| 75 | |
| 76 | // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle) |
| 77 | $this->type('total_amount', '800'); |
| 78 | |
| 79 | // Select payment method = Check and enter chk number |
| 80 | $this->select('payment_instrument_id', 'value=4'); |
| 81 | $this->waitForElementPresent('check_number'); |
| 82 | $this->type('check_number', '1044'); |
| 83 | |
| 84 | // go for the chicken combo (obviously) |
| 85 | // $this->click('CIVICRM_QFID_chicken_Chicken'); |
| 86 | |
| 87 | $this->waitForElementPresent('send_receipt'); |
| 88 | $this->assertTrue($this->isChecked("send_receipt"), 'Send Confirmation and Receipt checkbox should be checked by default but is not checked.'); |
| 89 | |
| 90 | // Clicking save. |
| 91 | $this->clickLink('_qf_Participant_upload-bottom'); |
| 92 | |
| 93 | // Is status message correct? |
| 94 | $this->checkCRMAlert("Event registration for $displayName has been added"); |
| 95 | |
| 96 | $this->waitForElementPresent("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 97 | //click through to the participant view screen |
| 98 | $this->clickAjaxLink("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']", '_qf_ParticipantView_cancel-bottom'); |
| 99 | |
| 100 | $this->webtestVerifyTabularData( |
| 101 | array( |
| 102 | 'Event' => 'Rain-forest Cup Youth Soccer Tournament', |
| 103 | 'Participant Role' => 'Attendee', |
| 104 | 'Status' => 'Registered', |
| 105 | 'Event Source' => 'Event StandaloneAddTest Webtest', |
| 106 | 'Fees' => '$ 800.00', |
| 107 | ) |
| 108 | ); |
| 109 | // check contribution record as well |
| 110 | //click through to the contribution view screen |
| 111 | $this->clickAjaxLink("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom'); |
| 112 | |
| 113 | $this->webtestVerifyTabularData( |
| 114 | array( |
| 115 | 'From' => $displayName, |
| 116 | 'Financial Type' => 'Event Fee', |
| 117 | 'Total Amount' => '$ 800.00', |
| 118 | 'Contribution Status' => 'Completed', |
| 119 | 'Paid By' => 'Check', |
| 120 | 'Check Number' => '1044', |
| 121 | ) |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | public function testEventParticipationAddWithMultipleRoles() { |
| 126 | $this->webtestLogin(); |
| 127 | |
| 128 | // Adding contact with randomized first name (so we can then select that contact when creating event registration) |
| 129 | $firstName = substr(sha1(rand()), 0, 7); |
| 130 | $this->webtestAddContact($firstName, 'Anderson', TRUE); |
| 131 | $displayName = "$firstName Anderson"; |
| 132 | |
| 133 | // add custom data for participant role |
| 134 | $this->openCiviPage("admin/custom/group", "reset=1"); |
| 135 | |
| 136 | //add new custom data |
| 137 | $this->clickLink("//a[@id='newCustomDataGroup']/span"); |
| 138 | |
| 139 | //fill custom group title |
| 140 | $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7); |
| 141 | $this->click('title'); |
| 142 | $this->type('title', $customGroupTitle); |
| 143 | |
| 144 | //custom group extends |
| 145 | $this->click('extends[0]'); |
| 146 | $this->select('extends[0]', 'value=ParticipantRole'); |
| 147 | |
| 148 | $this->click('extends[1][]'); |
| 149 | $this->select('extends[1][]', 'value=2'); |
| 150 | |
| 151 | $this->click("//option[@value='Contact']"); |
| 152 | $this->clickLink('_qf_Group_next'); |
| 153 | |
| 154 | //Is custom group created? |
| 155 | $this->checkCRMAlert("Your custom field set '$customGroupTitle' has been added. You can add custom fields now."); |
| 156 | |
| 157 | //add custom field - alphanumeric checkbox |
| 158 | $this->waitForAjaxContent(); |
| 159 | $checkboxFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4); |
| 160 | $this->click('label'); |
| 161 | $this->type('label', $checkboxFieldLabel); |
| 162 | $this->click('data_type[1]'); |
| 163 | $this->select('data_type[1]', 'value=CheckBox'); |
| 164 | $this->click("//option[@value='CheckBox']"); |
| 165 | $checkboxOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5); |
| 166 | $this->type('option_label_1', $checkboxOptionLabel1); |
| 167 | $this->type('option_value_1', '1'); |
| 168 | $checkboxOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5); |
| 169 | $this->type('option_label_2', $checkboxOptionLabel2); |
| 170 | $this->type('option_value_2', '2'); |
| 171 | $this->click('link=another choice'); |
| 172 | $checkboxOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5); |
| 173 | $this->type('option_label_3', $checkboxOptionLabel3); |
| 174 | $this->type('option_value_3', '3'); |
| 175 | |
| 176 | //enter options per line |
| 177 | $this->type('options_per_line', '2'); |
| 178 | |
| 179 | //enter pre help message |
| 180 | $this->type('help_pre', 'this is field pre help'); |
| 181 | |
| 182 | //enter post help message |
| 183 | $this->type('help_post', 'this field post help'); |
| 184 | |
| 185 | //Is searchable? |
| 186 | $this->click('is_searchable'); |
| 187 | |
| 188 | //clicking save |
| 189 | $this->click('_qf_Field_done-bottom'); |
| 190 | |
| 191 | //Is custom field created? |
| 192 | $this->checkCRMAlert("Custom field '$checkboxFieldLabel' has been saved."); |
| 193 | $this->waitForAjaxContent(); |
| 194 | |
| 195 | //create another custom field - Integer Radio |
| 196 | $this->clickPopupLink('newCustomField', '_qf_Field_cancel'); |
| 197 | $this->click('data_type[0]'); |
| 198 | $this->select('data_type[0]', 'value=1'); |
| 199 | $this->click("//option[@value='1']"); |
| 200 | $this->click('data_type[1]'); |
| 201 | $this->select('data_type[1]', 'value=Radio'); |
| 202 | $this->click("//option[@value='Radio']"); |
| 203 | |
| 204 | $radioFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4); |
| 205 | $this->type('label', $radioFieldLabel); |
| 206 | $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5); |
| 207 | $this->type('option_label_1', $radioOptionLabel1); |
| 208 | $this->type('option_value_1', '1'); |
| 209 | $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5); |
| 210 | $this->type('option_label_2', $radioOptionLabel2); |
| 211 | $this->type('option_value_2', '2'); |
| 212 | $this->click('link=another choice'); |
| 213 | $radioOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5); |
| 214 | $this->type('option_label_3', $radioOptionLabel3); |
| 215 | $this->type('option_value_3', '3'); |
| 216 | |
| 217 | //select options per line |
| 218 | $this->type('options_per_line', '3'); |
| 219 | |
| 220 | //enter pre help msg |
| 221 | $this->type('help_pre', 'this is field pre help'); |
| 222 | |
| 223 | //enter post help msg |
| 224 | $this->type('help_post', 'this is field post help'); |
| 225 | |
| 226 | //Is searchable? |
| 227 | $this->click('is_searchable'); |
| 228 | |
| 229 | //clicking save |
| 230 | $this->clickAjaxLink('_qf_Field_done-bottom'); |
| 231 | |
| 232 | // Visit home page for a sec to give caches time to be cleared |
| 233 | $this->openCiviPage(''); |
| 234 | |
| 235 | $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom"); |
| 236 | |
| 237 | // Type contact last name in contact auto-complete, wait for dropdown and click first result |
| 238 | $this->webtestFillAutocomplete($firstName); |
| 239 | |
| 240 | // Select event. Based on label for now. |
| 241 | $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament"); |
| 242 | |
| 243 | // Select roles |
| 244 | $this->multiselect2('role_id', array('Volunteer', 'Host')); |
| 245 | |
| 246 | $this->waitForElementPresent("xpath=//div[@class='crm-customData-block']//div[@class='custom-group custom-group-$customGroupTitle crm-accordion-wrapper collapsed']"); |
| 247 | $this->click("xpath=//div[@class='crm-customData-block']//div[@class='custom-group custom-group-$customGroupTitle crm-accordion-wrapper collapsed']//div[1]"); |
| 248 | $this->click("xpath=//div[@class='crm-customData-block']//div[@class='custom-group custom-group-$customGroupTitle crm-accordion-wrapper']//div[2]//table//tbody//tr[2]//td[2]//table//tbody//tr[1]//td[1]//label"); |
| 249 | $this->click("xpath=//div[@class='crm-customData-block']//div[@class='custom-group custom-group-$customGroupTitle crm-accordion-wrapper']//div[2]//table//tbody//tr[4]//td[2]//table//tbody//tr[1]//td[1]//label"); |
| 250 | |
| 251 | // Choose Registration Date. |
| 252 | // Using helper webtestFillDate function. |
| 253 | $this->webtestFillDate('register_date', 'now'); |
| 254 | $today = date('F jS, Y', strtotime('now')); |
| 255 | // May 5th, 2010 |
| 256 | |
| 257 | // Select participant status |
| 258 | $this->select('status_id', 'value=1'); |
| 259 | |
| 260 | // Setting registration source |
| 261 | $this->type('source', 'Event StandaloneAddTest Webtest'); |
| 262 | |
| 263 | // Since we're here, let's check of screen help is being displayed properly |
| 264 | $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).')); |
| 265 | |
| 266 | // Select an event fee |
| 267 | $this->waitForElementPresent('priceset'); |
| 268 | |
| 269 | $this->click("xpath=//input[@class='crm-form-radio']"); |
| 270 | |
| 271 | // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle) |
| 272 | $this->type('total_amount', '800'); |
| 273 | |
| 274 | // Select payment method = Check and enter chk number |
| 275 | $this->select('payment_instrument_id', 'value=4'); |
| 276 | $this->waitForElementPresent('check_number'); |
| 277 | $this->type('check_number', '1044'); |
| 278 | |
| 279 | // Clicking save. |
| 280 | $this->clickLink('_qf_Participant_upload-bottom'); |
| 281 | |
| 282 | // Is status message correct? |
| 283 | $this->checkCRMAlert("Event registration for $displayName has been added"); |
| 284 | |
| 285 | $this->waitForElementPresent("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 286 | //click through to the participant view screen |
| 287 | $this->clickAjaxLink("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']", '_qf_ParticipantView_cancel-bottom'); |
| 288 | |
| 289 | $this->webtestVerifyTabularData( |
| 290 | array( |
| 291 | 'Event' => 'Rain-forest Cup Youth Soccer Tournament', |
| 292 | 'Participant Role' => 'Attendee, Volunteer, Host', |
| 293 | 'Status' => 'Registered', |
| 294 | 'Event Source' => 'Event StandaloneAddTest Webtest', |
| 295 | 'Fees' => '$ 800.00', |
| 296 | ) |
| 297 | ); |
| 298 | |
| 299 | $this->assertTrue($this->isTextPresent("$customGroupTitle")); |
| 300 | $this->assertTrue($this->isTextPresent("$checkboxOptionLabel1")); |
| 301 | $this->assertTrue($this->isTextPresent("$radioOptionLabel1")); |
| 302 | |
| 303 | // check contribution record as well |
| 304 | //click through to the contribution view screen |
| 305 | $this->clickAjaxLink("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom'); |
| 306 | |
| 307 | $this->webtestVerifyTabularData( |
| 308 | array( |
| 309 | 'From' => $displayName, |
| 310 | 'Financial Type' => 'Event Fee', |
| 311 | 'Contribution Status' => 'Completed', |
| 312 | 'Paid By' => 'Check', |
| 313 | 'Check Number' => '1044', |
| 314 | ) |
| 315 | ); |
| 316 | $this->verifyText("xpath=//table/tbody/tr/td[text()='Total Amount']/following-sibling::td/strong", preg_quote('$ 800.00'), 'In line ' . __LINE__); |
| 317 | } |
| 318 | |
| 319 | public function testEventAddMultipleParticipants() { |
| 320 | $this->webtestLogin(); |
| 321 | |
| 322 | $processorId = $this->webtestAddPaymentProcessor(); |
| 323 | |
| 324 | $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone&mode=test&eid=3"); |
| 325 | |
| 326 | $contacts = array(); |
| 327 | |
| 328 | $this->assertTrue($this->isTextPresent("New Event Registration"), "Page title 'New Event Registration' missing"); |
| 329 | $this->assertTrue($this->isTextPresent("A TEST transaction will be submitted"), "test mode status 'A TEST transaction will be submitted' missing"); |
| 330 | $contacts[] = $this->_fillParticipantDetails($processorId); |
| 331 | $this->clickLink('_qf_Participant_upload_new-bottom'); |
| 332 | |
| 333 | $this->assertTrue($this->isTextPresent("New Event Registration"), "Page title 'New Event Registration' missing"); |
| 334 | $this->assertTrue($this->isTextPresent("A TEST transaction will be submitted"), "test mode status 'A TEST transaction will be submitted' missing"); |
| 335 | $contacts[] = $this->_fillParticipantDetails($processorId); |
| 336 | $this->clickLink('_qf_Participant_upload_new-bottom'); |
| 337 | |
| 338 | //searching the paricipants |
| 339 | $this->openCiviPage("event/search", "reset=1"); |
| 340 | $this->type('sort_name', 'Individual'); |
| 341 | $eventName = "Rain-forest Cup Youth Soccer Tournament"; |
| 342 | $this->select2("event_id", $eventName, FALSE, FALSE); |
| 343 | $this->check('participant_test'); |
| 344 | $this->clickLink("_qf_Search_refresh", "participantSearch"); |
| 345 | |
| 346 | //verifying the registered participants |
| 347 | $status = "Registered (test)"; |
| 348 | |
| 349 | foreach ($contacts as $contact) { |
| 350 | $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$contact['sort_name']}']/../../td[9]", preg_quote($status)); |
| 351 | $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$contact['sort_name']}']/../../td[4]/a", preg_quote($eventName)); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | public function testAjaxCustomGroupLoad() { |
| 356 | $this->webtestLogin(); |
| 357 | |
| 358 | $customSets = array( |
| 359 | array( |
| 360 | 'entity' => 'ParticipantEventName', |
| 361 | 'subEntity' => 'Fall Fundraiser Dinner', |
| 362 | 'triggerElement' => array('name' => "event_id", 'type' => "select2") |
| 363 | ), |
| 364 | array( |
| 365 | 'entity' => 'ParticipantRole', |
| 366 | 'subEntity' => 'Attendee', |
| 367 | 'triggerElement' => array('name' => 'role_id', 'type' => "select") |
| 368 | ), |
| 369 | ); |
| 370 | $pageUrl = array('url' => "participant/add", 'args' => "reset=1&action=add&context=standalone"); |
| 371 | $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl, TRUE); |
| 372 | } |
| 373 | |
| 374 | /* |
| 375 | * Webtest for CRM-10983 |
| 376 | */ |
| 377 | public function testCheckDuplicateCustomDataLoad() { |
| 378 | $this->webtestLogin(); |
| 379 | |
| 380 | $customSets = array( |
| 381 | array( |
| 382 | 'entity' => 'ParticipantEventType', |
| 383 | 'subEntity' => '- Any -', |
| 384 | 'triggerElement' => array('name' => "event_id", 'type' => "select") |
| 385 | ), |
| 386 | array( |
| 387 | 'entity' => 'ParticipantEventName', |
| 388 | 'subEntity' => '- Any -', |
| 389 | 'triggerElement' => array('name' => "event_id", 'type' => "select") |
| 390 | ), |
| 391 | array( |
| 392 | 'entity' => 'ParticipantEventName', |
| 393 | 'subEntity' => 'Rain-forest Cup Youth Soccer Tournament', |
| 394 | 'triggerElement' => array('name' => "event_id", 'type' => "select") |
| 395 | ), |
| 396 | array('entity' => 'ParticipantRole', 'subEntity' => '- Any -', 'triggerElement' => array('type' => "checkbox")), |
| 397 | array('entity' => 'ParticipantRole', 'subEntity' => 'Volunteer', 'triggerElement' => array('type' => "checkbox")), |
| 398 | ); |
| 399 | |
| 400 | $return = $this->addCustomGroupField($customSets); |
| 401 | |
| 402 | $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom"); |
| 403 | |
| 404 | // Select event. |
| 405 | $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament"); |
| 406 | |
| 407 | // Select role. |
| 408 | $this->multiselect2('role_id', array('Volunteer')); |
| 409 | |
| 410 | foreach ($return as $values) { |
| 411 | foreach ($values as $entityType => $customData) { |
| 412 | //checking for duplicate custom data present or not |
| 413 | $this->assertElementPresent("xpath=//*[@class='crm-customData-block']/div[@class='custom-group custom-group-{$customData['cgtitle']} crm-accordion-wrapper ']"); |
| 414 | $this->assertEquals(1, $this->getXpathCount("//*[@class='crm-customData-block']/div[@class='custom-group custom-group-{$customData['cgtitle']} crm-accordion-wrapper ']")); |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * @param int $processorId |
| 421 | */ |
| 422 | public function _fillParticipantDetails($processorId) { |
| 423 | $contact = $this->createDialogContact(); |
| 424 | |
| 425 | $event_id = $this->getAttribute("xpath=//*[@id='event_id']@value"); |
| 426 | //check if it is the selected event |
| 427 | $this->assertEquals($event_id, 3); |
| 428 | $this->select("role_id", "value=1"); |
| 429 | $this->webtestAddCreditCardDetails(); |
| 430 | $this->webtestAddBillingDetails(); |
| 431 | return $contact; |
| 432 | } |
| 433 | } |