Start migrating to use clickLink method
[civicrm-core.git] / tests / phpunit / WebTest / Import / ContactCustomDataTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
25 */
26
27
28 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
29 class WebTest_Import_ContactCustomDataTest extends ImportCiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testCustomDataImport() {
36 $this->webtestLogin();
37
38 $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7);
39 // Add a custom group and custom field
40 $customDataParams = $this->_addCustomData();
41
42 // Add New Strict Rule
43 $newRuleTitle = 'IndividualStrict_' . substr(sha1(rand()), 0, 7);
44 $this->openCiviPage("contact/deduperules", "reset=1");
45
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."));
56
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]);
59
60 // Add Contact
61 $firstName2 = 'An_' . substr(sha1(rand()), 0, 7);
62 $this->webtestAddContact($firstName2, "Summerson");
63 $this->waitForPageToLoad($this->getTimeoutMsec());
64
65 // Edit and expand all tabs
66 $this->click('link=Edit');
67 $this->waitForElementPresent('_qf_Contact_cancel');
68 $this->click('link=Expand all tabs');
69
70 // Fill custom data
71 $this->waitForElementPresent("{$customDataParams[0]}_1");
72 $this->type("{$customDataParams[0]}_1", 'This is a test field');
73 $this->click('_qf_Contact_upload_view');
74
75 // Get sample import data.
76 list($headers, $rows) = $this->_individualCustomCSVData($customDataParams, $firstName1);
77
78 // Import and check Individual contacts in Skip mode.
79 $other = array(
80 'saveMapping' => TRUE,
81 'callbackImportSummary' => 'checkDuplicateContacts',
82 'dedupe' => $rgId[0],
83 );
84
85 // Check duplicates
86 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
87
88 // Import without duplicate checking
89 $other = array('saveMapping' => TRUE);
90 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking', array(), $other);
91
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);
96
97 // Wait for result list.
98 $this->waitForElementPresent("css=div.ac_results-inner li");
99
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'));
104 }
105
106
107 /*
108 * Helper function to provide data for custom data import.
109 */
110 function _individualCustomCSVData($customDataParams, $firstName1) {
111 $headers = array(
112 'first_name' => 'First Name',
113 'last_name' => 'Last Name',
114 "custom_{$customDataParams[0]}" => "{$customDataParams[1]} :: {$customDataParams[2]}",
115 );
116
117 $rows = array(
118 array('first_name' => $firstName1,
119 'last_name' => 'Anderson',
120 "custom_{$customDataParams[0]}" => 'This is a test field',
121 ),
122 );
123
124 return array($headers, $rows);
125 }
126
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.'));
129 }
130
131 function _addCustomData() {
132
133 $this->openCiviPage("admin/custom/group", "reset=1");
134
135 //add new custom data
136 $this->click("//a[@id='newCustomDataGroup']/span");
137 $this->waitForPageToLoad($this->getTimeoutMsec());
138
139 //fill custom group title
140 $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7);
141 $this->click('title');
142 $this->type('title', $customGroupTitle);
143
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');
150
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());
154 $gid = $url[1];
155
156 // create another custom field - Date
157 $customField = 'Custom field ' . substr(sha1(rand()), 0, 4);
158 $this->type('label', $customField);
159
160 //enter pre help message
161 $this->type("help_pre", "this is field pre help");
162
163 //enter post help message
164 $this->type("help_post", "this field post help");
165
166 //Is searchable?
167 $this->click("is_searchable");
168
169 // clicking save
170 $this->click('_qf_Field_next-bottom');
171 $this->waitForElementPresent('newCustomField');
172
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];
176
177 return array("custom_{$customFieldId}", $customField, $customGroupTitle);
178 }
179 }
180