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_ContactCustomDataTest
32 class WebTest_Import_ContactCustomDataTest
extends ImportCiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testCustomDataImport() {
39 $this->webtestLogin();
41 $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7);
42 // Add a custom group and custom field
43 $customDataParams = $this->_addCustomData();
45 // Add New Strict Rule
46 $newRuleTitle = 'IndividualStrict_' . substr(sha1(rand()), 0, 7);
47 $this->openCiviPage("contact/deduperules", "reset=1");
49 $this->click("xpath=//div[@id='browseValues_Individual']/div[2]/a/span");
50 $this->waitForElementPresent('_qf_DedupeRules_next-bottom');
51 $this->type('title', $newRuleTitle);
52 $this->click("CIVICRM_QFID_Supervised_used");
53 $this->select("where_0", "label=$customDataParams[1]");
54 $this->type('weight_0', '10');
55 $this->type('threshold', '10');
56 $this->click('_qf_DedupeRules_next-bottom');
57 $this->waitForPageToLoad($this->getTimeoutMsec());
58 $this->waitForText("crm-notification-container", "The rule '{$newRuleTitle}' has been saved.");
60 $rgId = explode('&rgid=', $this->getAttribute("xpath=//div[@id='browseValues_Individual']/div/div/table/tbody//tr/td[text()='{$newRuleTitle}']/../td[3]/span/a[1][text()='Use Rule']@href"));
61 $rgId = explode('&', $rgId[1]);
64 $firstName2 = 'An_' . substr(sha1(rand()), 0, 7);
65 $this->webtestAddContact($firstName2, "Summerson");
67 // Edit and expand all tabs
68 $this->click('link=Edit');
69 $this->waitForElementPresent('_qf_Contact_cancel');
70 $this->click('link=Expand all tabs');
73 $this->waitForElementPresent("{$customDataParams[0]}_1");
74 $this->type("{$customDataParams[0]}_1", 'This is a test field');
75 $this->click('_qf_Contact_upload_view');
77 // Get sample import data.
78 list($headers, $rows) = $this->_individualCustomCSVData($customDataParams, $firstName1);
80 // Import and check Individual contacts in Skip mode.
82 'saveMapping' => TRUE,
83 'callbackImportSummary' => 'checkDuplicateContacts',
88 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
90 // Import without duplicate checking
91 $other = array('saveMapping' => TRUE);
92 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking', array(), $other);
94 // Type search name in autocomplete.
95 $this->click('sort_name_navigation');
96 $this->type('css=input#sort_name_navigation', $firstName1);
97 $this->typeKeys('css=input#sort_name_navigation', $firstName1);
99 // Wait for result list.
100 $this->waitForElementPresent("css=ul.ui-autocomplete li");
102 // Visit contact summary page.
103 $this->click("css=ul.ui-autocomplete li");
104 $this->waitForPageToLoad($this->getTimeoutMsec());
105 $this->assertTrue($this->isTextPresent('This is a test field'));
109 * Helper function to provide data for custom data import.
111 * @param array $customDataParams
112 * @param string $firstName1
116 public function _individualCustomCSVData($customDataParams, $firstName1) {
118 'first_name' => 'First Name',
119 'last_name' => 'Last Name',
120 "custom_{$customDataParams[0]}" => "{$customDataParams[1]} :: {$customDataParams[2]}",
125 'first_name' => $firstName1,
126 'last_name' => 'Anderson',
127 "custom_{$customDataParams[0]}" => 'This is a test field',
131 return array($headers, $rows);
135 * @param $originalHeaders
136 * @param $originalRows
137 * @param $checkSummary
139 public function checkDuplicateContacts($originalHeaders, $originalRows, $checkSummary) {
140 $this->assertTrue($this->isTextPresent('CiviCRM has detected one record which is a duplicate of existing CiviCRM contact record. These records have not been imported.'));
146 public function _addCustomData() {
148 $this->openCiviPage("admin/custom/group", "reset=1");
150 //add new custom data
151 $this->click("//a[@id='newCustomDataGroup']/span");
152 $this->waitForPageToLoad($this->getTimeoutMsec());
154 //fill custom group title
155 $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7);
156 $this->click('title');
157 $this->type('title', $customGroupTitle);
159 //custom group extends
160 $this->click('extends[0]');
161 $this->select('extends[0]', "value=Contact");
162 $this->click("//option[@value='Contact']");
163 $this->clickLink('_qf_Group_next-bottom');
165 //Is custom group created?
166 $this->waitForText('crm-notification-container', $customGroupTitle);
167 $this->waitForElementPresent('_qf_Field_cancel-bottom');
168 $gid = $this->urlArg('gid');
170 // create another custom field - Date
171 $customField = 'Custom field ' . substr(sha1(rand()), 0, 4);
172 $this->type('label', $customField);
174 //enter pre help message
175 $this->type("help_pre", "this is field pre help");
177 //enter post help message
178 $this->type("help_post", "this field post help");
181 $this->click("is_searchable");
184 $this->click('_qf_Field_done-bottom');
185 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td");
187 $this->waitForText('crm-notification-container', "Custom field '{$customField}' has been saved.");
188 $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/div[text()='$customField']/../../td[8]/span/a@href"));
189 $customFieldId = $customFieldId[1];
191 return array("custom_{$customFieldId}", $customField, $customGroupTitle);