Merge pull request #11821 from michaelmcandrew/500-http-response-code
[civicrm-core.git] / tests / phpunit / WebTest / Import / ParticipantTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Import_ParticipantTest
31 */
6a488035
TO
32class WebTest_Import_ParticipantTest extends ImportCiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
c490a46a
CW
38 /**
39 * Test participant import for Individuals.
40 */
00be9182 41 public function testParticipantImportIndividual() {
6a488035
TO
42 // Log in using webtestLogin() method
43 $this->webtestLogin();
44
45 // Get sample import data.
46 list($headers, $rows) = $this->_participantIndividualCSVData();
76e86fd8 47
6a488035
TO
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
c490a46a
CW
59 /**
60 * Test participant import for Organizations.
61 */
00be9182 62 public function testParticipantImportOrganization() {
6a488035
TO
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
c490a46a
CW
80 /**
81 * Test participant import for Households.
82 */
00be9182 83 public function testParticipantImportHousehold() {
6a488035
TO
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
4cbe18b8 101 /**
c490a46a
CW
102 * Helper function to provide data for participant import for Individuals.
103 *
4cbe18b8
EM
104 * @return array
105 */
00be9182 106 public function _participantIndividualCSVData() {
6a488035
TO
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
4cbe18b8 148 /**
c490a46a
CW
149 * Helper function to provide data for participant import for Household.
150 *
4cbe18b8
EM
151 * @return array
152 */
00be9182 153 public function _participantHouseholdCSVData() {
6a488035
TO
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
4cbe18b8 193 /**
c490a46a 194 * Helper function to provide data for participant import for Organization.
4cbe18b8
EM
195 * @return array
196 */
00be9182 197 public function _participantOrganizationCSVData() {
6a488035
TO
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
4cbe18b8 237 /**
eceb18cc 238 * Helper function to add new event.
4cbe18b8 239 *
e16033b4
TO
240 * @param array $params
241 * Parameters to create an event.
c490a46a 242 *
a6c01b45
CW
243 * @return array
244 * event details of newly created event
4cbe18b8 245 */
00be9182 246 public function _addNewEvent($params = array()) {
6a488035
TO
247
248 if (empty($params)) {
249
c3ad8633
CW
250 // Use default payment processor
251 $processorName = 'Test Processor';
6a488035
TO
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(
92915c55
TO
262 'Member' => "250.00",
263 'Non-Member' => "325.00",
6a488035
TO
264 ),
265 );
266 }
267
e3ae42f3 268 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
6a488035 269
6a488035
TO
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
a8d9d207 298 $this->select2('payment_processor', $processorName, TRUE);
e3ae42f3 299 $this->assertElementContainsText('paymentProcessor', $processorName);
e3ae42f3 300 $this->select("financial_type_id", "value=4");
6a488035
TO
301
302 $counter = 1;
303 foreach ($params['fee_level'] as $label => $amount) {
304 $this->type("label_{$counter}", $label);
305 $this->type("value_{$counter}", $amount);
306 $counter++;
307 }
308
309 $this->click("_qf_Fee_upload-bottom");
6acc185a 310 $this->waitForElementPresent("_qf_Fee_upload-bottom");
6a488035
TO
311
312 // Go to Online Registration tab
313 $this->click("link=Online Registration");
314 $this->waitForElementPresent("_qf_Registration_upload-bottom");
315
02e08b2e 316 $this->click("is_online_registration");
6a488035
TO
317 $this->assertChecked("is_online_registration");
318
02e08b2e 319 $this->fillRichTextField("intro_text", "Fill in all the fields below and click Continue.", 'CKEditor', TRUE);
6a488035
TO
320
321 // enable confirmation email
322 $this->click("CIVICRM_QFID_1_is_email_confirm");
323 $this->type("confirm_from_name", "Jane Doe");
324 $this->type("confirm_from_email", "jane.doe@example.org");
325
326 $this->click("_qf_Registration_upload-bottom");
6acc185a 327 $this->waitForElementPresent("_qf_Registration_upload-bottom");
328 $this->waitForTextPresent("'Online Registration' information has been saved.");
6a488035
TO
329
330 // verify event input on info page
331 // start at Manage Events listing
e3ae42f3 332 $this->openCiviPage('event/manage', 'reset=1');
6e64f99d 333 $this->clickLink("link=" . $params['title'], NULL);
6a488035 334
a471a3b6 335 $params['event_id'] = $this->urlArg('id');;
6a488035
TO
336
337 return $params;
338 }
96025800 339
6a488035 340}