| 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 'WebTest/Import/ImportCiviSeleniumTestCase.php'; |
| 28 | |
| 29 | /** |
| 30 | * Class WebTest_Import_ParticipantTest |
| 31 | */ |
| 32 | class WebTest_Import_ParticipantTest extends ImportCiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Test participant import for Individuals. |
| 40 | */ |
| 41 | public function testParticipantImportIndividual() { |
| 42 | // Log in using webtestLogin() method |
| 43 | $this->webtestLogin(); |
| 44 | |
| 45 | // Get sample import data. |
| 46 | list($headers, $rows) = $this->_participantIndividualCSVData(); |
| 47 | |
| 48 | // Create and import csv from provided data and check imported data. |
| 49 | $fieldMapper = array( |
| 50 | 'mapper[0][0]' => 'email', |
| 51 | 'mapper[1][0]' => 'event_id', |
| 52 | 'mapper[2][0]' => 'participant_fee_level', |
| 53 | 'mapper[4][0]' => 'participant_status_id', |
| 54 | ); |
| 55 | |
| 56 | $this->importCSVComponent('Event', $headers, $rows, 'Individual', 'Skip', $fieldMapper); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Test participant import for Organizations. |
| 61 | */ |
| 62 | public function testParticipantImportOrganization() { |
| 63 | // Log in using webtestLogin() method |
| 64 | $this->webtestLogin(); |
| 65 | |
| 66 | // Get sample import data. |
| 67 | list($headers, $rows) = $this->_participantOrganizationCSVData(); |
| 68 | |
| 69 | // Create and import csv from provided data and check imported data. |
| 70 | $fieldMapper = array( |
| 71 | 'mapper[0][0]' => 'organization_name', |
| 72 | 'mapper[1][0]' => 'event_id', |
| 73 | 'mapper[2][0]' => 'participant_fee_level', |
| 74 | 'mapper[4][0]' => 'participant_status_id', |
| 75 | ); |
| 76 | |
| 77 | $this->importCSVComponent('Event', $headers, $rows, 'Organization', 'Skip', $fieldMapper); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Test participant import for Households. |
| 82 | */ |
| 83 | public function testParticipantImportHousehold() { |
| 84 | // Log in using webtestLogin() method |
| 85 | $this->webtestLogin(); |
| 86 | |
| 87 | // Get sample import data. |
| 88 | list($headers, $rows) = $this->_participantHouseholdCSVData(); |
| 89 | |
| 90 | // Create and import csv from provided data and check imported data. |
| 91 | $fieldMapper = array( |
| 92 | 'mapper[0][0]' => 'household_name', |
| 93 | 'mapper[1][0]' => 'event_id', |
| 94 | 'mapper[2][0]' => 'participant_fee_level', |
| 95 | 'mapper[4][0]' => 'participant_status_id', |
| 96 | ); |
| 97 | |
| 98 | $this->importCSVComponent('Event', $headers, $rows, 'Household', 'Skip', $fieldMapper); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Helper function to provide data for participant import for Individuals. |
| 103 | * |
| 104 | * @return array |
| 105 | */ |
| 106 | public function _participantIndividualCSVData() { |
| 107 | $eventInfo = $this->_addNewEvent(); |
| 108 | |
| 109 | $firstName1 = substr(sha1(rand()), 0, 7); |
| 110 | $email1 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com'; |
| 111 | $this->webtestAddContact($firstName1, 'Anderson', $email1); |
| 112 | |
| 113 | $firstName2 = substr(sha1(rand()), 0, 7); |
| 114 | $email2 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com'; |
| 115 | $this->webtestAddContact($firstName2, 'Anderson', $email2); |
| 116 | |
| 117 | $headers = array( |
| 118 | 'email' => 'Email', |
| 119 | 'event_id' => 'Event Id', |
| 120 | 'fee_level' => 'Fee Level', |
| 121 | 'role' => 'Participant Role', |
| 122 | 'status' => 'Participant Status', |
| 123 | 'register_date' => 'Register date', |
| 124 | ); |
| 125 | |
| 126 | $rows = array( |
| 127 | array( |
| 128 | 'email' => $email1, |
| 129 | 'event_id' => $eventInfo['event_id'], |
| 130 | 'fee_level' => 'Member', |
| 131 | 'role' => 1, |
| 132 | 'status' => 1, |
| 133 | 'register_date' => '2011-03-30', |
| 134 | ), |
| 135 | array( |
| 136 | 'email' => $email2, |
| 137 | 'event_id' => $eventInfo['event_id'], |
| 138 | 'fee_level' => 'Non-Member', |
| 139 | 'role' => 1, |
| 140 | 'status' => 1, |
| 141 | 'register_date' => '2011-03-30', |
| 142 | ), |
| 143 | ); |
| 144 | |
| 145 | return array($headers, $rows); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Helper function to provide data for participant import for Household. |
| 150 | * |
| 151 | * @return array |
| 152 | */ |
| 153 | public function _participantHouseholdCSVData() { |
| 154 | $eventInfo = $this->_addNewEvent(); |
| 155 | |
| 156 | $household1 = substr(sha1(rand()), 0, 7) . ' home'; |
| 157 | $this->webtestAddHousehold($household1, TRUE); |
| 158 | |
| 159 | $household2 = substr(sha1(rand()), 0, 7) . ' home'; |
| 160 | $this->webtestAddHousehold($household2, TRUE); |
| 161 | |
| 162 | $headers = array( |
| 163 | 'household' => 'Household Name', |
| 164 | 'event_id' => 'Event Id', |
| 165 | 'fee_level' => 'Fee Level', |
| 166 | 'role' => 'Participant Role', |
| 167 | 'status' => 'Participant Status', |
| 168 | 'register_date' => 'Register date', |
| 169 | ); |
| 170 | |
| 171 | $rows = array( |
| 172 | array( |
| 173 | 'household' => $household1, |
| 174 | 'event_id' => $eventInfo['event_id'], |
| 175 | 'fee_level' => 'Member', |
| 176 | 'role' => 1, |
| 177 | 'status' => 1, |
| 178 | 'register_date' => '2011-03-30', |
| 179 | ), |
| 180 | array( |
| 181 | 'household' => $household2, |
| 182 | 'event_id' => $eventInfo['event_id'], |
| 183 | 'fee_level' => 'Non-Member', |
| 184 | 'role' => 1, |
| 185 | 'status' => 1, |
| 186 | 'register_date' => '2011-03-30', |
| 187 | ), |
| 188 | ); |
| 189 | |
| 190 | return array($headers, $rows); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Helper function to provide data for participant import for Organization. |
| 195 | * @return array |
| 196 | */ |
| 197 | public function _participantOrganizationCSVData() { |
| 198 | $eventInfo = $this->_addNewEvent(); |
| 199 | |
| 200 | $organization1 = substr(sha1(rand()), 0, 7) . ' org'; |
| 201 | $this->webtestAddOrganization($organization1, TRUE); |
| 202 | |
| 203 | $organization2 = substr(sha1(rand()), 0, 7) . ' org'; |
| 204 | $this->webtestAddOrganization($organization2, TRUE); |
| 205 | |
| 206 | $headers = array( |
| 207 | 'organization' => 'Organization Name', |
| 208 | 'event_id' => 'Event Id', |
| 209 | 'fee_level' => 'Fee Level', |
| 210 | 'role' => 'Participant Role', |
| 211 | 'status' => 'Participant Status', |
| 212 | 'register_date' => 'Register date', |
| 213 | ); |
| 214 | |
| 215 | $rows = array( |
| 216 | array( |
| 217 | 'organization' => $organization1, |
| 218 | 'event_id' => $eventInfo['event_id'], |
| 219 | 'fee_level' => 'Member', |
| 220 | 'role' => 1, |
| 221 | 'status' => 1, |
| 222 | 'register_date' => '2011-03-30', |
| 223 | ), |
| 224 | array( |
| 225 | 'organization' => $organization2, |
| 226 | 'event_id' => $eventInfo['event_id'], |
| 227 | 'fee_level' => 'Non-Member', |
| 228 | 'role' => 1, |
| 229 | 'status' => 1, |
| 230 | 'register_date' => '2011-03-30', |
| 231 | ), |
| 232 | ); |
| 233 | |
| 234 | return array($headers, $rows); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Helper function to add new event |
| 239 | * |
| 240 | * @param array $params |
| 241 | * Parameters to create an event. |
| 242 | * |
| 243 | * @return array |
| 244 | * event details of newly created event |
| 245 | */ |
| 246 | public function _addNewEvent($params = array()) { |
| 247 | |
| 248 | if (empty($params)) { |
| 249 | |
| 250 | // Use default payment processor |
| 251 | $processorName = 'Test Processor'; |
| 252 | $this->webtestAddPaymentProcessor($processorName); |
| 253 | |
| 254 | // create an event |
| 255 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); |
| 256 | $params = array( |
| 257 | 'title' => $eventTitle, |
| 258 | 'template_id' => 6, |
| 259 | 'event_type_id' => 4, |
| 260 | 'payment_processor' => $processorName, |
| 261 | 'fee_level' => array( |
| 262 | 'Member' => "250.00", |
| 263 | 'Non-Member' => "325.00", |
| 264 | ), |
| 265 | ); |
| 266 | } |
| 267 | |
| 268 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
| 269 | |
| 270 | $this->select("event_type_id", "value={$params['event_type_id']}"); |
| 271 | |
| 272 | // Attendee role s/b selected now. |
| 273 | $this->select("default_role_id", "value=1"); |
| 274 | |
| 275 | // Enter Event Title, Summary and Description |
| 276 | $this->type("title", $params['title']); |
| 277 | $this->type("summary", "This is a great conference. Sign up now!"); |
| 278 | $this->fillRichTextField("description", "Here is a description for this event.", 'CKEditor'); |
| 279 | |
| 280 | // Choose Start and End dates. |
| 281 | // Using helper webtestFillDate function. |
| 282 | $this->webtestFillDateTime("start_date", "+1 week"); |
| 283 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); |
| 284 | |
| 285 | $this->type("max_participants", "50"); |
| 286 | $this->click("is_map"); |
| 287 | $this->click("_qf_EventInfo_upload-bottom"); |
| 288 | |
| 289 | // Wait for Location tab form to load |
| 290 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 291 | |
| 292 | // Go to Fees tab |
| 293 | $this->click("link=Fees"); |
| 294 | $this->waitForElementPresent("_qf_Fee_upload-bottom"); |
| 295 | $this->click("CIVICRM_QFID_1_is_monetary"); |
| 296 | |
| 297 | // select newly created processor |
| 298 | $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]"; |
| 299 | $this->assertElementContainsText('paymentProcessor', $processorName); |
| 300 | $this->check($xpath); |
| 301 | $this->select("financial_type_id", "value=4"); |
| 302 | |
| 303 | $counter = 1; |
| 304 | foreach ($params['fee_level'] as $label => $amount) { |
| 305 | $this->type("label_{$counter}", $label); |
| 306 | $this->type("value_{$counter}", $amount); |
| 307 | $counter++; |
| 308 | } |
| 309 | |
| 310 | $this->click("_qf_Fee_upload-bottom"); |
| 311 | $this->waitForElementPresent("_qf_Fee_upload-bottom"); |
| 312 | |
| 313 | // Go to Online Registration tab |
| 314 | $this->click("link=Online Registration"); |
| 315 | $this->waitForElementPresent("_qf_Registration_upload-bottom"); |
| 316 | |
| 317 | $this->click("is_online_registration"); |
| 318 | $this->assertChecked("is_online_registration"); |
| 319 | |
| 320 | $this->fillRichTextField("intro_text", "Fill in all the fields below and click Continue.", 'CKEditor', TRUE); |
| 321 | |
| 322 | // enable confirmation email |
| 323 | $this->click("CIVICRM_QFID_1_is_email_confirm"); |
| 324 | $this->type("confirm_from_name", "Jane Doe"); |
| 325 | $this->type("confirm_from_email", "jane.doe@example.org"); |
| 326 | |
| 327 | $this->click("_qf_Registration_upload-bottom"); |
| 328 | $this->waitForElementPresent("_qf_Registration_upload-bottom"); |
| 329 | $this->waitForTextPresent("'Online Registration' information has been saved."); |
| 330 | |
| 331 | // verify event input on info page |
| 332 | // start at Manage Events listing |
| 333 | $this->openCiviPage('event/manage', 'reset=1'); |
| 334 | $this->clickLink("link=" . $params['title'], NULL); |
| 335 | |
| 336 | $params['event_id'] = $this->urlArg('id');; |
| 337 | |
| 338 | return $params; |
| 339 | } |
| 340 | } |