| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.5 | |
| 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_AddPricesetTest |
| 31 | */ |
| 32 | class WebTest_Event_AddPricesetTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | function testAddPriceSet() { |
| 39 | |
| 40 | // Log in using webtestLogin() method |
| 41 | $this->webtestLogin(); |
| 42 | |
| 43 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
| 44 | $usedFor = 'Event'; |
| 45 | $setHelp = 'Select your conference options.'; |
| 46 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
| 47 | |
| 48 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form |
| 49 | // which is where we are after adding Price Set. |
| 50 | $sid = $this->urlArg('sid'); |
| 51 | $this->assertType('numeric', $sid); |
| 52 | |
| 53 | $validStrings = array(); |
| 54 | |
| 55 | $fields = array( |
| 56 | 'Full Conference' => 'Text', |
| 57 | 'Meal Choice' => 'Select', |
| 58 | 'Pre-conference Meetup?' => 'Radio', |
| 59 | 'Evening Sessions' => 'CheckBox', |
| 60 | ); |
| 61 | $this->_testAddPriceFields($fields, $validateStrings); |
| 62 | // var_dump($validateStrings); |
| 63 | |
| 64 | // load the Price Set Preview and check for expected values |
| 65 | $this->_testVerifyPriceSet($validateStrings, $sid); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @param $setTitle |
| 70 | * @param $usedFor |
| 71 | * @param $setHelp |
| 72 | * @param string $financialType |
| 73 | */ |
| 74 | function _testAddSet($setTitle, $usedFor, $setHelp, $financialType = 'Event Fee') { |
| 75 | $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom'); |
| 76 | |
| 77 | // Enter Priceset fields (Title, Used For ...) |
| 78 | $this->type('title', $setTitle); |
| 79 | if ($usedFor == 'Event') { |
| 80 | $this->check('extends[1]'); |
| 81 | } |
| 82 | elseif ($usedFor == 'Contribution') { |
| 83 | $this->check('extends[2]'); |
| 84 | } |
| 85 | |
| 86 | $this->select("financial_type_id", "label={$financialType}"); |
| 87 | |
| 88 | $this->type('help_pre', $setHelp); |
| 89 | |
| 90 | $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); |
| 91 | $this->clickLink('_qf_Set_next-bottom', 'newPriceField'); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @param $fields |
| 96 | * @param $validateStrings |
| 97 | * @param bool $dateSpecificFields |
| 98 | */ |
| 99 | function _testAddPriceFields(&$fields, &$validateStrings, $dateSpecificFields = FALSE) { |
| 100 | $this->clickLink('newPriceField', '_qf_Field_cancel-bottom', FALSE); |
| 101 | foreach ($fields as $label => $type) { |
| 102 | $validateStrings[] = $label; |
| 103 | |
| 104 | $this->type('label', $label); |
| 105 | $this->select('html_type', "value={$type}"); |
| 106 | |
| 107 | switch ($type) { |
| 108 | case 'Text': |
| 109 | $validateStrings[] = '525.00'; |
| 110 | $this->type('price', '525.00'); |
| 111 | $this->select('financial_type_id', 'Donation'); |
| 112 | if ($dateSpecificFields == TRUE) { |
| 113 | $this->webtestFillDateTime('active_on', '+1 week'); |
| 114 | } |
| 115 | else { |
| 116 | $this->check('is_required'); |
| 117 | } |
| 118 | break; |
| 119 | |
| 120 | case 'Select': |
| 121 | $options = array( |
| 122 | 1 => array('label' => 'Chicken', |
| 123 | 'amount' => '30.00', |
| 124 | 'financial_type_id' => 'Donation' |
| 125 | ), |
| 126 | 2 => array( |
| 127 | 'label' => 'Vegetarian', |
| 128 | 'amount' => '25.00', |
| 129 | 'financial_type_id' => 'Donation' |
| 130 | ), |
| 131 | ); |
| 132 | $this->addMultipleChoiceOptions($options, $validateStrings); |
| 133 | if ($dateSpecificFields == TRUE) { |
| 134 | $this->webtestFillDateTime('expire_on', '-1 week'); |
| 135 | } |
| 136 | break; |
| 137 | |
| 138 | case 'Radio': |
| 139 | $options = array( |
| 140 | 1 => array('label' => 'Yes', |
| 141 | 'amount' => '50.00', |
| 142 | 'financial_type_id' => 'Donation' |
| 143 | |
| 144 | ), |
| 145 | 2 => array( |
| 146 | 'label' => 'No', |
| 147 | 'amount' => '0', |
| 148 | 'financial_type_id' => 'Donation' |
| 149 | ), |
| 150 | ); |
| 151 | $this->addMultipleChoiceOptions($options, $validateStrings); |
| 152 | $this->click('is_required'); |
| 153 | if ($dateSpecificFields == TRUE) { |
| 154 | $this->webtestFillDateTime('active_on', '-1 week'); |
| 155 | } |
| 156 | break; |
| 157 | |
| 158 | case 'CheckBox': |
| 159 | $options = array( |
| 160 | 1 => array('label' => 'First Night', |
| 161 | 'amount' => '15.00', |
| 162 | 'financial_type_id' => 'Donation' |
| 163 | ), |
| 164 | 2 => array( |
| 165 | 'label' => 'Second Night', |
| 166 | 'amount' => '15.00', |
| 167 | 'financial_type_id' => 'Donation' |
| 168 | ), |
| 169 | ); |
| 170 | $this->addMultipleChoiceOptions($options, $validateStrings); |
| 171 | if ($dateSpecificFields == TRUE) { |
| 172 | $this->webtestFillDateTime('expire_on', '+1 week'); |
| 173 | } |
| 174 | break; |
| 175 | |
| 176 | default: |
| 177 | break; |
| 178 | } |
| 179 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE); |
| 180 | $this->waitForText('crm-notification-container', "Price Field '".$label."' has been saved."); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * @param $validateStrings |
| 186 | * @param $sid |
| 187 | */ |
| 188 | function _testVerifyPriceSet($validateStrings, $sid) { |
| 189 | // verify Price Set at Preview page |
| 190 | // start at Manage Price Sets listing |
| 191 | $this->openCiviPage('admin/price', 'reset=1'); |
| 192 | |
| 193 | // Use the price set id ($sid) to pick the correct row |
| 194 | $this->clickLink("//*[@id='price_set-{$sid}']/td[4]/span[1]/a[2]", '_qf_Preview_cancel-bottom'); |
| 195 | |
| 196 | // Check for expected price set field strings |
| 197 | $this->assertStringsPresent($validateStrings); |
| 198 | } |
| 199 | |
| 200 | function testRegisterWithPriceSet() { |
| 201 | // Log in using webtestLogin() method |
| 202 | $this->webtestLogin(); |
| 203 | |
| 204 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
| 205 | $usedFor = 'Event'; |
| 206 | $setHelp = 'Select your conference options.'; |
| 207 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
| 208 | |
| 209 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form |
| 210 | // which is where we are after adding Price Set. |
| 211 | $sid = $this->urlArg('sid'); |
| 212 | $this->assertType('numeric', $sid); |
| 213 | |
| 214 | $validStrings = array(); |
| 215 | $fields = array( |
| 216 | 'Full Conference' => 'Text', |
| 217 | 'Meal Choice' => 'Select', |
| 218 | 'Pre-conference Meetup?' => 'Radio', |
| 219 | 'Evening Sessions' => 'CheckBox', |
| 220 | ); |
| 221 | $this->_testAddPriceFields($fields, $validateStrings); |
| 222 | |
| 223 | // load the Price Set Preview and check for expected values |
| 224 | $this->_testVerifyPriceSet($validateStrings, $sid); |
| 225 | |
| 226 | // We need a payment processor |
| 227 | $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7); |
| 228 | $this->webtestAddPaymentProcessor($processorName); |
| 229 | |
| 230 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
| 231 | |
| 232 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 233 | $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com'; |
| 234 | $eventDescription = 'Here is a description for this conference.'; |
| 235 | |
| 236 | $this->select('event_type_id', 'value=1'); |
| 237 | |
| 238 | // Attendee role s/b selected now. |
| 239 | $this->select('default_role_id', 'value=1'); |
| 240 | |
| 241 | // Enter Event Title, Summary and Description |
| 242 | $this->type('title', $eventTitle); |
| 243 | $this->type('summary', 'This is a great conference. Sign up now!'); |
| 244 | |
| 245 | // Type description in ckEditor (fieldname, text to type, editor) |
| 246 | $this->fillRichTextField('description', $eventDescription); |
| 247 | |
| 248 | // Choose Start and End dates. |
| 249 | // Using helper webtestFillDate function. |
| 250 | $this->webtestFillDateTime("start_date", "+1 week"); |
| 251 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); |
| 252 | |
| 253 | $this->type('max_participants', '50'); |
| 254 | $this->click('is_map'); |
| 255 | $this->click('_qf_EventInfo_upload-bottom'); |
| 256 | |
| 257 | // Wait for Location tab form to load |
| 258 | $this->waitForElementPresent('_qf_Location_upload_done-bottom'); |
| 259 | |
| 260 | // Go to Fees tab |
| 261 | $this->click('link=Fees'); |
| 262 | $this->waitForElementPresent('_qf_Fee_upload_done-bottom'); |
| 263 | $this->click('CIVICRM_QFID_1_is_monetary'); |
| 264 | $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']"); |
| 265 | $this->select('financial_type_id','label=Event Fee'); |
| 266 | $this->select('price_set_id', 'label=' . $setTitle); |
| 267 | |
| 268 | |
| 269 | // intro text for registration page |
| 270 | $registerIntro = 'Fill in all the fields below and click Continue.'; |
| 271 | $this->clickLink('_qf_Fee_upload-bottom', 'link=Online Registration', FALSE); |
| 272 | |
| 273 | // Go to Online Registration tab |
| 274 | $this->click('link=Online Registration'); |
| 275 | $this->waitForElementPresent('_qf_Registration_upload-bottom'); |
| 276 | |
| 277 | $this->check('is_online_registration'); |
| 278 | $this->assertChecked('is_online_registration'); |
| 279 | |
| 280 | $this->click('intro_text-plain'); |
| 281 | $this->fillRichTextField('intro_text', $registerIntro); |
| 282 | |
| 283 | // enable confirmation email |
| 284 | $this->click('CIVICRM_QFID_1_is_email_confirm'); |
| 285 | $this->type('confirm_from_name', 'Jane Doe'); |
| 286 | $this->type('confirm_from_email', 'jane.doe@example.org'); |
| 287 | |
| 288 | $this->click('_qf_Registration_upload-bottom'); |
| 289 | $this->waitForTextPresent("'Online Registration' information has been saved."); |
| 290 | |
| 291 | // verify event input on info page |
| 292 | // start at Manage Events listing |
| 293 | $this->openCiviPage('event/manage', 'reset=1'); |
| 294 | $this->click("link=$eventTitle"); |
| 295 | |
| 296 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 297 | $eventInfoUrl = $this->getLocation(); |
| 298 | |
| 299 | $permissions = array("edit-1-register-for-events"); |
| 300 | $this->changePermissions($permissions); |
| 301 | $this->webtestLogout(); |
| 302 | $this->open($eventInfoUrl); |
| 303 | $this->click('link=Register Now'); |
| 304 | $this->waitForElementPresent('_qf_Register_upload-bottom'); |
| 305 | |
| 306 | $this->type("xpath=//input[@class='four crm-form-text required']", "1"); |
| 307 | $this->click("xpath=//input[@class='crm-form-radio']"); |
| 308 | $this->click("xpath=//input[@class='crm-form-checkbox']"); |
| 309 | $this->type("first_name", "Jane"); |
| 310 | $lastName = "Smith" . substr(sha1(rand()), 0, 7); |
| 311 | $this->type("last_name", $lastName); |
| 312 | $this->type('email-Primary', $email); |
| 313 | |
| 314 | $this->waitForElementPresent('credit_card_type'); |
| 315 | $this->select('credit_card_type', 'value=Visa'); |
| 316 | $this->type('credit_card_number', '4111111111111111'); |
| 317 | $this->type('cvv2', '000'); |
| 318 | $this->select('credit_card_exp_date[M]', 'value=1'); |
| 319 | $this->select('credit_card_exp_date[Y]', 'value=2020'); |
| 320 | $this->type('billing_first_name', 'Jane'); |
| 321 | $this->type('billing_last_name', $lastName); |
| 322 | $this->type('billing_street_address-5', '15 Main St.'); |
| 323 | $this->type(' billing_city-5', 'San Jose'); |
| 324 | $this->select('billing_country_id-5', 'value=1228'); |
| 325 | $this->select('billing_state_province_id-5', 'value=1004'); |
| 326 | $this->type('billing_postal_code-5', '94129'); |
| 327 | |
| 328 | $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom'); |
| 329 | $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information'); |
| 330 | $this->assertStringsPresent($confirmStrings); |
| 331 | $this->click('_qf_Confirm_next-bottom'); |
| 332 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 333 | $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date'); |
| 334 | $this->assertStringsPresent($thankStrings); |
| 335 | |
| 336 | // Log in using webtestLogin() method |
| 337 | $this->webtestLogin(); |
| 338 | |
| 339 | //Find Participant |
| 340 | $this->openCiviPage('event/search', 'reset=1', '_qf_Search_refresh'); |
| 341 | |
| 342 | $this->type('sort_name', "$email"); |
| 343 | $this->clickLink('_qf_Search_refresh', "xpath=id('participantSearch')/table/tbody/tr/td[11]/span/a[text()='View']"); |
| 344 | $this->click("xpath=id('participantSearch')/table/tbody/tr/td[11]/span/a[text()='View']"); |
| 345 | $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom'); |
| 346 | |
| 347 | $expected = array( |
| 348 | 2 => 'Full Conference', |
| 349 | 3 => 'Pre-conference Meetup? - Yes', |
| 350 | 4 => 'Evening Sessions - First Night', |
| 351 | ); |
| 352 | foreach ($expected as $value => $label) { |
| 353 | $this->verifyText("xpath=id('ParticipantView')/div[2]/table[1]/tbody/tr[8]/td[2]/table/tbody/tr[$value]/td", $label); |
| 354 | } |
| 355 | // Fixme: We can't asset full string like - "Event Total: $ 590.00" as it has special char |
| 356 | $this->assertStringsPresent(' 590.00'); |
| 357 | $this->click('_qf_ParticipantView_cancel-bottom'); |
| 358 | } |
| 359 | |
| 360 | function testParticipantWithDateSpecificPriceSet() { |
| 361 | |
| 362 | // Log in using webtestLogin() method |
| 363 | $this->webtestLogin(); |
| 364 | |
| 365 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
| 366 | $usedFor = 'Event'; |
| 367 | $setHelp = 'Select your conference options.'; |
| 368 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
| 369 | |
| 370 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form |
| 371 | // which is where we are after adding Price Set. |
| 372 | $sid = $this->urlArg('sid'); |
| 373 | $this->assertType('numeric', $sid); |
| 374 | |
| 375 | $validStrings = array(); |
| 376 | $fields = array( |
| 377 | 'Full Conference' => 'Text', |
| 378 | 'Meal Choice' => 'Select', |
| 379 | 'Pre-conference Meetup?' => 'Radio', |
| 380 | 'Evening Sessions' => 'CheckBox', |
| 381 | ); |
| 382 | $this->_testAddPriceFields($fields, $validateStrings, TRUE); |
| 383 | |
| 384 | // load the Price Set Preview and check for expected values |
| 385 | $this->_testVerifyPriceSet($validateStrings, $sid); |
| 386 | |
| 387 | // We need a payment processor |
| 388 | $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7); |
| 389 | $this->webtestAddPaymentProcessor($processorName); |
| 390 | |
| 391 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
| 392 | |
| 393 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 394 | $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com'; |
| 395 | $eventDescription = 'Here is a description for this conference.'; |
| 396 | |
| 397 | $this->select('event_type_id', 'value=1'); |
| 398 | |
| 399 | // Attendee role s/b selected now. |
| 400 | $this->select('default_role_id', 'value=1'); |
| 401 | |
| 402 | // Enter Event Title, Summary and Description |
| 403 | $this->type('title', $eventTitle); |
| 404 | $this->type('summary', 'This is a great conference. Sign up now!'); |
| 405 | |
| 406 | // Type description in ckEditor (fieldname, text to type, editor) |
| 407 | $this->fillRichTextField('description', $eventDescription ); |
| 408 | |
| 409 | // Choose Start and End dates. |
| 410 | // Using helper webtestFillDate function. |
| 411 | $this->webtestFillDateTime("start_date", "+1 week"); |
| 412 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); |
| 413 | |
| 414 | $this->type('max_participants', '50'); |
| 415 | $this->click('is_map'); |
| 416 | $this->click('_qf_EventInfo_upload-bottom'); |
| 417 | |
| 418 | // Wait for Location tab form to load |
| 419 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 420 | |
| 421 | // Go to Fees tab |
| 422 | $this->click('link=Fees'); |
| 423 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); |
| 424 | $this->click('CIVICRM_QFID_1_is_monetary'); |
| 425 | $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']"); |
| 426 | $this->select('financial_type_id','label=Event Fee'); |
| 427 | $this->select('price_set_id', 'label=' . $setTitle); |
| 428 | |
| 429 | $this->clickLink('_qf_Fee_upload-bottom', 'link=Online Registration', FALSE); |
| 430 | |
| 431 | // intro text for registration page |
| 432 | $registerIntro = 'Fill in all the fields below and click Continue.'; |
| 433 | |
| 434 | // Go to Online Registration tab |
| 435 | $this->click('link=Online Registration'); |
| 436 | $this->waitForElementPresent('_qf_Registration_upload-bottom'); |
| 437 | |
| 438 | $this->check('is_online_registration'); |
| 439 | $this->assertChecked('is_online_registration'); |
| 440 | |
| 441 | $this->click('intro_text-plain'); |
| 442 | $this->fillRichTextField('intro_text', $registerIntro); |
| 443 | |
| 444 | // enable confirmation email |
| 445 | $this->click('CIVICRM_QFID_1_is_email_confirm'); |
| 446 | $this->type('confirm_from_name', 'Jane Doe'); |
| 447 | $this->type('confirm_from_email', 'jane.doe@example.org'); |
| 448 | |
| 449 | $this->click('_qf_Registration_upload-bottom'); |
| 450 | $this->waitForTextPresent("'Online Registration' information has been saved."); |
| 451 | |
| 452 | // verify event input on info page |
| 453 | // start at Manage Events listing |
| 454 | $this->openCiviPage('event/manage', 'reset=1'); |
| 455 | $this->click("link=$eventTitle"); |
| 456 | |
| 457 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 458 | // Adding contact with randomized first name (so we can then select that contact when creating event registration) |
| 459 | // We're using Quick Add block on the main page for this. |
| 460 | $firstName = substr(sha1(rand()), 0, 7); |
| 461 | $lastName = 'Anderson'. substr(sha1(rand()), 0, 7); |
| 462 | $this->webtestAddContact($firstName, $lastName, TRUE); |
| 463 | $contactName = "$lastName, $firstName"; |
| 464 | $displayName = "$firstName $lastName"; |
| 465 | |
| 466 | $this->openCiviPage('participant/add', 'reset=1&action=add&context=standalone', '_qf_Participant_upload-bottom'); |
| 467 | |
| 468 | // Type contact last name in contact auto-complete, wait for dropdown and click first result |
| 469 | $this->webtestFillAutocomplete($firstName); |
| 470 | |
| 471 | // Select event. Based on label for now. |
| 472 | $this->select2('event_id', "$eventTitle"); |
| 473 | // Select role |
| 474 | $this->multiselect2('role_id', array('Volunteer')); |
| 475 | |
| 476 | $this->waitForElementPresent("xpath=//input[@class='crm-form-radio']"); |
| 477 | $this->click("xpath=//input[@class='crm-form-radio']"); |
| 478 | $this->click("xpath=//input[@class='crm-form-checkbox']"); |
| 479 | |
| 480 | // Choose Registration Date. |
| 481 | // Using helper webtestFillDate function. |
| 482 | $this->webtestFillDate('register_date', 'now'); |
| 483 | $today = date('F jS, Y', strtotime('now')); |
| 484 | |
| 485 | // Select participant status |
| 486 | $this->select('status_id', 'value=1'); |
| 487 | |
| 488 | // Clicking save. |
| 489 | $this->click('_qf_Participant_upload-bottom'); |
| 490 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 491 | // Is status message correct? |
| 492 | $this->waitForText("crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!"); |
| 493 | |
| 494 | $this->waitForElementPresent("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 495 | |
| 496 | //click through to the participant view screen |
| 497 | $this->click("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 498 | $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom'); |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Function to test to regiter participant for event with |
| 503 | |
| 504 | * multiple price fields in price-set |
| 505 | * CRM-11986 |
| 506 | |
| 507 | * |
| 508 | */ |
| 509 | function testEventWithPriceSet() { |
| 510 | |
| 511 | // Log in using webtestLogin() method |
| 512 | $this->webtestLogin(); |
| 513 | |
| 514 | // Adding contact with randomized first name (so we can then select that contact when creating event registration) |
| 515 | // We're using Quick Add block on the main page for this. |
| 516 | $firstName = substr(sha1(rand()), 0, 7); |
| 517 | $lastName = 'Anderson'. substr(sha1(rand()), 0, 7); |
| 518 | $this->webtestAddContact($firstName, $lastName, TRUE); |
| 519 | $contactName = "$lastName, $firstName"; |
| 520 | $displayName = "$firstName $lastName"; |
| 521 | |
| 522 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
| 523 | $usedFor = 'Event'; |
| 524 | $setHelp = 'Select your conference options.'; |
| 525 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
| 526 | |
| 527 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form |
| 528 | // which is where we are after adding Price Set. |
| 529 | $sid = $this->urlArg('sid'); |
| 530 | $this->assertType('numeric', $sid); |
| 531 | |
| 532 | $validStrings = array(); |
| 533 | $fields = array( |
| 534 | 'Full Conference' => 'Text', |
| 535 | 'Pre-conference Meetup?' => 'Radio', |
| 536 | 'Evening Sessions' => 'CheckBox', |
| 537 | ); |
| 538 | $this->_testAddPriceFields($fields, $validateStrings); |
| 539 | |
| 540 | // load the Price Set Preview and check for expected values |
| 541 | $this->_testVerifyPriceSet($validateStrings, $sid); |
| 542 | |
| 543 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
| 544 | |
| 545 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 546 | $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com'; |
| 547 | $eventDescription = 'Here is a description for this conference.'; |
| 548 | |
| 549 | $this->select('event_type_id', 'value=1'); |
| 550 | |
| 551 | // Attendee role s/b selected now. |
| 552 | $this->select('default_role_id', 'value=1'); |
| 553 | |
| 554 | // Enter Event Title, Summary and Description |
| 555 | $this->type('title', $eventTitle); |
| 556 | $this->type('summary', 'This is a great conference. Sign up now!'); |
| 557 | |
| 558 | // Type description in ckEditor (fieldname, text to type, editor) |
| 559 | $this->fillRichTextField('description', $eventDescription); |
| 560 | |
| 561 | // Choose Start and End dates. |
| 562 | // Using helper webtestFillDate function. |
| 563 | $this->webtestFillDateTime("start_date", "+1 week"); |
| 564 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); |
| 565 | |
| 566 | $this->type('max_participants', '50'); |
| 567 | $this->click('is_map'); |
| 568 | $this->click('_qf_EventInfo_upload-bottom'); |
| 569 | |
| 570 | // Wait for Location tab form to load |
| 571 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 572 | |
| 573 | // Go to Fees tab |
| 574 | $this->click('link=Fees'); |
| 575 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); |
| 576 | $this->click('CIVICRM_QFID_1_is_monetary'); |
| 577 | $this->select('financial_type_id','label=Event Fee'); |
| 578 | $this->select('price_set_id', 'label=' . $setTitle); |
| 579 | |
| 580 | $this->click('_qf_Fee_upload-bottom'); |
| 581 | $this->waitForText("crm-notification-container","'Fees' information has been saved."); |
| 582 | |
| 583 | $this->openCiviPage('participant/add', 'reset=1&action=add&context=standalone', '_qf_Participant_upload-bottom'); |
| 584 | |
| 585 | // Type contact last name in contact auto-complete, wait for dropdown and click first result |
| 586 | $this->webtestFillAutocomplete($firstName); |
| 587 | $this->select2('event_id', $eventTitle); |
| 588 | // Select role |
| 589 | $this->multiselect2('role_id', array('Volunteer')); |
| 590 | |
| 591 | // Choose Registration Date. |
| 592 | // Using helper webtestFillDate function. |
| 593 | $this->webtestFillDate('register_date', 'now'); |
| 594 | $today = date('F jS, Y', strtotime('now')); |
| 595 | // May 5th, 2010 |
| 596 | |
| 597 | // Select participant status |
| 598 | $this->select('status_id', 'value=1'); |
| 599 | |
| 600 | // Setting registration source |
| 601 | $this->type('source', 'Event StandaloneAddTest Webtest'); |
| 602 | |
| 603 | // Select an event fee |
| 604 | $this->waitForElementPresent('priceset'); |
| 605 | $this->type("//div[@id='priceset']/div[2]/div[2]/input", '5'); |
| 606 | $this->fireEvent("//div[@id='priceset']/div[2]/div[2]/input", 'blur'); |
| 607 | $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[1]/span/input"); |
| 608 | $this->click("xpath=//div[@id='priceset']/div[4]/div[2]/div[1]/span/input"); |
| 609 | $this->click("xpath=//div[@id='priceset']/div[4]/div[2]/div[2]/span/input"); |
| 610 | |
| 611 | // Select payment method = Check and enter chk number |
| 612 | $this->select('payment_instrument_id', 'value=4'); |
| 613 | $this->waitForElementPresent('check_number'); |
| 614 | $this->type('check_number', '1044'); |
| 615 | |
| 616 | // Clicking save. |
| 617 | $this->click('_qf_Participant_upload-bottom'); |
| 618 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 619 | |
| 620 | // Is status message correct? |
| 621 | $this->assertElementContainsText("css=#crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!"); |
| 622 | |
| 623 | $this->waitForElementPresent("xpath=//form[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 624 | //click through to the participant view screen |
| 625 | $this->click("xpath=//form[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 626 | $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom'); |
| 627 | |
| 628 | $this->webtestVerifyTabularData( |
| 629 | array( |
| 630 | 'Event' => $eventTitle, |
| 631 | 'Participant Role' => 'Attendee', |
| 632 | 'Status' => 'Registered', |
| 633 | 'Event Source' => 'Event StandaloneAddTest Webtest', |
| 634 | ) |
| 635 | ); |
| 636 | $this->waitForElementPresent("xpath=//table/tbody/tr/td[text()='Fees']/following-sibling::td"); |
| 637 | $this->verifyText("xpath=//table/tbody/tr/td[text()='Fees']/following-sibling::td/table/tbody/tr[2]/td", preg_quote('$ 2,705.00'), 'In line ' . __LINE__); |
| 638 | $expectedLineItems = array( |
| 639 | 2 => array( |
| 640 | 1 => 'Full Conference', |
| 641 | 2 => '5', |
| 642 | 3 => '$ 525.00', |
| 643 | 4 => '$ 2,625.00', |
| 644 | ), |
| 645 | 3 => array( |
| 646 | 2 => '1', |
| 647 | 3 => '$ 50.00', |
| 648 | 4 => '$ 50.00', |
| 649 | ), |
| 650 | 4 => array( |
| 651 | 1 => 'Evening Sessions - First Night', |
| 652 | 2 => '1', |
| 653 | 3 => '$ 15.00', |
| 654 | 4 => '$ 15.00', |
| 655 | ), |
| 656 | 5 => array( |
| 657 | 1 => 'Evening Sessions - Second Night', |
| 658 | 2 => '1', |
| 659 | 3 => '$ 15.00', |
| 660 | 4 => '$ 15.00', |
| 661 | ), |
| 662 | ); |
| 663 | $this->_checkLineItems($expectedLineItems); |
| 664 | // check contribution record as well |
| 665 | // click through to the contribution view screen |
| 666 | $this->click("xpath=//*[@id='ParticipantView']/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 667 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); |
| 668 | |
| 669 | $this->webtestVerifyTabularData( |
| 670 | array( |
| 671 | 'From' => $displayName, |
| 672 | 'Financial Type' => 'Event Fee', |
| 673 | 'Contribution Status' => 'Completed', |
| 674 | 'Paid By' => 'Check', |
| 675 | 'Check Number' => '1044', |
| 676 | 'Received Into' => 'Deposit Bank Account', |
| 677 | ) |
| 678 | ); |
| 679 | $this->verifyText("xpath=//td[text()='Contribution Amount']/following-sibling::td//div/div", preg_quote('Contribution Total: $ 2,705.00')); |
| 680 | } |
| 681 | |
| 682 | |
| 683 | function testDeletePriceSetforEventTemplate() { |
| 684 | // Log in using webtestLogin() method |
| 685 | $this->webtestLogin(); |
| 686 | |
| 687 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
| 688 | $usedFor = 'Event'; |
| 689 | $setHelp = 'Select your conference options.'; |
| 690 | $this->_testAddSet($setTitle, $usedFor, $setHelp); |
| 691 | |
| 692 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form |
| 693 | // which is where we are after adding Price Set. |
| 694 | $sid = $this->urlArg('sid'); |
| 695 | $this->assertType('numeric', $sid); |
| 696 | |
| 697 | $validStrings = array(); |
| 698 | $fields = array( |
| 699 | 'Test Field' => 'Text', |
| 700 | ); |
| 701 | $this->_testAddPriceFields($fields, $validateStrings); |
| 702 | |
| 703 | // load the Price Set Preview and check for expected values |
| 704 | $this->_testVerifyPriceSet($validateStrings, $sid); |
| 705 | $this->openCiviPage('admin/eventTemplate', 'reset=1'); |
| 706 | $this->clickLink('newEventTemplate'); |
| 707 | $this->select("template_id", "value=6"); |
| 708 | // Wait for event type to be filled in (since page reloads) |
| 709 | $this->waitForElementPresent("template_id"); |
| 710 | // Enter Event Title, Summary and Description |
| 711 | $this->select("event_type_id", "value=4"); |
| 712 | $this->select("default_role_id", "value=1"); |
| 713 | $this->type("title", "Test Event"); |
| 714 | $this->type("summary", "This is a great conference. Sign up now!"); |
| 715 | |
| 716 | $this->click("_qf_EventInfo_upload-bottom"); |
| 717 | $this->waitForElementPresent('link=Fees'); |
| 718 | // Go to Fees tab |
| 719 | $this->click('link=Fees'); |
| 720 | $this->waitForElementPresent('_qf_Fee_upload-bottom'); |
| 721 | $this->click('CIVICRM_QFID_1_is_monetary'); |
| 722 | $this->select('financial_type_id','label=Event Fee'); |
| 723 | $this->select('price_set_id', 'label=' . $setTitle); |
| 724 | $templateId = $this->urlArg('id'); |
| 725 | $this->click('_qf_Fee_upload-bottom'); |
| 726 | |
| 727 | //check the delete for price field |
| 728 | $this->openCiviPage("admin/price/field", "reset=1&action=browse&sid={$sid}"); |
| 729 | $this->click("xpath=//table[@id='options']/tbody/tr/td[9]/span[2]/ul/li[2]/a"); |
| 730 | //assert the message |
| 731 | $this->waitForText('price_set_used_by', |
| 732 | "it is currently in use by one or more active events or contribution pages or contributions or event templates."); |
| 733 | |
| 734 | //check the delete for priceset |
| 735 | $this->openCiviPage("admin/price", "reset=1"); |
| 736 | $this->click("xpath=//table[@id='option11']/tbody/tr/td[4]/span[2]/ul/li[3]/a"); |
| 737 | // Check confirmation alert. |
| 738 | $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this price set?/", |
| 739 | $this->getConfirmation() |
| 740 | )); |
| 741 | $this->chooseOkOnNextConfirmation(); |
| 742 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 743 | //assert the message |
| 744 | $this->waitForText('price_set_used_by', |
| 745 | "it is currently in use by one or more active events or contribution pages or contributions or event templates."); |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * @param $expectedLineItems |
| 750 | */ |
| 751 | function _checkLineItems($expectedLineItems) { |
| 752 | foreach ($expectedLineItems as $lineKey => $lineValue) { |
| 753 | foreach ($lineValue as $key => $value) { |
| 754 | $this->verifyText("xpath=//table/tbody//tr/td[text()='Selections']/following-sibling::td/table/tbody//tr[$lineKey]/td[$key]", preg_quote($value)); |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | |