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 // Log in using webtestLogin() method
40 $this->webtestLogin();
42 // Get sample import data.
43 list($headers, $rows) = $this->_participantIndividualCSVData();
45 // Create and import csv from provided data and check imported data.
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',
53 $this->importCSVComponent('Event', $headers, $rows, 'Individual', 'Skip', $fieldMapper);
57 * Test participant import for Organizations.
59 function testParticipantImportOrganization() {
60 // Log in using webtestLogin() method
61 $this->webtestLogin();
63 // Get sample import data.
64 list($headers, $rows) = $this->_participantOrganizationCSVData();
66 // Create and import csv from provided data and check imported data.
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',
74 $this->importCSVComponent('Event', $headers, $rows, 'Organization', 'Skip', $fieldMapper);
78 * Test participant import for Households.
80 function testParticipantImportHousehold() {
81 // Log in using webtestLogin() method
82 $this->webtestLogin();
84 // Get sample import data.
85 list($headers, $rows) = $this->_participantHouseholdCSVData();
87 // Create and import csv from provided data and check imported data.
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',
95 $this->importCSVComponent('Event', $headers, $rows, 'Household', 'Skip', $fieldMapper);
99 * Helper function to provide data for participant import for Individuals.
101 function _participantIndividualCSVData() {
102 $eventInfo = $this->_addNewEvent();
104 $firstName1 = substr(sha1(rand()), 0, 7);
105 $email1 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
106 $this->webtestAddContact($firstName1, 'Anderson', $email1);
108 $firstName2 = substr(sha1(rand()), 0, 7);
109 $email2 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
110 $this->webtestAddContact($firstName2, 'Anderson', $email2);
114 'event_id' => 'Event Id',
115 'fee_level' => 'Fee Level',
116 'role' => 'Participant Role',
117 'status' => 'Participant Status',
118 'register_date' => 'Register date',
124 'event_id' => $eventInfo['event_id'],
125 'fee_level' => 'Member',
128 'register_date' => '2011-03-30',
132 'event_id' => $eventInfo['event_id'],
133 'fee_level' => 'Non-Member',
136 'register_date' => '2011-03-30',
140 return array($headers, $rows);
144 * Helper function to provide data for participant import for Household.
146 function _participantHouseholdCSVData() {
147 $eventInfo = $this->_addNewEvent();
149 $household1 = substr(sha1(rand()), 0, 7) . ' home';
150 $this->webtestAddHousehold($household1, TRUE);
152 $household2 = substr(sha1(rand()), 0, 7) . ' home';
153 $this->webtestAddHousehold($household2, TRUE);
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',
166 'household' => $household1,
167 'event_id' => $eventInfo['event_id'],
168 'fee_level' => 'Member',
171 'register_date' => '2011-03-30',
174 'household' => $household2,
175 'event_id' => $eventInfo['event_id'],
176 'fee_level' => 'Non-Member',
179 'register_date' => '2011-03-30',
183 return array($headers, $rows);
187 * Helper function to provide data for participant import for Organization.
189 function _participantOrganizationCSVData() {
190 $eventInfo = $this->_addNewEvent();
192 $organization1 = substr(sha1(rand()), 0, 7) . ' org';
193 $this->webtestAddOrganization($organization1, TRUE);
195 $organization2 = substr(sha1(rand()), 0, 7) . ' org';
196 $this->webtestAddOrganization($organization2, TRUE);
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',
209 'organization' => $organization1,
210 'event_id' => $eventInfo['event_id'],
211 'fee_level' => 'Member',
214 'register_date' => '2011-03-30',
217 'organization' => $organization2,
218 'event_id' => $eventInfo['event_id'],
219 'fee_level' => 'Non-Member',
222 'register_date' => '2011-03-30',
226 return array($headers, $rows);
230 * Helper function to add new event
232 * @params array $params parameters to create an event
234 * @return array $params event details of newly created event
236 function _addNewEvent($params = array(
239 if (empty($params)) {
241 // We need a payment processor
242 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
243 $this->webtestAddPaymentProcessor($processorName);
246 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
248 'title' => $eventTitle,
250 'event_type_id' => 4,
251 'payment_processor' => $processorName,
252 'fee_level' => array(
253 'Member' => "250.00",
254 'Non-Member' => "325.00",
259 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
261 $this->select("event_type_id", "value={$params['event_type_id']}");
263 // Attendee role s/b selected now.
264 $this->select("default_role_id", "value=1");
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');
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 ");
276 $this->type("max_participants", "50");
277 $this->click("is_map");
278 $this->click("_qf_EventInfo_upload-bottom");
280 // Wait for Location tab form to load
281 $this->waitForPageToLoad($this->getTimeoutMsec());
284 $this->click("link=Fees");
285 $this->waitForElementPresent("_qf_Fee_upload-bottom");
286 $this->click("CIVICRM_QFID_1_is_monetary");
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");
295 foreach ($params['fee_level'] as $label => $amount) {
296 $this->type("label_{$counter}", $label);
297 $this->type("value_{$counter}", $amount);
301 $this->click("_qf_Fee_upload-bottom");
302 $this->waitForPageToLoad($this->getTimeoutMsec());
304 // Go to Online Registration tab
305 $this->click("link=Online Registration");
306 $this->waitForElementPresent("_qf_Registration_upload-bottom");
308 $this->check("is_online_registration");
309 $this->assertChecked("is_online_registration");
311 $this->fillRichTextField("intro_text", "Fill in all the fields below and click Continue.");
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");
318 $this->click("_qf_Registration_upload-bottom");
319 $this->waitForPageToLoad($this->getTimeoutMsec());
320 $this->waitForTextPresent("'Registration' information has been saved.");
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']);
327 $this->waitForPageToLoad($this->getTimeoutMsec());
330 preg_match('/id=([0-9]+)/', $this->getLocation(), $matches);
331 $params['event_id'] = $matches[1];