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