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_Supervised_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->waitForText("crm-notification-container", "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=ul.ui-autocomplete li");
99 // Visit contact summary page.
100 $this->click("css=ul.ui-autocomplete 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.
109 * @param $customDataParams
114 function _individualCustomCSVData($customDataParams, $firstName1) {
116 'first_name' => 'First Name',
117 'last_name' => 'Last Name',
118 "custom_{$customDataParams[0]}" => "{$customDataParams[1]} :: {$customDataParams[2]}",
122 array('first_name' => $firstName1,
123 'last_name' => 'Anderson',
124 "custom_{$customDataParams[0]}" => 'This is a test field',
128 return array($headers, $rows);
132 * @param $originalHeaders
133 * @param $originalRows
134 * @param $checkSummary
136 function checkDuplicateContacts($originalHeaders, $originalRows, $checkSummary) {
137 $this->assertTrue($this->isTextPresent('CiviCRM has detected one record which is a duplicate of existing CiviCRM contact record. These records have not been imported.'));
143 function _addCustomData() {
145 $this->openCiviPage("admin/custom/group", "reset=1");
147 //add new custom data
148 $this->click("//a[@id='newCustomDataGroup']/span");
149 $this->waitForPageToLoad($this->getTimeoutMsec());
151 //fill custom group title
152 $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7);
153 $this->click('title');
154 $this->type('title', $customGroupTitle);
156 //custom group extends
157 $this->click('extends[0]');
158 $this->select('extends[0]', "value=Contact");
159 $this->click("//option[@value='Contact']");
160 $this->click('_qf_Group_next-bottom');
161 $this->waitForElementPresent('_qf_Field_cancel-bottom');
163 //Is custom group created?
164 $this->waitForText('crm-notification-container', $customGroupTitle);
165 $gid = $this->urlArg('gid');
167 // create another custom field - Date
168 $customField = 'Custom field ' . substr(sha1(rand()), 0, 4);
169 $this->type('label', $customField);
171 //enter pre help message
172 $this->type("help_pre", "this is field pre help");
174 //enter post help message
175 $this->type("help_post", "this field post help");
178 $this->click("is_searchable");
181 $this->click('_qf_Field_next-bottom');
182 $this->waitForElementPresent('newCustomField');
184 $this->assertTrue($this->isTextPresent("Custom field '{$customField}' has been saved."));
185 $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField']/../../td[8]/span/a@href"));
186 $customFieldId = $customFieldId[1];
188 return array("custom_{$customFieldId}", $customField, $customGroupTitle);