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