3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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_ContactTest
32 class WebTest_Import_ContactTest
extends ImportCiviSeleniumTestCase
{
34 protected function setUp() {
39 * Test contact import for Individuals.
41 public function testIndividualImport() {
42 $this->webtestLogin();
44 // Get sample import data.
45 list($headers, $rows) = $this->_individualCSVData();
47 // Import and check Individual contacts in Skip mode.
49 'saveMapping' => TRUE,
50 'createGroup' => TRUE,
54 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
56 // Get imported contact Ids
57 $importedContactIds = $this->_getImportedContactIds($rows);
59 // Build update mode import headers
60 $updateHeaders = array(
61 'contact_id' => 'Internal Contact ID',
62 'first_name' => 'First Name',
63 'last_name' => 'Last Name',
66 // Create update mode import rows
67 $updateRows = array();
68 foreach ($importedContactIds as $cid) {
69 $updateRows[$cid] = array(
71 'first_name' => substr(sha1(rand()), 0, 7),
72 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
76 // Import and check Individual contacts in Update mode.
77 $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update');
79 // Visit contacts to check updated data.
80 foreach ($updateRows as $updatedRow) {
81 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
83 $displayName = "{$updatedRow['first_name']} {$updatedRow['last_name']}";
84 $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not update!");
87 // Headers that should not updated.
88 $fillHeaders = $updateHeaders;
90 // Headers that should fill.
91 $fillHeaders['gender'] = 'Gender';
92 $fillHeaders['dob'] = 'Birth Date';
95 foreach ($importedContactIds as $cid) {
96 $fillRows[$cid] = array(
99 'first_name' => substr(sha1(rand()), 0, 7),
101 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
103 'dob' => '1986-04-16',
107 // Import and check Individual contacts in Update mode.
108 $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill');
110 // Visit contacts to check filled data.
111 foreach ($fillRows as $cid => $fillRow) {
112 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
114 // Check old display name.
115 $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}";
116 $this->assertTrue($this->isTextPresent("$displayName"), "Contact display name should not update in fill mode!");
118 $this->verifyText("css=div#contact-summary div.crm-contact-gender_display", preg_quote($fillRow['gender']));
121 // Recreate same conacts using 'No Duplicate Checking'
122 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking');
126 * Test contact import for Organization.
128 public function testOrganizationImport() {
130 $this->webtestLogin();
132 // Get sample import data.
133 list($headers, $rows) = $this->_organizationCSVData();
135 // Import and check Organization contacts
137 'saveMapping' => TRUE,
138 'createGroup' => TRUE,
142 $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other);
144 // Get imported contact Ids
145 $importedContactIds = $this->_getImportedContactIds($rows, 'Organization');
147 // Build update mode import headers
148 $updateHeaders = array(
149 'contact_id' => 'Internal Contact ID',
150 'organization_name' => 'Organization Name',
153 // Create update mode import rows
154 $updateRows = array();
155 foreach ($importedContactIds as $cid) {
156 $updateRows[$cid] = array(
157 'contact_id' => $cid,
158 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7),
162 // Import and check Individual contacts in Update mode.
163 $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update');
165 // Visit contacts to check updated data.
166 foreach ($updateRows as $updatedRow) {
167 $organizationName = $updatedRow['organization_name'];
168 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
170 $this->assertTrue($this->isTextPresent("$organizationName"), "Contact did not update!");
173 // Headers that should not updated.
174 $fillHeaders = $updateHeaders;
176 // Headers that should fill.
177 $fillHeaders['legal_name'] = 'Legal Name';
180 foreach ($importedContactIds as $cid) {
181 $fillRows[$cid] = array(
182 'contact_id' => $cid,
184 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7),
185 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7),
189 // Import and check Individual contacts in Update mode.
190 $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill');
192 // Visit contacts to check filled data.
193 foreach ($fillRows as $cid => $fillRow) {
194 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
196 // Check old Organization name.
197 $organizationName = $updateRows[$cid]['organization_name'];
198 $this->assertTrue($this->isTextPresent("$organizationName"), "Contact should not update in fill mode!");
199 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRow['legal_name']));
202 // Recreate same conacts using 'No Duplicate Checking'
203 $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking');
207 * Test contact import for Household.
209 public function testHouseholdImport() {
211 $this->webtestLogin();
213 // Get sample import data.
214 list($headers, $rows) = $this->_householdCSVData();
216 // Import and check Household contacts
218 'saveMapping' => TRUE,
219 'createGroup' => TRUE,
223 $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other);
225 // Get imported contact Ids
226 $importedContactIds = $this->_getImportedContactIds($rows, 'Household');
228 // Build update mode import headers
229 $updateHeaders = array(
230 'contact_id' => 'Internal Contact ID',
231 'household_name' => 'Household Name',
234 // Create update mode import rows
235 $updateRows = array();
236 foreach ($importedContactIds as $cid) {
237 $updateRows[$cid] = array(
238 'contact_id' => $cid,
239 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
243 // Import and check Individual contacts in Update mode.
244 $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update');
246 // Visit contacts to check updated data.
247 foreach ($updateRows as $updatedRow) {
248 $householdName = $updatedRow['household_name'];
249 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
251 $this->assertTrue($this->isTextPresent("$householdName"), "Contact did not update!");
254 // Headers that should not updated.
255 $fillHeaders = $updateHeaders;
257 // Headers that should fill.
258 $fillHeaders['nick_name'] = 'Nick Name';
261 foreach ($importedContactIds as $cid) {
262 $fillRows[$cid] = array(
263 'contact_id' => $cid,
265 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
266 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7),
270 // Import and check Individual contacts in Update mode.
271 $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill');
273 // Visit contacts to check filled data.
274 foreach ($fillRows as $cid => $fillRow) {
275 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
277 // Check old Household name.
278 $householdName = $updateRows[$cid]['household_name'];
279 $this->assertTrue($this->isTextPresent("$householdName"), "Contact should not update in fill mode!");
280 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRow['nick_name']));
283 // Recreate same conacts using 'No Duplicate Checking'
284 $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking');
288 * Helper function to provide data for contact import for Individuals.
293 public function _individualCSVData() {
295 'first_name' => 'First Name',
296 'middle_name' => 'Middle Name',
297 'last_name' => 'Last Name',
300 'address_1' => 'Additional Address 1',
301 'address_2' => 'Additional Address 2',
304 'country' => 'Country',
309 'first_name' => substr(sha1(rand()), 0, 7),
310 'middle_name' => substr(sha1(rand()), 0, 7),
311 'last_name' => 'Anderson',
312 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
313 'phone' => '6949912154',
314 'address_1' => 'Add 1',
315 'address_2' => 'Add 2',
318 'country' => 'UNITED STATES',
321 'first_name' => substr(sha1(rand()), 0, 7),
322 'middle_name' => substr(sha1(rand()), 0, 7),
323 'last_name' => 'Summerson',
324 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
325 'phone' => '6944412154',
326 'address_1' => 'Add 1',
327 'address_2' => 'Add 2',
330 'country' => 'UNITED STATES',
334 return array($headers, $rows);
338 * Helper function to provide data for contact import for Organizations.
343 public function _organizationCSVData() {
345 'organization_name' => 'Organization Name',
348 'address_1' => 'Additional Address 1',
349 'address_2' => 'Additional Address 2',
352 'country' => 'Country',
357 'organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
358 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
359 'phone' => '9949912154',
360 'address_1' => 'Add 1',
361 'address_2' => 'Add 2',
364 'country' => 'UNITED STATES',
367 'organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
368 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
369 'phone' => '6949412154',
370 'address_1' => 'Add 1',
371 'address_2' => 'Add 2',
374 'country' => 'UNITED STATES',
378 return array($headers, $rows);
382 * Helper function to provide data for contact import for Household.
387 public function _householdCSVData() {
389 'household_name' => 'Household Name',
392 'address_1' => 'Additional Address 1',
393 'address_2' => 'Additional Address 2',
396 'country' => 'Country',
401 'household_name' => 'household_' . substr(sha1(rand()), 0, 7),
402 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
403 'phone' => '3949912154',
404 'address_1' => 'Add 1',
405 'address_2' => 'Add 2',
408 'country' => 'UNITED STATES',
411 'household_name' => 'household_' . substr(sha1(rand()), 0, 7),
412 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
413 'phone' => '5949412154',
414 'address_1' => 'Add 1',
415 'address_2' => 'Add 2',
418 'country' => 'UNITED STATES',
422 return array($headers, $rows);