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