| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.3 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 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 | class WebTest_Event_AddEventTest extends CiviSeleniumTestCase { |
| 29 | |
| 30 | protected function setUp() { |
| 31 | parent::setUp(); |
| 32 | } |
| 33 | |
| 34 | function testAddPaidEventNoTemplate() { |
| 35 | // Log in using webtestLogin() method |
| 36 | $this->webtestLogin(); |
| 37 | |
| 38 | // We need a payment processor |
| 39 | $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7); |
| 40 | $this->webtestAddPaymentProcessor($processorName); |
| 41 | |
| 42 | $this->openCiviPage("event/add", "reset=1&action=add"); |
| 43 | |
| 44 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 45 | $eventDescription = "Here is a description for this conference."; |
| 46 | $this->_testAddEventInfo($eventTitle, $eventDescription); |
| 47 | |
| 48 | $streetAddress = "100 Main Street"; |
| 49 | $this->_testAddLocation($streetAddress); |
| 50 | |
| 51 | $this->_testAddReminder($eventTitle); |
| 52 | |
| 53 | $this->_testAddFees(FALSE, FALSE, $processorName); |
| 54 | |
| 55 | // intro text for registration page |
| 56 | $registerIntro = "Fill in all the fields below and click Continue."; |
| 57 | $multipleRegistrations = TRUE; |
| 58 | $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations); |
| 59 | |
| 60 | $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress); |
| 61 | $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings); |
| 62 | |
| 63 | $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro); |
| 64 | $registerUrl = $this->_testVerifyRegisterPage($registerStrings); |
| 65 | |
| 66 | $numberRegistrations = 3; |
| 67 | $anonymous = TRUE; |
| 68 | $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous); |
| 69 | } |
| 70 | |
| 71 | function testAddPaidEventDiscount() { |
| 72 | |
| 73 | // Log in using webtestLogin() method |
| 74 | $this->webtestLogin(); |
| 75 | |
| 76 | // We need a payment processor |
| 77 | $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7); |
| 78 | $this->webtestAddPaymentProcessor($processorName); |
| 79 | |
| 80 | $this->openCiviPage("event/add", "reset=1&action=add"); |
| 81 | |
| 82 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 83 | $eventDescription = "Here is a description for this conference."; |
| 84 | $this->_testAddEventInfo($eventTitle, $eventDescription); |
| 85 | |
| 86 | $streetAddress = "100 Main Street"; |
| 87 | $this->_testAddLocation($streetAddress); |
| 88 | |
| 89 | $this->_testAddReminder($eventTitle); |
| 90 | |
| 91 | $this->_testAddFees(TRUE, FALSE, $processorName); |
| 92 | |
| 93 | // intro text for registration page |
| 94 | $registerIntro = "Fill in all the fields below and click Continue."; |
| 95 | $multipleRegistrations = TRUE; |
| 96 | $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations); |
| 97 | |
| 98 | $discountFees = array("225.00", "300.00"); |
| 99 | |
| 100 | $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress); |
| 101 | $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings, $discountFees); |
| 102 | |
| 103 | $registerStrings = array_push($discountFees, "Member", "Non-member", $registerIntro); |
| 104 | $registerUrl = $this->_testVerifyRegisterPage($registerStrings); |
| 105 | |
| 106 | $numberRegistrations = 3; |
| 107 | $anonymous = TRUE; |
| 108 | $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous); |
| 109 | } |
| 110 | |
| 111 | function testDeletePriceSetDiscount() { |
| 112 | |
| 113 | // Log in using webtestLogin() method |
| 114 | $this->webtestLogin(); |
| 115 | |
| 116 | // We need a payment processor |
| 117 | $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7); |
| 118 | $this->webtestAddPaymentProcessor($processorName); |
| 119 | |
| 120 | $this->openCiviPage("event/add", "reset=1&action=add"); |
| 121 | |
| 122 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 123 | $eventDescription = "Here is a description for this conference."; |
| 124 | $this->_testAddEventInfo($eventTitle, $eventDescription); |
| 125 | |
| 126 | $streetAddress = "100 Main Street"; |
| 127 | $this->_testAddLocation($streetAddress); |
| 128 | |
| 129 | //Add two discounts |
| 130 | $discount = $this->_testAddFees(TRUE, FALSE, $processorName, TRUE); |
| 131 | |
| 132 | // intro text for registration page |
| 133 | $registerIntro = "Fill in all the fields below and click Continue."; |
| 134 | $multipleRegistrations = TRUE; |
| 135 | $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations); |
| 136 | |
| 137 | $discountFees = array("225.00", "300.00"); |
| 138 | |
| 139 | $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress); |
| 140 | $id = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings, $discountFees); |
| 141 | |
| 142 | $registerStrings = array_push($discountFees, "Member", "Non-member", $registerIntro); |
| 143 | $registerUrl = $this->_testVerifyRegisterPage($registerStrings); |
| 144 | |
| 145 | //Add Price Set now |
| 146 | $this->openCiviPage("event/manage/fee", "reset=1&action=update&id=$id", "_qf_Fee_upload-bottom"); |
| 147 | $this->click("xpath=//a[@id='quickconfig']"); |
| 148 | $this->waitForElementPresent('popupContainer'); |
| 149 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
| 150 | // Sleep should never be used for wait for anything to load from the server |
| 151 | // Justification for this instance: FIXME |
| 152 | sleep(3); |
| 153 | $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[1]"); |
| 154 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
| 155 | // Sleep should never be used for wait for anything to load from the server |
| 156 | // Justification for this instance: FIXME |
| 157 | sleep(3); |
| 158 | |
| 159 | //Assert quick config change and discount deletion |
| 160 | $this->openCiviPage("admin/price", "reset=1"); |
| 161 | $this->assertStringsPresent($discount); |
| 162 | } |
| 163 | |
| 164 | function testAddDeleteEventDiscount() { |
| 165 | |
| 166 | // Log in using webtestLogin() method |
| 167 | $this->webtestLogin(); |
| 168 | |
| 169 | // We need a payment processor |
| 170 | $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7); |
| 171 | $this->webtestAddPaymentProcessor($processorName); |
| 172 | |
| 173 | $this->openCiviPage("event/add", "reset=1&action=add"); |
| 174 | |
| 175 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 176 | $eventDescription = "Here is a description for this conference."; |
| 177 | $this->_testAddEventInfo($eventTitle, $eventDescription); |
| 178 | |
| 179 | $streetAddress = "100 Main Street"; |
| 180 | $this->_testAddLocation($streetAddress); |
| 181 | |
| 182 | //Add two discounts |
| 183 | $discount = $this->_testAddFees(TRUE, FALSE, $processorName, TRUE); |
| 184 | |
| 185 | // intro text for registration page |
| 186 | $registerIntro = "Fill in all the fields below and click Continue."; |
| 187 | $multipleRegistrations = TRUE; |
| 188 | $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations); |
| 189 | |
| 190 | $discountFees = array("225.00", "300.00"); |
| 191 | |
| 192 | $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress); |
| 193 | $id = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings, $discountFees); |
| 194 | |
| 195 | $registerStrings = array_push($discountFees, "Member", "Non-member", $registerIntro); |
| 196 | $registerUrl = $this->_testVerifyRegisterPage($registerStrings); |
| 197 | //Delete the discount |
| 198 | $this->_deleteDiscount($id, $eventTitle, $discount); |
| 199 | } |
| 200 | |
| 201 | function _deleteDiscount($id, $eventTitle, $discount) { |
| 202 | $this->openCiviPage("event/manage/fee", "reset=1&action=update&id=$id", "_qf_Fee_upload-bottom"); |
| 203 | $this->type("discount_name_2", ""); |
| 204 | $this->click("xpath=//tr[@id='discount_2']/td[3]/span/a"); |
| 205 | $this->click("xpath=//tr[@id='discount_2']/td[4]/span/a"); |
| 206 | $this->type("discounted_value_1_2", ""); |
| 207 | $this->type("discounted_value_2_2", ""); |
| 208 | $this->click("_qf_Fee_upload-bottom"); |
| 209 | $this->waitForPageToLoad(); |
| 210 | //Assertions |
| 211 | $this->openCiviPage("admin/price", "reset=1"); |
| 212 | $this->assertStringsPresent($discount[1]); |
| 213 | } |
| 214 | |
| 215 | function testAddPaidEventWithTemplate() { |
| 216 | |
| 217 | // Log in using webtestLogin() method |
| 218 | $this->webtestLogin(); |
| 219 | |
| 220 | // We need a payment processor |
| 221 | $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7); |
| 222 | $this->webtestAddPaymentProcessor($processorName); |
| 223 | |
| 224 | $this->openCiviPage("event/add", "reset=1&action=add"); |
| 225 | |
| 226 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 227 | $eventDescription = "Here is a description for this conference."; |
| 228 | // Select paid online registration template. |
| 229 | $templateID = 6; |
| 230 | $eventTypeID = 1; |
| 231 | $this->_testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID); |
| 232 | |
| 233 | $streetAddress = "100 Main Street"; |
| 234 | $this->_testAddLocation($streetAddress); |
| 235 | |
| 236 | $this->_testAddFees(FALSE, FALSE, $processorName); |
| 237 | |
| 238 | // intro text for registration page |
| 239 | $registerIntro = "Fill in all the fields below and click Continue."; |
| 240 | $this->_testAddOnlineRegistration($registerIntro); |
| 241 | |
| 242 | // $eventInfoStrings = array( $eventTitle, $eventDescription, $streetAddress ); |
| 243 | $eventInfoStrings = array($eventTitle, $streetAddress); |
| 244 | $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings); |
| 245 | |
| 246 | $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro); |
| 247 | $this->_testVerifyRegisterPage($registerStrings); |
| 248 | } |
| 249 | |
| 250 | function testAddFreeEventWithTemplate() { |
| 251 | |
| 252 | // Log in using webtestLogin() method |
| 253 | $this->webtestLogin(); |
| 254 | |
| 255 | $this->openCiviPage("event/add", "reset=1&action=add"); |
| 256 | |
| 257 | $eventTitle = 'My Free Meeting - ' . substr(sha1(rand()), 0, 7); |
| 258 | $eventDescription = "Here is a description for this free meeting."; |
| 259 | // Select "Free Meeting with Online Registration" template (id = 5). |
| 260 | $templateID = 5; |
| 261 | $eventTypeID = 4; |
| 262 | |
| 263 | $this->_testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID); |
| 264 | |
| 265 | $streetAddress = "100 Main Street"; |
| 266 | |
| 267 | $this->_testAddLocation($streetAddress); |
| 268 | |
| 269 | // Go to Fees tab and check that Paid Event is false (No) |
| 270 | $this->click("link=Fees"); |
| 271 | $this->waitForElementPresent("_qf_Fee_upload-bottom"); |
| 272 | $this->verifyChecked("CIVICRM_QFID_0_is_monetary"); |
| 273 | |
| 274 | // intro text for registration page |
| 275 | $registerIntro = "Fill in all the fields below and click Continue."; |
| 276 | $this->_testAddOnlineRegistration($registerIntro); |
| 277 | |
| 278 | // $eventInfoStrings = array( $eventTitle, $eventDescription, $streetAddress ); |
| 279 | $eventInfoStrings = array($eventTitle, $streetAddress); |
| 280 | $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings); |
| 281 | |
| 282 | $registerStrings = array($registerIntro); |
| 283 | $this->_testVerifyRegisterPage($registerStrings); |
| 284 | // make sure paid_event div is NOT present since this is a free event |
| 285 | $this->verifyElementNotPresent("css=div.paid_event-section"); |
| 286 | } |
| 287 | |
| 288 | function testUnpaidPaid() { |
| 289 | |
| 290 | // Log in using webtestLogin() method |
| 291 | $this->webtestLogin(); |
| 292 | |
| 293 | $this->openCiviPage("event/add", "reset=1&action=add"); |
| 294 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 295 | $eventDescription = "Here is a description for this conference."; |
| 296 | $this->_testAddEventInfo($eventTitle, $eventDescription); |
| 297 | |
| 298 | //add fee section with pay later checked |
| 299 | $this->_testAddFees(FALSE, FALSE, NULL, FALSE, TRUE); |
| 300 | |
| 301 | //make the event unpaid |
| 302 | $this->waitForElementPresent("_qf_Fee_upload-bottom"); |
| 303 | $this->assertChecked('is_pay_later'); |
| 304 | $this->click("CIVICRM_QFID_0_is_monetary"); |
| 305 | $this->clickLink("_qf_Fee_upload-bottom", "_qf_Fee_upload-bottom"); |
| 306 | |
| 307 | //check if pay later option is disabled |
| 308 | $this->click('CIVICRM_QFID_1_is_monetary'); |
| 309 | $this->waitForElementPresent('is_pay_later'); |
| 310 | $this->assertNotChecked('is_pay_later'); |
| 311 | } |
| 312 | |
| 313 | function testAjaxCustomGroupLoad() { |
| 314 | $this->webtestLogin(); |
| 315 | |
| 316 | $triggerElement = array('name' => 'event_type_id', 'type' => 'select'); |
| 317 | $customSets = array( |
| 318 | array('entity' => 'Event', 'subEntity' => 'Conference', 'triggerElement' => $triggerElement), |
| 319 | ); |
| 320 | |
| 321 | $pageUrl = array('url' => 'event/add', 'args' => "reset=1&action=add"); |
| 322 | $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); |
| 323 | } |
| 324 | |
| 325 | function _testAddEventInfo($eventTitle, $eventDescription) { |
| 326 | $this->waitForElementPresent("_qf_EventInfo_upload-bottom"); |
| 327 | |
| 328 | $this->select("event_type_id", "value=1"); |
| 329 | |
| 330 | // Attendee role s/b selected now. |
| 331 | $this->select("default_role_id", "value=1"); |
| 332 | |
| 333 | // Enter Event Title, Summary and Description |
| 334 | $this->type("title", $eventTitle); |
| 335 | $this->type("summary", "This is a great conference. Sign up now!"); |
| 336 | |
| 337 | // Type description in ckEditor (fieldname, text to type, editor) |
| 338 | $this->fillRichTextField("description", $eventDescription, 'CKEditor'); |
| 339 | |
| 340 | // Choose Start and End dates. |
| 341 | // Using helper webtestFillDate function. |
| 342 | $this->webtestFillDateTime("start_date", "+1 week"); |
| 343 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); |
| 344 | |
| 345 | $this->type("max_participants", "50"); |
| 346 | $this->click("is_map"); |
| 347 | $this->click("is_public"); |
| 348 | $this->click("_qf_EventInfo_upload-bottom"); |
| 349 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 350 | } |
| 351 | |
| 352 | function _testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID) { |
| 353 | $this->waitForElementPresent("_qf_EventInfo_upload-bottom"); |
| 354 | |
| 355 | // Select event template. Use option value, not label - since labels can be translated and test would fail |
| 356 | $this->select("template_id", "value={$templateID}"); |
| 357 | |
| 358 | // Wait for event type to be filled in (since page reloads) |
| 359 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 360 | $this->verifySelectedValue("event_type_id", $eventTypeID); |
| 361 | |
| 362 | // Attendee role s/b selected now. |
| 363 | $this->verifySelectedValue("default_role_id", "1"); |
| 364 | |
| 365 | // Enter Event Title, Summary and Description |
| 366 | $this->type("title", $eventTitle); |
| 367 | |
| 368 | $this->type("summary", "This is a great conference. Sign up now!"); |
| 369 | |
| 370 | // Type description in ckEditor (fieldname, text to type, editor) |
| 371 | $this->fillRichTextField("description", $eventDescription, 'CKEditor'); |
| 372 | |
| 373 | // Choose Start and End dates. |
| 374 | // Using helper webtestFillDate function. |
| 375 | $this->webtestFillDateTime("start_date", "+1 week"); |
| 376 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); |
| 377 | |
| 378 | $this->type("max_participants", "50"); |
| 379 | $this->click("is_map"); |
| 380 | $this->click("_qf_EventInfo_upload-bottom"); |
| 381 | |
| 382 | } |
| 383 | |
| 384 | function _testAddLocation($streetAddress) { |
| 385 | // Wait for Location tab form to load |
| 386 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 387 | $this->waitForElementPresent("_qf_Location_upload-bottom"); |
| 388 | |
| 389 | // Fill in address fields |
| 390 | $streetAddress = "100 Main Street"; |
| 391 | $this->type("address_1_street_address", $streetAddress); |
| 392 | $this->type("address_1_city", "San Francisco"); |
| 393 | $this->type("address_1_postal_code", "94117"); |
| 394 | $this->select("address_1_state_province_id", "value=1004"); |
| 395 | $this->type("email_1_email", "info@civicrm.org"); |
| 396 | |
| 397 | $this->click("_qf_Location_upload-bottom"); |
| 398 | |
| 399 | // Wait for "saved" status msg |
| 400 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 401 | $this->waitForTextPresent("'Location' information has been saved."); |
| 402 | } |
| 403 | |
| 404 | function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro", $double = FALSE, $payLater = FALSE) { |
| 405 | $discount1 = "Early-bird" . substr(sha1(rand()), 0, 7); |
| 406 | $discount2 = ""; |
| 407 | // Go to Fees tab |
| 408 | $this->click("link=Fees"); |
| 409 | $this->waitForElementPresent("_qf_Fee_upload-bottom"); |
| 410 | $this->click("CIVICRM_QFID_1_is_monetary"); |
| 411 | |
| 412 | if ($payLater) { |
| 413 | $this->check('is_pay_later'); |
| 414 | $this->type('pay_later_receipt', 'testing later instructions'); |
| 415 | } |
| 416 | else { |
| 417 | $this->uncheck('is_pay_later'); |
| 418 | } |
| 419 | |
| 420 | if ($processorName) { |
| 421 | $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']"); |
| 422 | } |
| 423 | $this->select("financial_type_id", "value=4"); |
| 424 | if ($priceSet) { |
| 425 | // get one - TBD |
| 426 | } |
| 427 | else { |
| 428 | $this->type("label_1", "Member"); |
| 429 | $this->type("value_1", "225.00"); |
| 430 | $this->type("label_2", "Non-member"); |
| 431 | $this->type("value_2", "300.00"); |
| 432 | $this->click("CIVICRM_QFID_1_4"); |
| 433 | } |
| 434 | |
| 435 | if ($discount) { |
| 436 | // enter early bird discount fees |
| 437 | $this->click("is_discount"); |
| 438 | $this->waitForElementPresent("discount_name_1"); |
| 439 | $this->type("discount_name_1", $discount1); |
| 440 | $this->webtestFillDate("discount_start_date_1", "-3 week"); |
| 441 | $this->webtestFillDate("discount_end_date_1", "-2 week"); |
| 442 | $this->clickLink("_qf_Fee_submit", "discounted_value_1_1"); |
| 443 | |
| 444 | $this->type("discounted_value_1_1","225.00"); |
| 445 | $this->type("discounted_value_2_1","300.00"); |
| 446 | |
| 447 | if ($double) { |
| 448 | $discount2 = "Early-bird" . substr(sha1(rand()), 0, 7); |
| 449 | // enter early bird discount fees |
| 450 | $this->click("link=another discount set"); |
| 451 | $this->waitForElementPresent("discount_name_2"); |
| 452 | $this->type("discount_name_2", $discount2); |
| 453 | $this->webtestFillDate("discount_start_date_2", "-1 week"); |
| 454 | $this->webtestFillDate("discount_end_date_2", "+1 week"); |
| 455 | $this->clickLink("_qf_Fee_submit", "discounted_value_2_1"); |
| 456 | $this->type("discounted_value_1_2","225.00"); |
| 457 | $this->type("discounted_value_2_2","300.00"); |
| 458 | } |
| 459 | $this->click("xpath=//fieldset[@id='discount']/fieldset/table/tbody/tr[2]/td[3]/input"); |
| 460 | } |
| 461 | $this->click("_qf_Fee_upload-bottom"); |
| 462 | |
| 463 | // Wait for "saved" status msg |
| 464 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 465 | $this->waitForText('crm-notification-container', "'Fee' information has been saved"); |
| 466 | return array($discount1, $discount2); |
| 467 | } |
| 468 | |
| 469 | function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) { |
| 470 | // Go to Online Registration tab |
| 471 | $this->click("link=Online Registration"); |
| 472 | $this->waitForElementPresent("_qf_Registration_upload-bottom"); |
| 473 | |
| 474 | $this->check("is_online_registration"); |
| 475 | $this->assertChecked("is_online_registration"); |
| 476 | if ($multipleRegistrations) { |
| 477 | $this->check("is_multiple_registrations"); |
| 478 | $this->assertChecked("is_multiple_registrations"); |
| 479 | } |
| 480 | |
| 481 | $this->fillRichTextField("intro_text", $registerIntro); |
| 482 | |
| 483 | // enable confirmation email |
| 484 | $this->click("CIVICRM_QFID_1_is_email_confirm"); |
| 485 | $this->type("confirm_from_name", "Jane Doe"); |
| 486 | |
| 487 | $this->type("confirm_from_email", "jane.doe@example.org"); |
| 488 | |
| 489 | $this->click("_qf_Registration_upload-bottom"); |
| 490 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 491 | $this->waitForTextPresent("'Registration' information has been saved."); |
| 492 | } |
| 493 | |
| 494 | function _testVerifyEventInfo($eventTitle, $eventInfoStrings, $eventFees = NULL) { |
| 495 | // verify event input on info page |
| 496 | // start at Manage Events listing |
| 497 | $this->openCiviPage("event/manage", "reset=1"); |
| 498 | $this->click("link=$eventTitle"); |
| 499 | |
| 500 | // Look for Register button |
| 501 | $this->waitForElementPresent("link=Register Now"); |
| 502 | |
| 503 | // Check for correct event info strings |
| 504 | $this->assertStringsPresent($eventInfoStrings); |
| 505 | |
| 506 | // Optionally verify event fees (especially for discounts) |
| 507 | if ($eventFees) { |
| 508 | $this->assertStringsPresent($eventFees); |
| 509 | |
| 510 | } |
| 511 | return $this->urlArg('id'); |
| 512 | } |
| 513 | |
| 514 | function _testVerifyRegisterPage($registerStrings) { |
| 515 | // Go to Register page and check for intro text and fee levels |
| 516 | $this->click("link=Register Now"); |
| 517 | $this->waitForElementPresent("_qf_Register_upload-bottom"); |
| 518 | $this->assertStringsPresent($registerStrings); |
| 519 | return $this->getLocation(); |
| 520 | } |
| 521 | |
| 522 | function _testOnlineRegistration($registerUrl, $numberRegistrations = 1, $anonymous = TRUE, $isPayLater = FALSE, $participantEmailInfo = array(), $paymentProcessor = NULL) { |
| 523 | $infoPassed = FALSE; |
| 524 | if (!empty($participantEmailInfo)) { |
| 525 | $infoPassed = TRUE; |
| 526 | } |
| 527 | if ($anonymous) { |
| 528 | $this->webtestLogout(); |
| 529 | } |
| 530 | $primaryParticipantInfo = array(); |
| 531 | $this->open($registerUrl); |
| 532 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 533 | |
| 534 | $this->select("additional_participants", "value=" . $numberRegistrations); |
| 535 | |
| 536 | $email = $infoPassed ? $participantEmailInfo[0] : "smith" . substr(sha1(rand()), 0, 7) . "@example.org"; |
| 537 | $primaryParticipantInfo['email'] = $email; |
| 538 | $this->type("email-Primary", $email); |
| 539 | if (!$isPayLater) { |
| 540 | if ($paymentProcessor) { |
| 541 | $paymentProcessorEle = $this->getAttribute("xpath=//form[@id='Register']//label[contains(text(), '{$paymentProcessor}')]/@for"); |
| 542 | $this->check($paymentProcessorEle); |
| 543 | } |
| 544 | $this->select("credit_card_type", "value=Visa"); |
| 545 | $this->type("credit_card_number", "4111111111111111"); |
| 546 | $this->type("cvv2", "000"); |
| 547 | $this->select("credit_card_exp_date[M]", "value=1"); |
| 548 | $this->select("credit_card_exp_date[Y]", "value=2020"); |
| 549 | $primaryParticipantInfo['first_name'] = "Jane"; |
| 550 | $primaryParticipantInfo['last_name'] = "Smith" . substr(sha1(rand()), 0, 7); |
| 551 | $this->type("billing_first_name", $primaryParticipantInfo['first_name']); |
| 552 | $this->type("billing_last_name", $primaryParticipantInfo['last_name']); |
| 553 | $this->type("billing_street_address-5", "15 Main St."); |
| 554 | $this->type(" billing_city-5", "San Jose"); |
| 555 | $this->select("billing_country_id-5", "value=1228"); |
| 556 | $this->select("billing_state_province_id-5", "value=1004"); |
| 557 | $this->type("billing_postal_code-5", "94129"); |
| 558 | } |
| 559 | |
| 560 | $this->click("_qf_Register_upload-bottom"); |
| 561 | |
| 562 | if ($numberRegistrations > 1) { |
| 563 | for ($i = 1; $i <= $numberRegistrations; $i++) { |
| 564 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 565 | // Look for Skip button |
| 566 | $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array"); |
| 567 | $addtlEmail = $infoPassed ? $participantEmailInfo[$i] : "smith" . substr(sha1(rand()), 0, 7) . "@example.org"; |
| 568 | $this->type("email-Primary", $addtlEmail); |
| 569 | $this->click("_qf_Participant_{$i}_next"); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 574 | $this->waitForElementPresent("_qf_Confirm_next-bottom"); |
| 575 | $confirmStrings = array("Event Fee(s)"); |
| 576 | if (!$isPayLater) { |
| 577 | $confirmStrings += array("Billing Name and Address", "Credit Card Information"); |
| 578 | } |
| 579 | $this->assertStringsPresent($confirmStrings); |
| 580 | $this->click("_qf_Confirm_next-bottom"); |
| 581 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 582 | $thankStrings = array("Thank You for Registering", "Event Total"); |
| 583 | if (!$isPayLater) { |
| 584 | $thankStrings = array("Transaction Date"); |
| 585 | } |
| 586 | else { |
| 587 | $thankStrings += array("testing later instructions"); |
| 588 | } |
| 589 | $this->assertStringsPresent($thankStrings); |
| 590 | return $primaryParticipantInfo; |
| 591 | } |
| 592 | |
| 593 | function _testAddReminder($eventTitle) { |
| 594 | // Go to Schedule Reminders tab |
| 595 | $this->click('css=li#tab_reminder a'); |
| 596 | $this->waitForElementPresent("_qf_ScheduleReminders_upload-bottom"); |
| 597 | $this->type("title", "Event Reminder for " . $eventTitle); |
| 598 | $this->select('entity', 'label=Registered'); |
| 599 | |
| 600 | $this->select('start_action_offset', 'label=1'); |
| 601 | $this->select('start_action_condition', 'label=after'); |
| 602 | $this->click('is_repeat'); |
| 603 | $this->select('repetition_frequency_interval', 'label=2'); |
| 604 | $this->select('end_date', 'label=Event End Date'); |
| 605 | $this->click('recipient'); |
| 606 | $this->select('recipient', 'label=Participant Role'); |
| 607 | // $this->select( 'recipient_listing', 'value=1' ); |
| 608 | |
| 609 | // Fill Subject |
| 610 | $subject = 'subject' . substr(sha1(rand()), 0, 4); |
| 611 | $this->type('subject', $subject); |
| 612 | $this->fillRichTextField("html_message", "This is the test HTML version here!!!", 'CKEditor'); |
| 613 | |
| 614 | $this->type("text_message", "This is the test text version here!!!"); |
| 615 | //click on save |
| 616 | $this->click('_qf_ScheduleReminders_upload-bottom'); |
| 617 | $this->waitForElementPresent("link=Add Reminder"); |
| 618 | |
| 619 | $this->waitForElementPresent("link=Edit"); |
| 620 | |
| 621 | $verifyText = array( |
| 622 | 1 => 'Event Reminder for ' . $eventTitle, |
| 623 | 3 => '1 hour after Event Start Date', |
| 624 | 4 => 'Registered', |
| 625 | 5 => 'Yes', |
| 626 | 6 => 'Yes', |
| 627 | ); |
| 628 | |
| 629 | //verify the fields for Event Reminder selector |
| 630 | foreach ($verifyText as $key => $value) { |
| 631 | $this->verifyText("xpath=//table[@class='display']/tbody/tr/td[$key]", $value); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | function testEventAddMultipleParticipant() { |
| 636 | // Log in using webtestLogin() method |
| 637 | $this->webtestLogin(); |
| 638 | $this->openCiviPage("event/add", "reset=1&action=add"); |
| 639 | |
| 640 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 641 | $eventDescription = "Here is a description for this conference."; |
| 642 | $this->_testAddEventInfo($eventTitle, $eventDescription); |
| 643 | $streetAddress = "100 Main Street"; |
| 644 | $this->_testAddLocation($streetAddress); |
| 645 | |
| 646 | $this->_testAddFees(FALSE, FALSE, "Test Processor", FALSE, TRUE); |
| 647 | $registerIntro = "Fill in all the fields below and click Continue."; |
| 648 | $multipleRegistrations = TRUE; |
| 649 | $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations); |
| 650 | $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress); |
| 651 | $eventId = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings); |
| 652 | |
| 653 | $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro); |
| 654 | $registerUrl = $this->_testVerifyRegisterPage($registerStrings); |
| 655 | $numberRegistrations = 3; |
| 656 | $anonymous = TRUE; |
| 657 | |
| 658 | // CRM-12615 add additional participants and check email, amount |
| 659 | $primaryParticipant = "smith" . substr(sha1(rand()), 0, 7) . "@example.org"; |
| 660 | $secParticipant = "smith" . substr(sha1(rand()), 0, 7) . "@example.org"; |
| 661 | $thirdParticipant = "smith" . substr(sha1(rand()), 0, 7) . "@example.org"; |
| 662 | $participantEmails = array($primaryParticipant, $secParticipant, $thirdParticipant); |
| 663 | $addtlPart = array($secParticipant, $thirdParticipant); |
| 664 | $primaryParticipantInfo = $this->_testOnlineRegistration($registerUrl, 2, $anonymous, FALSE, $participantEmails, "Test Processor"); |
| 665 | $primaryDisplayName = "{$primaryParticipantInfo['first_name']} {$primaryParticipantInfo['last_name']}"; |
| 666 | $this->webtestLogin(); |
| 667 | $this->openCiviPage("event/search?reset=1", "reset=1"); |
| 668 | $this->type('event_name', $eventTitle); |
| 669 | $this->click("event_name"); |
| 670 | $this->waitForElementPresent("css=div.ac_results-inner li"); |
| 671 | $this->click("css=div.ac_results-inner li"); |
| 672 | $this->clickLink('_qf_Search_refresh'); |
| 673 | $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(), '{$secParticipant}')]/../../td[6]", preg_quote('225.00')); |
| 674 | $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(), '{$thirdParticipant}')]/../../td[6]", preg_quote('225.00')); |
| 675 | |
| 676 | //CRM-12618 check edit screen of additional participant and ensuring record_contribution not present |
| 677 | foreach ($addtlPart as $value) { |
| 678 | $this->clickLink("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(), '{$value}')]/../../td[11]/span/a[2][contains(text(), 'Edit')]", '_qf_Participant_upload-bottom'); |
| 679 | $this->assertTrue($this->isElementPresent("xpath=//tr[@class='crm-participant-form-block-registered-by']/td[2]/a[contains(text(), '$primaryDisplayName')]"), 'Registered By info is wrong on additional participant edit form'); |
| 680 | $this->assertElementContainsText("xpath=//form[@id='Participant']/h3", 'Edit Event Registration'); |
| 681 | $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[@class='crm-participant-form-block-displayName']/td[2][contains(text(), '{$value}')]"), |
| 682 | 'Wrong Participant edit form' |
| 683 | ); |
| 684 | $this->assertFalse($this->isElementPresent('record_contribution'), 'Record Payment checkbox showed up wrongly for additional participant edit screen'); |
| 685 | $this->clickLink("_qf_Participant_cancel-top"); |
| 686 | } |
| 687 | |
| 688 | //unselect the payment processor configured |
| 689 | $this->openCiviPage("event/manage/fee", "reset=1&action=update&id={$eventId}", '_qf_Fee_upload-bottom'); |
| 690 | $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='Test Processor']"); |
| 691 | $this->clickLink("_qf_Fee_upload-bottom"); |
| 692 | |
| 693 | // add participant and 3 additional participant and change status of participant from edit participant |
| 694 | $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous, TRUE); |
| 695 | $this->webtestLogin(); |
| 696 | |
| 697 | $this->openCiviPage("event/search?reset=1", "reset=1"); |
| 698 | $this->type('event_name', $eventTitle); |
| 699 | $this->click("event_name"); |
| 700 | $this->waitForElementPresent("css=div.ac_results-inner li"); |
| 701 | $this->click("css=div.ac_results-inner li"); |
| 702 | $this->click("xpath=//td[@class='crm-event-form-block-participant_status']/div[@class='listing-box']//div/label[text()='Pending from pay later']"); |
| 703 | $this->click('_qf_Search_refresh'); |
| 704 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 705 | $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='Edit']"); |
| 706 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 707 | $this->select('status_id', 'label=Registered'); |
| 708 | $this->click('record_contribution'); |
| 709 | $this->select('contribution_status_id', 'label=Completed'); |
| 710 | $pID = $this->urlArg('id'); |
| 711 | $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $pID, 'contribution_id', 'participant_id'); |
| 712 | $this->click('_qf_Participant_upload-top'); |
| 713 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 714 | $this->verifyFinancialRecords($contributionID); |
| 715 | |
| 716 | // add participant and 3 additional participant and change status of participant from edit contribution |
| 717 | $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous, TRUE); |
| 718 | $this->webtestLogin(); |
| 719 | |
| 720 | $this->openCiviPage("event/search?reset=1", "reset=1"); $this->type('event_name', $eventTitle); |
| 721 | $this->click("event_name"); |
| 722 | $this->waitForElementPresent("css=div.ac_results-inner li"); |
| 723 | $this->click("css=div.ac_results-inner li"); |
| 724 | $this->click("xpath=//td[@class='crm-event-form-block-participant_status']/div[@class='listing-box']//div/label[text()='Pending from pay later']"); |
| 725 | $this->click('_qf_Search_refresh'); |
| 726 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 727 | $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='View']"); |
| 728 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 729 | $pID = $this->urlArg('id'); |
| 730 | $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $pID, 'contribution_id', 'participant_id'); |
| 731 | $this->click("xpath=//tr[@id='rowid$contributionID']/td[8]/span//a[text()='Edit']"); |
| 732 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 733 | $this->select('contribution_status_id', 'label=Completed'); |
| 734 | $this->click('_qf_Contribution_upload-bottom'); |
| 735 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 736 | $this->verifyFinancialRecords($contributionID); |
| 737 | } |
| 738 | |
| 739 | function verifyFinancialRecords($contributionID) { |
| 740 | // check count for civicrm_contribution and civicrm_financial_item in civicrm_entity_financial_trxn |
| 741 | $query = "SELECT COUNT(DISTINCT(c1.id)) civicrm_contribution, COUNT(c2.id) civicrm_financial_item FROM civicrm_entity_financial_trxn c1 |
| 742 | LEFT JOIN civicrm_entity_financial_trxn c2 ON c1.financial_trxn_id = c2.financial_trxn_id AND c2.entity_table ='civicrm_financial_item' |
| 743 | LEFT JOIN civicrm_financial_item cfi ON cfi.id = c2.entity_id |
| 744 | WHERE c1.entity_table = 'civicrm_contribution' AND c1.entity_id = %1 AND cfi.status_id = 1"; |
| 745 | $params = array(1 => array($contributionID, 'Integer')); |
| 746 | $dao = CRM_Core_DAO::executeQuery($query, $params); |
| 747 | $dao->fetch(); |
| 748 | $this->assertEquals('2', $dao->civicrm_contribution, 'civicrm_financial_trxn count does not match'); |
| 749 | $this->assertEquals('8',$dao->civicrm_financial_item, 'civicrm_financial_item count does not match'); |
| 750 | $query = "SELECT COUNT(cft.id) civicrm_financial_trxn FROM civicrm_entity_financial_trxn ceft |
| 751 | INNER JOIN civicrm_financial_trxn cft ON ceft.financial_trxn_id = cft.id |
| 752 | WHERE ceft.entity_id = %1 AND ceft.entity_table = 'civicrm_contribution'"; |
| 753 | $dao = CRM_Core_DAO::executeQuery($query, $params); |
| 754 | $dao->fetch(); |
| 755 | $this->assertEquals('2', $dao->civicrm_financial_trxn, 'civicrm_financial_trxn count does not match'); |
| 756 | } |
| 757 | } |