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_MatchExternalIdTest
extends ImportCiviSeleniumTestCase
{
31 protected function setUp() {
36 * Test participant import for Individuals matching on external identifier.
38 function testContributionImport() {
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 $this->webtestLogin();
46 // Get sample import data.
47 list($headers, $rows, $fieldMapper) = $this->_contributionIndividualCSVData();
49 // Create and import csv from provided data and check imported data.
50 $this->importCSVComponent('Contribution', $headers, $rows, 'Individual', 'Insert new contributions', $fieldMapper);
54 * Test membership import for Individuals matching on external identifier.
56 function testMemberImportIndividual() {
57 // This is the path where our testing install resides.
58 // The rest of URL is defined in CiviSeleniumTestCase base class, in
60 $this->open($this->sboxPath
);
62 $this->webtestLogin();
64 // Get membership import data for Individuals.
65 list($headers, $rows, $fieldMapper) = $this->_memberIndividualCSVData();
67 // Import participants and check imported data.
68 $this->importCSVComponent('Membership', $headers, $rows, 'Individual', 'Skip', $fieldMapper);
72 * Test participant import for Individuals matching on external identifier.
74 function testParticipantImportIndividual() {
75 // This is the path where our testing install resides.
76 // The rest of URL is defined in CiviSeleniumTestCase base class, in
78 $this->open($this->sboxPath
);
80 // Log in using webtestLogin() method
81 $this->webtestLogin();
83 // Get sample import data.
84 list($headers, $rows, $fieldMapper) = $this->_participantIndividualCSVData();
86 // Create and import csv from provided data and check imported data.
87 $this->importCSVComponent('Event', $headers, $rows, 'Individual', 'Skip', $fieldMapper);
91 * Helper function to provide data for contribution import for Individual.
93 function _contributionIndividualCSVData() {
94 $firstName1 = substr(sha1(rand()), 0, 7);
95 $lastName1 = substr(sha1(rand()), 0, 7);
96 $externalId1 = substr(sha1(rand()), 0, 4);
98 $this->_addContact($firstName1, $lastName1, $externalId1);
100 $firstName2 = substr(sha1(rand()), 0, 7);
101 $lastName2 = substr(sha1(rand()), 0, 7);
102 $externalId2 = substr(sha1(rand()), 0, 4);
104 $this->_addContact($firstName2, $lastName2, $externalId2);
107 'external_identifier' => 'External Identifier',
108 'fee_amount' => 'Fee Amount',
109 'financial_type' => 'Financial Type',
110 'contribution_status_id' => 'Contribution Status',
111 'total_amount' => 'Total Amount',
116 'external_identifier' => $externalId1,
117 'fee_amount' => '200',
118 'financial_type' => 'Donation',
119 'contribution_status_id' => 'Completed',
120 'total_amount' => '200',
123 'external_identifier' => $externalId2,
124 'fee_amount' => '400',
125 'financial_type' => 'Donation',
126 'contribution_status_id' => 'Completed',
127 'total_amount' => '400',
130 $fieldMapper = array(
131 'mapper[0][0]' => 'external_identifier',
132 'mapper[2][0]' => 'financial_type',
133 'mapper[4][0]' => 'total_amount',
135 return array($headers, $rows, $fieldMapper);
139 * Helper function to provide data for membership import for Individual.
141 function _memberIndividualCSVData() {
142 $memTypeParams = $this->webtestAddMembershipType();
144 $firstName1 = substr(sha1(rand()), 0, 7);
145 $lastName1 = substr(sha1(rand()), 0, 7);
146 $externalId1 = substr(sha1(rand()), 0, 4);
148 $this->_addContact($firstName1, $lastName1, $externalId1);
149 $startDate1 = date('Y-m-d');
150 $year = date('Y') - 1;
152 $firstName2 = substr(sha1(rand()), 0, 7);
153 $lastName2 = substr(sha1(rand()), 0, 7);
154 $externalId2 = substr(sha1(rand()), 0, 4);
156 $this->_addContact($firstName2, $lastName2, $externalId2);
157 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year));
160 'external_identifier' => 'External Identifier',
161 'membership_type_id' => 'Membership Type',
162 'membership_start_date' => 'Membership Start Date',
166 'external_identifier' => $externalId1,
167 'membership_type_id' => $memTypeParams['membership_type'],
168 'membership_start_date' => $startDate1,
171 'external_identifier' => $externalId2,
172 'membership_type_id' => $memTypeParams['membership_type'],
173 'membership_start_date' => $startDate2,
177 $fieldMapper = array(
178 'mapper[0][0]' => 'external_identifier',
179 'mapper[1][0]' => 'membership_type_id',
180 'mapper[2][0]' => 'membership_start_date',
182 return array($headers, $rows, $fieldMapper);
186 * Helper function to provide data for participant import for Individual.
188 function _participantIndividualCSVData() {
189 $eventInfo = $this->_addNewEvent();
191 $firstName1 = substr(sha1(rand()), 0, 7);
192 $lastName1 = substr(sha1(rand()), 0, 7);
193 $externalId1 = substr(sha1(rand()), 0, 4);
195 $this->_addContact($firstName1, $lastName1, $externalId1);
197 $firstName2 = substr(sha1(rand()), 0, 7);
198 $lastName2 = substr(sha1(rand()), 0, 7);
199 $externalId2 = substr(sha1(rand()), 0, 4);
201 $this->_addContact($firstName2, $lastName2, $externalId2);
204 'external_identifier' => 'External Identifier',
205 'event_id' => 'Event Id',
206 'fee_level' => 'Fee Level',
207 'role' => 'Participant Role',
208 'status' => 'Participant Status',
209 'register_date' => 'Register date',
214 'external_identifier' => $externalId1,
215 'event_id' => $eventInfo['event_id'],
216 'fee_level' => 'Member',
219 'register_date' => '2011-03-30',
222 'external_identifier' => $externalId2,
223 'event_id' => $eventInfo['event_id'],
224 'fee_level' => 'Non-Member',
227 'register_date' => '2011-03-30',
231 $fieldMapper = array(
232 'mapper[0][0]' => 'external_identifier',
233 'mapper[1][0]' => 'event_id',
234 'mapper[2][0]' => 'participant_fee_level',
235 'mapper[4][0]' => 'participant_status_id',
238 return array($headers, $rows, $fieldMapper);
242 * Helper function to add new contact
244 * @params $firstName, $lastName, $externalId
246 * @return int external id
248 function _addContact($firstName, $lastName, $externalId) {
249 $this->open($this->sboxPath
. "civicrm/contact/add?reset=1&ct=Individual");
252 $this->type("first_name", $firstName);
255 $this->type("last_name", $lastName);
257 //fill in external identifier
258 $this->type("external_identifier", $externalId);
261 $this->click("_qf_Contact_upload_view");
262 $this->waitForPageToLoad($this->getTimeoutMsec());
263 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
269 * Helper function to add new event
271 * @params array $params parameters to create an event
273 * @return array $params event details of newly created event
275 function _addNewEvent($params = array(
277 if (empty($params)) {
279 // We need a payment processor
280 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
281 $this->webtestAddPaymentProcessor($processorName);
284 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
286 'title' => $eventTitle,
288 'event_type_id' => 4,
289 'payment_processor' => $processorName,
290 'fee_level' => array(
291 'Member' => "250.00",
292 'Non-Member' => "325.00",
297 $this->open($this->sboxPath
. "civicrm/event/add?reset=1&action=add");
299 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
301 // Let's start filling the form with values.
302 $this->select("event_type_id", "value={$params['event_type_id']}");
304 // Attendee role s/b selected now.
305 $this->select("default_role_id", "value=1");
307 // Enter Event Title, Summary and Description
308 $this->type("title", $params['title']);
309 $this->type("summary", "This is a great conference. Sign up now!");
310 $this->fillRichTextField("description", "Here is a description for this event.", 'CKEditor');
312 // Choose Start and End dates.
313 // Using helper webtestFillDate function.
314 $this->webtestFillDateTime("start_date", "+1 week");
315 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
317 $this->type("max_participants", "50");
318 $this->click("is_map");
319 $this->click("_qf_EventInfo_upload-bottom");
321 // Wait for Location tab form to load
322 $this->waitForPageToLoad($this->getTimeoutMsec());
325 $this->click("link=Fees");
326 $this->waitForElementPresent("_qf_Fee_upload-bottom");
327 $this->click("CIVICRM_QFID_1_is_monetary");
328 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
329 $this->select( "financial_type_id", "value=4" );
332 foreach ($params['fee_level'] as $label => $amount) {
333 $this->type("label_{$counter}", $label);
334 $this->type("value_{$counter}", $amount);
338 $this->click("_qf_Fee_upload-bottom");
339 $this->waitForPageToLoad($this->getTimeoutMsec());
341 // Go to Online Registration tab
342 $this->click("link=Online Registration");
343 $this->waitForElementPresent("_qf_Registration_upload-bottom");
345 $this->check("is_online_registration");
346 $this->assertChecked("is_online_registration");
348 $this->fillRichTextField("intro_text", "Fill in all the fields below and click Continue.");
350 // enable confirmation email
351 $this->click("CIVICRM_QFID_1_is_email_confirm");
352 $this->type("confirm_from_name", "Jane Doe");
353 $this->type("confirm_from_email", "jane.doe@example.org");
355 $this->click("_qf_Registration_upload-bottom");
356 $this->waitForPageToLoad($this->getTimeoutMsec());
357 $this->assertElementContainsText('crm-notification-container', "Saved");
359 // verify event input on info page
360 // start at Manage Events listing
361 $this->open($this->sboxPath
. "civicrm/event/manage?reset=1");
362 $this->type("xpath=//div[@class='crm-block crm-form-block crm-event-searchevent-form-block']/table/tbody/tr/td/input",$params['title']);
363 $this->click("_qf_SearchEvent_refresh");
364 $this->waitForPageToLoad($this->getTimeoutMsec());
365 $this->click("link=" . $params['title']);
367 $this->waitForPageToLoad($this->getTimeoutMsec());
370 preg_match('/id=([0-9]+)/', $this->getLocation(), $matches);
371 $params['event_id'] = $matches[1];