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_ContactSubtypeTest
32 class WebTest_Import_ContactSubtypeTest
extends ImportCiviSeleniumTestCase
{
34 protected function setUp() {
39 * Test contact import for Individuals Subtype.
41 public function testIndividualSubtypeImport() {
42 $this->webtestLogin();
44 // Get sample import data.
45 list($headers, $rows) = $this->_individualSubtypeCSVData();
47 // Import and check Individual contacts in Skip mode with contact type Parent.
48 $other = array('contactSubtype' => 'Parent');
50 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
52 // Get imported contact Ids
53 $importedContactIds = $this->_getImportedContactIds($rows);
55 // Build update mode import headers
56 $updateHeaders = array(
57 'contact_id' => 'Internal Contact ID',
58 'first_name' => 'First Name',
59 'last_name' => 'Last Name',
62 // Create update mode import rows
63 $updateRows = array();
64 foreach ($importedContactIds as $cid) {
65 $updateRows[$cid] = array(
67 'first_name' => substr(sha1(rand()), 0, 7),
68 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
72 // Import and check Individual contacts in Update mode with contact type Parent.
73 $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update', array(), $other);
75 // Visit contacts to check updated data.
76 foreach ($updateRows as $updatedRow) {
77 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
78 $displayName = "{$updatedRow['first_name']} {$updatedRow['last_name']}";
79 $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not update!");
82 // Headers that should not updated.
83 $fillHeaders = $updateHeaders;
85 // Headers that should fill.
86 $fillHeaders['gender'] = 'Gender';
87 $fillHeaders['dob'] = 'Birth Date';
90 foreach ($importedContactIds as $cid) {
91 $fillRows[$cid] = array(
94 'first_name' => substr(sha1(rand()), 0, 7),
96 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
98 'dob' => '1986-04-16',
102 // Import and check Individual contacts in Update mode with contact type Parent.
103 $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill', array(), $other);
105 // Visit contacts to check filled data.
106 foreach ($fillRows as $cid => $fillRow) {
107 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
109 // Check old display name.
110 $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}";
111 $this->assertTrue($this->isTextPresent("$displayName"), "Contact should not update in fill mode!");
113 $this->verifyText("css=div#contact-summary div.crm-contact-gender_display", preg_quote($fillRow['gender']));
116 // Recreate same conacts using 'No Duplicate Checking' with contact type Parent.
117 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking', array(), $other);
121 * Test contact import for Organization Subtype.
123 public function testOrganizationSubtypeImport() {
124 $this->webtestLogin();
126 // Get sample import data.
127 list($headers, $rows) = $this->_organizationSubtypeCSVData();
129 // Import and check Organization contacts
130 $other = array('contactSubtype' => 'Team');
132 $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other);
134 // Get imported contact Ids
135 $importedContactIds = $this->_getImportedContactIds($rows, 'Organization');
137 // Build update mode import headers
138 $updateHeaders = array(
139 'contact_id' => 'Internal Contact ID',
140 'organization_name' => 'Organization Name',
143 // Create update mode import rows
144 $updateRows = array();
145 foreach ($importedContactIds as $cid) {
146 $updateRows[$cid] = array(
147 'contact_id' => $cid,
148 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7),
152 // Import and check Individual contacts in Update mode with contact type Team.
153 $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update', array(), $other);
155 // Visit contacts to check updated data.
156 foreach ($updateRows as $updatedRow) {
157 $organizationName = $updatedRow['organization_name'];
158 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
160 $this->assertTrue($this->isTextPresent("$organizationName"), "Contact did not update!");
163 // Headers that should not updated.
164 $fillHeaders = $updateHeaders;
166 // Headers that should fill.
167 $fillHeaders['legal_name'] = 'Legal Name';
170 foreach ($importedContactIds as $cid) {
171 $fillRows[$cid] = array(
172 'contact_id' => $cid,
174 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7),
175 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7),
179 // Import and check Individual contacts in Update mode with contact type Team.
180 $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill', array(), $other);
182 // Visit contacts to check filled data.
183 foreach ($fillRows as $cid => $fillRow) {
184 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
186 // Check old Organization name.
187 $organizationName = $updateRows[$cid]['organization_name'];
188 $this->assertTrue($this->isTextPresent("$organizationName"), "Contact should not update in fill mode!");
189 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRow['legal_name']));
192 // Recreate same conacts using 'No Duplicate Checking' with contact type Team.
193 $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking', array(), $other);
197 * Test contact import for Household Subtype.
199 public function testHouseholdSubtypeImport() {
200 $this->webtestLogin();
202 // Create Household Subtype
203 $householdSubtype = $this->_createHouseholdSubtype();
205 // Get sample import data.
206 list($headers, $rows) = $this->_householdSubtypeCSVData();
208 // Import and check Organization contacts
209 $other = array('contactSubtype' => $householdSubtype);
211 $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other);
213 // Get imported contact Ids
214 $importedContactIds = $this->_getImportedContactIds($rows, 'Household');
216 // Build update mode import headers
217 $updateHeaders = array(
218 'contact_id' => 'Internal Contact ID',
219 'household_name' => 'Household Name',
222 // Create update mode import rows
223 $updateRows = array();
224 foreach ($importedContactIds as $cid) {
225 $updateRows[$cid] = array(
226 'contact_id' => $cid,
227 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
231 // Import and check Individual contacts in Update mode.
232 $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update', array(), $other);
234 // Visit contacts to check updated data.
235 foreach ($updateRows as $updatedRow) {
236 $householdName = $updatedRow['household_name'];
237 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
239 $this->assertTrue($this->isTextPresent("$householdName"), "Contact did not update!");
242 // Headers that should not updated.
243 $fillHeaders = $updateHeaders;
245 // Headers that should fill.
246 $fillHeaders['nick_name'] = 'Nick Name';
249 foreach ($importedContactIds as $cid) {
250 $fillRows[$cid] = array(
251 'contact_id' => $cid,
253 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
254 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7),
258 // Import and check Individual contacts in Update mode.
259 $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill', array(), $other);
261 // Visit contacts to check filled data.
262 foreach ($fillRows as $cid => $fillRow) {
263 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
265 // Check old Household name.
266 $householdName = $updateRows[$cid]['household_name'];
267 $this->assertTrue($this->isTextPresent("$householdName"), "Contact should not update in fill mode!");
268 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRow['nick_name']));
271 // Recreate same conacts using 'No Duplicate Checking'
272 $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking', array(), $other);
276 * Helper function to create Household Subtype.
281 public function _createHouseholdSubtype() {
283 // Visit to create contact subtype
284 $this->openCiviPage("admin/options/subtype", "action=add&reset=1");
286 // Create Household subtype
287 $householdSubtype = substr(sha1(rand()), 0, 7);
288 $this->type("label", $householdSubtype);
289 $this->select("parent_id", "label=Household");
290 $this->click("_qf_ContactType_next-bottom");
291 $this->waitForPageToLoad($this->getTimeoutMsec());
292 return $householdSubtype;
296 * Helper function to provide data for contact import for Individuals Subtype.
301 public function _individualSubtypeCSVData() {
303 'first_name' => 'First Name',
304 'middle_name' => 'Middle Name',
305 'last_name' => 'Last Name',
308 'address_1' => 'Additional Address 1',
309 'address_2' => 'Additional Address 2',
312 'country' => 'Country',
317 'first_name' => substr(sha1(rand()), 0, 7),
318 'middle_name' => substr(sha1(rand()), 0, 7),
319 'last_name' => 'Anderson',
320 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
321 'phone' => '6949912154',
322 'address_1' => 'Add 1',
323 'address_2' => 'Add 2',
326 'country' => 'UNITED STATES',
329 'first_name' => substr(sha1(rand()), 0, 7),
330 'middle_name' => substr(sha1(rand()), 0, 7),
331 'last_name' => 'Summerson',
332 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
333 'phone' => '6944412154',
334 'address_1' => 'Add 1',
335 'address_2' => 'Add 2',
338 'country' => 'UNITED STATES',
342 return array($headers, $rows);
346 * Helper function to provide data for contact import for Organizations Subtype.
351 public function _organizationSubtypeCSVData() {
353 'organization_name' => 'Organization Name',
356 'address_1' => 'Additional Address 1',
357 'address_2' => 'Additional Address 2',
360 'country' => 'Country',
365 'organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
366 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
367 'phone' => '9949912154',
368 'address_1' => 'Add 1',
369 'address_2' => 'Add 2',
372 'country' => 'UNITED STATES',
375 'organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
376 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
377 'phone' => '6949412154',
378 'address_1' => 'Add 1',
379 'address_2' => 'Add 2',
382 'country' => 'UNITED STATES',
386 return array($headers, $rows);
390 * Helper function to provide data for contact import for Household Subtype.
395 public function _householdSubtypeCSVData() {
397 'household_name' => 'Household Name',
400 'address_1' => 'Additional Address 1',
401 'address_2' => 'Additional Address 2',
404 'country' => 'Country',
409 'household_name' => 'household_' . substr(sha1(rand()), 0, 7),
410 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
411 'phone' => '3949912154',
412 'address_1' => 'Add 1',
413 'address_2' => 'Add 2',
416 'country' => 'UNITED STATES',
419 'household_name' => 'household_' . substr(sha1(rand()), 0, 7),
420 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
421 'phone' => '5949412154',
422 'address_1' => 'Add 1',
423 'address_2' => 'Add 2',
426 'country' => 'UNITED STATES',
430 return array($headers, $rows);