3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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';
28 class WebTest_Import_ContactCustomDataTest
extends ImportCiviSeleniumTestCase
{
30 protected function setUp() {
34 function testCustomDataImport() {
35 $this->webtestLogin();
37 $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7);
38 // Add a custom group and custom field
39 $customDataParams = $this->_addCustomData();
41 // Add New Strict Rule
42 $newRuleTitle = 'IndividualStrict_' . substr(sha1(rand()), 0, 7);
43 $this->openCiviPage("contact/deduperules", "reset=1");
45 $this->click("xpath=//div[@id='browseValues_Individual']/div[2]/a/span");
46 $this->waitForElementPresent('_qf_DedupeRules_next-bottom');
47 $this->type('title', $newRuleTitle);
48 $this->click("CIVICRM_QFID_1_used");
49 $this->select("where_0", "label=$customDataParams[1]");
50 $this->type('weight_0', '10');
51 $this->type('threshold', '10');
52 $this->click('_qf_DedupeRules_next-bottom');
53 $this->waitForPageToLoad($this->getTimeoutMsec());
54 $this->assertTrue($this->isTextPresent("The rule '{$newRuleTitle}' has been saved."));
56 $rgId = explode('&rgid=', $this->getAttribute("xpath=//div[@id='browseValues_Individual']//table/tbody//tr/td[text()='{$newRuleTitle}']/../td[3]/span/a[text()='Use Rule']@href"));
57 $rgId = explode('&', $rgId[1]);
60 $firstName2 = 'An_' . substr(sha1(rand()), 0, 7);
61 $this->webtestAddContact($firstName2, "Summerson");
62 $this->waitForPageToLoad($this->getTimeoutMsec());
64 // Edit and expand all tabs
65 $this->click('link=Edit');
66 $this->waitForElementPresent('_qf_Contact_cancel');
67 $this->click('link=Expand all tabs');
70 $this->waitForElementPresent("{$customDataParams[0]}_1");
71 $this->type("{$customDataParams[0]}_1", 'This is a test field');
72 $this->click('_qf_Contact_upload_view');
74 // Get sample import data.
75 list($headers, $rows) = $this->_individualCustomCSVData($customDataParams, $firstName1);
77 // Import and check Individual contacts in Skip mode.
79 'saveMapping' => TRUE,
80 'callbackImportSummary' => 'checkDuplicateContacts',
85 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
87 // Import without duplicate checking
88 $other = array('saveMapping' => TRUE);
89 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking', array(), $other);
91 // Type search name in autocomplete.
92 $this->click('sort_name_navigation');
93 $this->type('css=input#sort_name_navigation', $firstName1);
94 $this->typeKeys('css=input#sort_name_navigation', $firstName1);
96 // Wait for result list.
97 $this->waitForElementPresent("css=div.ac_results-inner li");
99 // Visit contact summary page.
100 $this->click("css=div.ac_results-inner li");
101 $this->waitForPageToLoad($this->getTimeoutMsec());
102 $this->assertTrue($this->isTextPresent('This is a test field'));
106 * Helper function to provide data for custom data import.
108 function _individualCustomCSVData($customDataParams, $firstName1) {
110 'first_name' => 'First Name',
111 'last_name' => 'Last Name',
112 "custom_{$customDataParams[0]}" => "{$customDataParams[1]} :: {$customDataParams[2]}",
116 array('first_name' => $firstName1,
117 'last_name' => 'Anderson',
118 "custom_{$customDataParams[0]}" => 'This is a test field',
122 return array($headers, $rows);
125 function checkDuplicateContacts($originalHeaders, $originalRows, $checkSummary) {
126 $this->assertTrue($this->isTextPresent('CiviCRM has detected one record which is a duplicate of existing CiviCRM contact record. These records have not been imported.'));
129 function _addCustomData() {
131 $this->openCiviPage("admin/custom/group", "reset=1");
133 //add new custom data
134 $this->click("//a[@id='newCustomDataGroup']/span");
135 $this->waitForPageToLoad($this->getTimeoutMsec());
137 //fill custom group title
138 $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7);
139 $this->click('title');
140 $this->type('title', $customGroupTitle);
142 //custom group extends
143 $this->click('extends[0]');
144 $this->select('extends[0]', "value=Contact");
145 $this->click("//option[@value='Contact']");
146 $this->click('_qf_Group_next-bottom');
147 $this->waitForElementPresent('_qf_Field_cancel-bottom');
149 //Is custom group created?
150 $this->waitForText('crm-notification-container', $customGroupTitle);
151 $gid = $this->urlArg('gid');
153 // create another custom field - Date
154 $customField = 'Custom field ' . substr(sha1(rand()), 0, 4);
155 $this->type('label', $customField);
157 //enter pre help message
158 $this->type("help_pre", "this is field pre help");
160 //enter post help message
161 $this->type("help_post", "this field post help");
164 $this->click("is_searchable");
167 $this->click('_qf_Field_next-bottom');
168 $this->waitForElementPresent('newCustomField');
170 $this->assertTrue($this->isTextPresent("Your custom field '{$customField}' has been saved."));
171 $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField']/../../td[8]/span/a@href"));
172 $customFieldId = $customFieldId[1];
174 return array("custom_{$customFieldId}", $customField, $customGroupTitle);