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_ContactCustomDataTest
extends ImportCiviSeleniumTestCase
{
31 protected function setUp() {
35 function testCustomDataImport() {
36 $this->webtestLogin();
38 $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7);
39 // Add a custom group and custom field
40 $customDataParams = $this->_addCustomData();
42 // Add New Strict Rule
43 $newRuleTitle = 'IndividualStrict_' . substr(sha1(rand()), 0, 7);
44 $this->openCiviPage("contact/deduperules", "reset=1");
46 $this->click("xpath=//div[@id='browseValues_Individual']/div[2]/a/span");
47 $this->waitForElementPresent('_qf_DedupeRules_next-bottom');
48 $this->type('title', $newRuleTitle);
49 $this->click("CIVICRM_QFID_1_used");
50 $this->select("where_0", "label=$customDataParams[1]");
51 $this->type('weight_0', '10');
52 $this->type('threshold', '10');
53 $this->click('_qf_DedupeRules_next-bottom');
54 $this->waitForPageToLoad($this->getTimeoutMsec());
55 $this->assertTrue($this->isTextPresent("The rule '{$newRuleTitle}' has been saved."));
57 $rgId = explode('&rgid=', $this->getAttribute("xpath=//div[@id='browseValues_Individual']//table/tbody//tr/td[text()='{$newRuleTitle}']/../td[3]/span/a[text()='Use Rule']@href"));
58 $rgId = explode('&', $rgId[1]);
61 $firstName2 = 'An_' . substr(sha1(rand()), 0, 7);
62 $this->webtestAddContact($firstName2, "Summerson");
63 $this->waitForPageToLoad($this->getTimeoutMsec());
65 // Edit and expand all tabs
66 $this->click('link=Edit');
67 $this->waitForElementPresent('_qf_Contact_cancel');
68 $this->click('link=Expand all tabs');
71 $this->waitForElementPresent("{$customDataParams[0]}_1");
72 $this->type("{$customDataParams[0]}_1", 'This is a test field');
73 $this->click('_qf_Contact_upload_view');
75 // Get sample import data.
76 list($headers, $rows) = $this->_individualCustomCSVData($customDataParams, $firstName1);
78 // Import and check Individual contacts in Skip mode.
80 'saveMapping' => TRUE,
81 'callbackImportSummary' => 'checkDuplicateContacts',
86 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
88 // Import without duplicate checking
89 $other = array('saveMapping' => TRUE);
90 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking', array(), $other);
92 // Type search name in autocomplete.
93 $this->click('sort_name_navigation');
94 $this->type('css=input#sort_name_navigation', $firstName1);
95 $this->typeKeys('css=input#sort_name_navigation', $firstName1);
97 // Wait for result list.
98 $this->waitForElementPresent("css=div.ac_results-inner li");
100 // Visit contact summary page.
101 $this->click("css=div.ac_results-inner li");
102 $this->waitForPageToLoad($this->getTimeoutMsec());
103 $this->assertTrue($this->isTextPresent('This is a test field'));
108 * Helper function to provide data for custom data import.
110 function _individualCustomCSVData($customDataParams, $firstName1) {
112 'first_name' => 'First Name',
113 'last_name' => 'Last Name',
114 "custom_{$customDataParams[0]}" => "{$customDataParams[1]} :: {$customDataParams[2]}",
118 array('first_name' => $firstName1,
119 'last_name' => 'Anderson',
120 "custom_{$customDataParams[0]}" => 'This is a test field',
124 return array($headers, $rows);
127 function checkDuplicateContacts($originalHeaders, $originalRows, $checkSummary) {
128 $this->assertTrue($this->isTextPresent('CiviCRM has detected one record which is a duplicate of existing CiviCRM contact record. These records have not been imported.'));
131 function _addCustomData() {
133 $this->openCiviPage("admin/custom/group", "reset=1");
135 //add new custom data
136 $this->click("//a[@id='newCustomDataGroup']/span");
137 $this->waitForPageToLoad($this->getTimeoutMsec());
139 //fill custom group title
140 $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7);
141 $this->click('title');
142 $this->type('title', $customGroupTitle);
144 //custom group extends
145 $this->click('extends[0]');
146 $this->select('extends[0]', "value=Contact");
147 $this->click("//option[@value='Contact']");
148 $this->click('_qf_Group_next-bottom');
149 $this->waitForElementPresent('_qf_Field_cancel-bottom');
151 //Is custom group created?
152 $this->assertTrue($this->isTextPresent("Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."));
153 $url = explode('gid=', $this->getLocation());
156 // create another custom field - Date
157 $customField = 'Custom field ' . substr(sha1(rand()), 0, 4);
158 $this->type('label', $customField);
160 //enter pre help message
161 $this->type("help_pre", "this is field pre help");
163 //enter post help message
164 $this->type("help_post", "this field post help");
167 $this->click("is_searchable");
170 $this->click('_qf_Field_next-bottom');
171 $this->waitForElementPresent('newCustomField');
173 $this->assertTrue($this->isTextPresent("Your custom field '{$customField}' has been saved."));
174 $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField']/../../td[8]/span/a@href"));
175 $customFieldId = $customFieldId[1];
177 return array("custom_{$customFieldId}", $customField, $customGroupTitle);