3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
27 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
30 * Class WebTest_Import_MatchExternalIdTest
32 class WebTest_Import_MatchExternalIdTest
extends ImportCiviSeleniumTestCase
{
34 protected function setUp() {
39 * Test participant import for Individuals matching on external identifier.
41 public function testContributionImport() {
42 $this->webtestLogin();
44 // Get sample import data.
45 list($headers, $rows, $fieldMapper) = $this->_contributionIndividualCSVData();
47 // Create and import csv from provided data and check imported data.
48 $this->importCSVComponent('Contribution', $headers, $rows, 'Individual', 'Insert new contributions', $fieldMapper);
52 * Test membership import for Individuals matching on external identifier.
54 public function testMemberImportIndividual() {
55 $this->webtestLogin();
57 // Get membership import data for Individuals.
58 list($headers, $rows, $fieldMapper) = $this->_memberIndividualCSVData();
60 // Import participants and check imported data.
61 $this->importCSVComponent('Membership', $headers, $rows, 'Individual', 'Skip', $fieldMapper);
65 * Test participant import for Individuals matching on external identifier.
67 public function testParticipantImportIndividual() {
68 // Log in using webtestLogin() method
69 $this->webtestLogin();
71 // Get sample import data.
72 list($headers, $rows, $fieldMapper) = $this->_participantIndividualCSVData();
74 // Create and import csv from provided data and check imported data.
75 $this->importCSVComponent('Event', $headers, $rows, 'Individual', 'Skip', $fieldMapper);
79 * Helper function to provide data for contribution import for Individual.
83 public function _contributionIndividualCSVData() {
84 $firstName1 = substr(sha1(rand()), 0, 7);
85 $lastName1 = substr(sha1(rand()), 0, 7);
86 $externalId1 = substr(sha1(rand()), 0, 4);
88 $this->_addContact($firstName1, $lastName1, $externalId1);
90 $firstName2 = substr(sha1(rand()), 0, 7);
91 $lastName2 = substr(sha1(rand()), 0, 7);
92 $externalId2 = substr(sha1(rand()), 0, 4);
94 $this->_addContact($firstName2, $lastName2, $externalId2);
97 'external_identifier' => 'External Identifier',
98 'fee_amount' => 'Fee Amount',
99 'financial_type' => 'Financial Type',
100 'contribution_status_id' => 'Contribution Status',
101 'total_amount' => 'Total Amount',
106 'external_identifier' => $externalId1,
107 'fee_amount' => '200',
108 'financial_type' => 'Donation',
109 'contribution_status_id' => 'Completed',
110 'total_amount' => '200',
113 'external_identifier' => $externalId2,
114 'fee_amount' => '400',
115 'financial_type' => 'Donation',
116 'contribution_status_id' => 'Completed',
117 'total_amount' => '400',
120 $fieldMapper = array(
121 'mapper[0][0]' => 'external_identifier',
122 'mapper[2][0]' => 'financial_type',
123 'mapper[4][0]' => 'total_amount',
125 return array($headers, $rows, $fieldMapper);
129 * Helper function to provide data for membership import for Individual.
133 public function _memberIndividualCSVData() {
134 $memTypeParams = $this->webtestAddMembershipType();
136 $firstName1 = substr(sha1(rand()), 0, 7);
137 $lastName1 = substr(sha1(rand()), 0, 7);
138 $externalId1 = substr(sha1(rand()), 0, 4);
140 $this->_addContact($firstName1, $lastName1, $externalId1);
141 $startDate1 = date('Y-m-d');
142 $year = date('Y') - 1;
144 $firstName2 = substr(sha1(rand()), 0, 7);
145 $lastName2 = substr(sha1(rand()), 0, 7);
146 $externalId2 = substr(sha1(rand()), 0, 4);
148 $this->_addContact($firstName2, $lastName2, $externalId2);
149 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year));
152 'external_identifier' => 'External Identifier',
153 'membership_type_id' => 'Membership Type',
154 'membership_start_date' => 'Membership Start Date',
158 'external_identifier' => $externalId1,
159 'membership_type_id' => $memTypeParams['membership_type'],
160 'membership_start_date' => $startDate1,
163 'external_identifier' => $externalId2,
164 'membership_type_id' => $memTypeParams['membership_type'],
165 'membership_start_date' => $startDate2,
169 $fieldMapper = array(
170 'mapper[0][0]' => 'external_identifier',
171 'mapper[1][0]' => 'membership_type_id',
172 'mapper[2][0]' => 'membership_start_date',
174 return array($headers, $rows, $fieldMapper);
178 * Helper function to provide data for participant import for Individual.
182 public function _participantIndividualCSVData() {
183 $eventInfo = $this->_addNewEvent();
185 $firstName1 = substr(sha1(rand()), 0, 7);
186 $lastName1 = substr(sha1(rand()), 0, 7);
187 $externalId1 = substr(sha1(rand()), 0, 4);
189 $this->_addContact($firstName1, $lastName1, $externalId1);
191 $firstName2 = substr(sha1(rand()), 0, 7);
192 $lastName2 = substr(sha1(rand()), 0, 7);
193 $externalId2 = substr(sha1(rand()), 0, 4);
195 $this->_addContact($firstName2, $lastName2, $externalId2);
198 'external_identifier' => 'External Identifier',
199 'event_id' => 'Event Id',
200 'fee_level' => 'Fee Level',
201 'role' => 'Participant Role',
202 'status' => 'Participant Status',
203 'register_date' => 'Register date',
208 'external_identifier' => $externalId1,
209 'event_id' => $eventInfo['event_id'],
210 'fee_level' => 'Member',
213 'register_date' => '2011-03-30',
216 'external_identifier' => $externalId2,
217 'event_id' => $eventInfo['event_id'],
218 'fee_level' => 'Non-Member',
221 'register_date' => '2011-03-30',
225 $fieldMapper = array(
226 'mapper[0][0]' => 'external_identifier',
227 'mapper[1][0]' => 'event_id',
228 'mapper[2][0]' => 'participant_fee_level',
229 'mapper[4][0]' => 'participant_status_id',
232 return array($headers, $rows, $fieldMapper);
236 * Helper function to add new contact.
238 * @param string $firstName
239 * @param string $lastName
240 * @param int $externalId
245 public function _addContact($firstName, $lastName, $externalId) {
246 $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
249 $this->type("first_name", $firstName);
252 $this->type("last_name", $lastName);
254 //fill in external identifier
255 $this->type("external_identifier", $externalId);
258 $this->click("_qf_Contact_upload_view");
259 $this->waitForPageToLoad($this->getTimeoutMsec());
260 $this->waitForText('crm-notification-container', "Contact Saved");
266 * Helper function to add new event.
268 * @param array $params
271 * event details of newly created event
273 public function _addNewEvent($params = array()) {
274 if (empty($params)) {
276 // Use default payment processor
277 $processorName = 'Test Processor';
278 $this->webtestAddPaymentProcessor($processorName);
281 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
283 'title' => $eventTitle,
285 'event_type_id' => 4,
286 'payment_processor' => $processorName,
287 'fee_level' => array(
288 'Member' => "250.00",
289 'Non-Member' => "325.00",
294 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
296 $this->select("event_type_id", "value={$params['event_type_id']}");
298 // Attendee role s/b selected now.
299 $this->select("default_role_id", "value=1");
301 // Enter Event Title, Summary and Description
302 $this->type("title", $params['title']);
303 $this->type("summary", "This is a great conference. Sign up now!");
304 $this->fillRichTextField("description", "Here is a description for this event.", 'CKEditor');
306 // Choose Start and End dates.
307 // Using helper webtestFillDate function.
308 $this->webtestFillDateTime("start_date", "+1 week");
309 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
311 $this->type("max_participants", "50");
312 $this->click("is_map");
313 $this->click("_qf_EventInfo_upload-bottom");
315 // Wait for Location tab form to load
316 $this->waitForPageToLoad($this->getTimeoutMsec());
319 $this->click("link=Fees");
320 $this->waitForElementPresent("_qf_Fee_upload-bottom");
321 $this->click("CIVICRM_QFID_1_is_monetary");
322 $this->select2('payment_processor', $processorName, TRUE);
323 $this->select("financial_type_id", "value=4");
326 foreach ($params['fee_level'] as $label => $amount) {
327 $this->type("label_{$counter}", $label);
328 $this->type("value_{$counter}", $amount);
332 $this->click("_qf_Fee_upload-bottom");
333 $this->waitForElementPresent("_qf_Fee_upload-bottom");
335 // Go to Online Registration tab
336 $this->click("link=Online Registration");
337 $this->waitForElementPresent("_qf_Registration_upload-bottom");
339 $this->click("is_online_registration");
340 $this->assertChecked("is_online_registration");
342 $this->fillRichTextField("intro_text", "Fill in all the fields below and click Continue.", 'CKEditor', TRUE);
344 // enable confirmation email
345 $this->click("CIVICRM_QFID_1_is_email_confirm");
346 $this->type("confirm_from_name", "Jane Doe");
347 $this->type("confirm_from_email", "jane.doe@example.org");
349 $this->click("_qf_Registration_upload-bottom");
350 $this->waitForElementPresent("_qf_Registration_upload-bottom");
351 $this->waitForText('crm-notification-container', "'Online Registration' information has been saved");
353 // verify event input on info page
354 // start at Manage Events listing
355 $this->openCiviPage('event/manage', 'reset=1');
356 $this->type("xpath=//div[@class='crm-block crm-form-block crm-event-searchevent-form-block']/table/tbody/tr/td/input", $params['title']);
357 $this->click("_qf_SearchEvent_refresh");
358 $this->waitForPageToLoad($this->getTimeoutMsec());
359 $this->clickLink("link=" . $params['title'], NULL);
361 $params['event_id'] = $this->urlArg('id');