3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
29 class WebTest_Import_ParticipantTest
extends ImportCiviSeleniumTestCase
{
31 protected function setUp() {
36 * Test participant import for Individuals.
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
42 $this->open($this->sboxPath
);
44 // Log in using webtestLogin() method
45 $this->webtestLogin();
47 // Get sample import data.
48 list($headers, $rows) = $this->_participantIndividualCSVData();
50 // Create and import csv from provided data and check imported data.
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',
58 $this->importCSVComponent('Event', $headers, $rows, 'Individual', 'Skip', $fieldMapper);
62 * Test participant import for Organizations.
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
68 $this->open($this->sboxPath
);
70 // Log in using webtestLogin() method
71 $this->webtestLogin();
73 // Get sample import data.
74 list($headers, $rows) = $this->_participantOrganizationCSVData();
76 // Create and import csv from provided data and check imported data.
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',
84 $this->importCSVComponent('Event', $headers, $rows, 'Organization', 'Skip', $fieldMapper);
88 * Test participant import for Households.
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
94 $this->open($this->sboxPath
);
96 // Log in using webtestLogin() method
97 $this->webtestLogin();
99 // Get sample import data.
100 list($headers, $rows) = $this->_participantHouseholdCSVData();
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',
110 $this->importCSVComponent('Event', $headers, $rows, 'Household', 'Skip', $fieldMapper);
114 * Helper function to provide data for participant import for Individuals.
116 function _participantIndividualCSVData() {
117 $eventInfo = $this->_addNewEvent();
119 $firstName1 = substr(sha1(rand()), 0, 7);
120 $email1 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
121 $this->webtestAddContact($firstName1, 'Anderson', $email1);
123 $firstName2 = substr(sha1(rand()), 0, 7);
124 $email2 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
125 $this->webtestAddContact($firstName2, 'Anderson', $email2);
129 'event_id' => 'Event Id',
130 'fee_level' => 'Fee Level',
131 'role' => 'Participant Role',
132 'status' => 'Participant Status',
133 'register_date' => 'Register date',
139 'event_id' => $eventInfo['event_id'],
140 'fee_level' => 'Member',
143 'register_date' => '2011-03-30',
147 'event_id' => $eventInfo['event_id'],
148 'fee_level' => 'Non-Member',
151 'register_date' => '2011-03-30',
155 return array($headers, $rows);
159 * Helper function to provide data for participant import for Household.
161 function _participantHouseholdCSVData() {
162 $eventInfo = $this->_addNewEvent();
164 $household1 = substr(sha1(rand()), 0, 7) . ' home';
165 $this->webtestAddHousehold($household1, TRUE);
167 $household2 = substr(sha1(rand()), 0, 7) . ' home';
168 $this->webtestAddHousehold($household2, TRUE);
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',
181 'household' => $household1,
182 'event_id' => $eventInfo['event_id'],
183 'fee_level' => 'Member',
186 'register_date' => '2011-03-30',
189 'household' => $household2,
190 'event_id' => $eventInfo['event_id'],
191 'fee_level' => 'Non-Member',
194 'register_date' => '2011-03-30',
198 return array($headers, $rows);
202 * Helper function to provide data for participant import for Organization.
204 function _participantOrganizationCSVData() {
205 $eventInfo = $this->_addNewEvent();
207 $organization1 = substr(sha1(rand()), 0, 7) . ' org';
208 $this->webtestAddOrganization($organization1, TRUE);
210 $organization2 = substr(sha1(rand()), 0, 7) . ' org';
211 $this->webtestAddOrganization($organization2, TRUE);
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',
224 'organization' => $organization1,
225 'event_id' => $eventInfo['event_id'],
226 'fee_level' => 'Member',
229 'register_date' => '2011-03-30',
232 'organization' => $organization2,
233 'event_id' => $eventInfo['event_id'],
234 'fee_level' => 'Non-Member',
237 'register_date' => '2011-03-30',
241 return array($headers, $rows);
245 * Helper function to add new event
247 * @params array $params parameters to create an event
249 * @return array $params event details of newly created event
251 function _addNewEvent($params = array(
254 if (empty($params)) {
256 // We need a payment processor
257 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
258 $this->webtestAddPaymentProcessor($processorName);
261 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
263 'title' => $eventTitle,
265 'event_type_id' => 4,
266 'payment_processor' => $processorName,
267 'fee_level' => array(
268 'Member' => "250.00",
269 'Non-Member' => "325.00",
274 $this->open($this->sboxPath
. "civicrm/event/add?reset=1&action=add");
276 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
278 // Let's start filling the form with values.
279 $this->select("event_type_id", "value={$params['event_type_id']}");
281 // Attendee role s/b selected now.
282 $this->select("default_role_id", "value=1");
284 // Enter Event Title, Summary and Description
285 $this->type("title", $params['title']);
286 $this->type("summary", "This is a great conference. Sign up now!");
287 $this->fillRichTextField("description", "Here is a description for this event.", 'CKEditor');
289 // Choose Start and End dates.
290 // Using helper webtestFillDate function.
291 $this->webtestFillDateTime("start_date", "+1 week");
292 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
294 $this->type("max_participants", "50");
295 $this->click("is_map");
296 $this->click("_qf_EventInfo_upload-bottom");
298 // Wait for Location tab form to load
299 $this->waitForPageToLoad($this->getTimeoutMsec());
302 $this->click("link=Fees");
303 $this->waitForElementPresent("_qf_Fee_upload-bottom");
304 $this->click("CIVICRM_QFID_1_is_monetary");
306 // select newly created processor
307 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
308 $this->assertTrue($this->isTextPresent($processorName));
309 $this->check($xpath);
311 $this->select("financial_type_id", "value=4");
314 foreach ($params['fee_level'] as $label => $amount) {
315 $this->type("label_{$counter}", $label);
316 $this->type("value_{$counter}", $amount);
320 $this->click("_qf_Fee_upload-bottom");
321 $this->waitForPageToLoad($this->getTimeoutMsec());
323 // Go to Online Registration tab
324 $this->click("link=Online Registration");
325 $this->waitForElementPresent("_qf_Registration_upload-bottom");
327 $this->check("is_online_registration");
328 $this->assertChecked("is_online_registration");
330 $this->fillRichTextField("intro_text", "Fill in all the fields below and click Continue.");
332 // enable confirmation email
333 $this->click("CIVICRM_QFID_1_is_email_confirm");
334 $this->type("confirm_from_name", "Jane Doe");
335 $this->type("confirm_from_email", "jane.doe@example.org");
337 $this->click("_qf_Registration_upload-bottom");
338 $this->waitForPageToLoad($this->getTimeoutMsec());
339 $this->waitForTextPresent("'Registration' information has been saved.");
341 // verify event input on info page
342 // start at Manage Events listing
343 $this->open($this->sboxPath
. "civicrm/event/manage?reset=1");
344 $this->click("link=" . $params['title']);
346 $this->waitForPageToLoad($this->getTimeoutMsec());
349 preg_match('/id=([0-9]+)/', $this->getLocation(), $matches);
350 $params['event_id'] = $matches[1];