09ee62f1daf3f5783b51103aaec7904e4249244a
[civicrm-core.git] / tests / phpunit / WebTest / Import / ParticipantTest.php
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 '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 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 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 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 /**
105 * @return array
106 */
107 function _participantIndividualCSVData() {
108 $eventInfo = $this->_addNewEvent();
109
110 $firstName1 = substr(sha1(rand()), 0, 7);
111 $email1 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
112 $this->webtestAddContact($firstName1, 'Anderson', $email1);
113
114 $firstName2 = substr(sha1(rand()), 0, 7);
115 $email2 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
116 $this->webtestAddContact($firstName2, 'Anderson', $email2);
117
118 $headers = array(
119 'email' => 'Email',
120 'event_id' => 'Event Id',
121 'fee_level' => 'Fee Level',
122 'role' => 'Participant Role',
123 'status' => 'Participant Status',
124 'register_date' => 'Register date',
125 );
126
127 $rows = array(
128 array(
129 'email' => $email1,
130 'event_id' => $eventInfo['event_id'],
131 'fee_level' => 'Member',
132 'role' => 1,
133 'status' => 1,
134 'register_date' => '2011-03-30',
135 ),
136 array(
137 'email' => $email2,
138 'event_id' => $eventInfo['event_id'],
139 'fee_level' => 'Non-Member',
140 'role' => 1,
141 'status' => 1,
142 'register_date' => '2011-03-30',
143 ),
144 );
145
146 return array($headers, $rows);
147 }
148
149 /*
150 * Helper function to provide data for participant import for Household.
151 */
152 /**
153 * @return array
154 */
155 function _participantHouseholdCSVData() {
156 $eventInfo = $this->_addNewEvent();
157
158 $household1 = substr(sha1(rand()), 0, 7) . ' home';
159 $this->webtestAddHousehold($household1, TRUE);
160
161 $household2 = substr(sha1(rand()), 0, 7) . ' home';
162 $this->webtestAddHousehold($household2, TRUE);
163
164 $headers = array(
165 'household' => 'Household Name',
166 'event_id' => 'Event Id',
167 'fee_level' => 'Fee Level',
168 'role' => 'Participant Role',
169 'status' => 'Participant Status',
170 'register_date' => 'Register date',
171 );
172
173 $rows = array(
174 array(
175 'household' => $household1,
176 'event_id' => $eventInfo['event_id'],
177 'fee_level' => 'Member',
178 'role' => 1,
179 'status' => 1,
180 'register_date' => '2011-03-30',
181 ),
182 array(
183 'household' => $household2,
184 'event_id' => $eventInfo['event_id'],
185 'fee_level' => 'Non-Member',
186 'role' => 1,
187 'status' => 1,
188 'register_date' => '2011-03-30',
189 ),
190 );
191
192 return array($headers, $rows);
193 }
194
195 /*
196 * Helper function to provide data for participant import for Organization.
197 */
198 /**
199 * @return array
200 */
201 function _participantOrganizationCSVData() {
202 $eventInfo = $this->_addNewEvent();
203
204 $organization1 = substr(sha1(rand()), 0, 7) . ' org';
205 $this->webtestAddOrganization($organization1, TRUE);
206
207 $organization2 = substr(sha1(rand()), 0, 7) . ' org';
208 $this->webtestAddOrganization($organization2, TRUE);
209
210 $headers = array(
211 'organization' => 'Organization Name',
212 'event_id' => 'Event Id',
213 'fee_level' => 'Fee Level',
214 'role' => 'Participant Role',
215 'status' => 'Participant Status',
216 'register_date' => 'Register date',
217 );
218
219 $rows = array(
220 array(
221 'organization' => $organization1,
222 'event_id' => $eventInfo['event_id'],
223 'fee_level' => 'Member',
224 'role' => 1,
225 'status' => 1,
226 'register_date' => '2011-03-30',
227 ),
228 array(
229 'organization' => $organization2,
230 'event_id' => $eventInfo['event_id'],
231 'fee_level' => 'Non-Member',
232 'role' => 1,
233 'status' => 1,
234 'register_date' => '2011-03-30',
235 ),
236 );
237
238 return array($headers, $rows);
239 }
240
241 /*
242 * Helper function to add new event
243 *
244 * @params array $params parameters to create an event
245 *
246 * @return array $params event details of newly created event
247 */
248 /**
249 * @param array $params
250 *
251 * @return array
252 */
253 function _addNewEvent($params = array(
254 )) {
255
256 if (empty($params)) {
257
258 // Use default payment processor
259 $processorName = 'Test Processor';
260 $this->webtestAddPaymentProcessor($processorName);
261
262 // create an event
263 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
264 $params = array(
265 'title' => $eventTitle,
266 'template_id' => 6,
267 'event_type_id' => 4,
268 'payment_processor' => $processorName,
269 'fee_level' => array(
270 'Member' => "250.00",
271 'Non-Member' => "325.00",
272 ),
273 );
274 }
275
276 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
277
278 $this->select("event_type_id", "value={$params['event_type_id']}");
279
280 // Attendee role s/b selected now.
281 $this->select("default_role_id", "value=1");
282
283 // Enter Event Title, Summary and Description
284 $this->type("title", $params['title']);
285 $this->type("summary", "This is a great conference. Sign up now!");
286 $this->fillRichTextField("description", "Here is a description for this event.", 'CKEditor');
287
288 // Choose Start and End dates.
289 // Using helper webtestFillDate function.
290 $this->webtestFillDateTime("start_date", "+1 week");
291 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
292
293 $this->type("max_participants", "50");
294 $this->click("is_map");
295 $this->click("_qf_EventInfo_upload-bottom");
296
297 // Wait for Location tab form to load
298 $this->waitForPageToLoad($this->getTimeoutMsec());
299
300 // Go to Fees tab
301 $this->click("link=Fees");
302 $this->waitForElementPresent("_qf_Fee_upload-bottom");
303 $this->click("CIVICRM_QFID_1_is_monetary");
304
305 // select newly created processor
306 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
307 $this->assertElementContainsText('paymentProcessor', $processorName);
308 $this->check($xpath);
309 $this->select("financial_type_id", "value=4");
310
311 $counter = 1;
312 foreach ($params['fee_level'] as $label => $amount) {
313 $this->type("label_{$counter}", $label);
314 $this->type("value_{$counter}", $amount);
315 $counter++;
316 }
317
318 $this->click("_qf_Fee_upload-bottom");
319 $this->waitForElementPresent("_qf_Fee_upload-bottom");
320
321 // Go to Online Registration tab
322 $this->click("link=Online Registration");
323 $this->waitForElementPresent("_qf_Registration_upload-bottom");
324
325 $this->click("is_online_registration");
326 $this->assertChecked("is_online_registration");
327
328 $this->fillRichTextField("intro_text", "Fill in all the fields below and click Continue.", 'CKEditor', TRUE);
329
330 // enable confirmation email
331 $this->click("CIVICRM_QFID_1_is_email_confirm");
332 $this->type("confirm_from_name", "Jane Doe");
333 $this->type("confirm_from_email", "jane.doe@example.org");
334
335 $this->click("_qf_Registration_upload-bottom");
336 $this->waitForElementPresent("_qf_Registration_upload-bottom");
337 $this->waitForTextPresent("'Online Registration' information has been saved.");
338
339 // verify event input on info page
340 // start at Manage Events listing
341 $this->openCiviPage('event/manage', 'reset=1');
342 $this->clickLink("link=" . $params['title'], NULL);
343
344 $params['event_id'] = $this->urlArg('id');;
345
346 return $params;
347 }
348 }
349