Merge remote-tracking branch 'origin/4.4' into 4.4-4.5-2014-09-14-13-58-42
[civicrm-core.git] / tests / phpunit / WebTest / Import / AddressImportTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Import_AddressImportTest
31 */
32 class WebTest_Import_AddressImportTest extends ImportCiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testCustomAddressDataImport() {
39 $this->webtestLogin();
40
41 $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7);
42 // Add a custom group and custom field
43 $customDataParams = $this->_addCustomData();
44
45 // Get sample import data.
46 list($headers, $rows) = $this->_individualCustomCSVData($customDataParams, $firstName1);
47
48 $this->importContacts($headers, $rows, 'Individual', 'Skip', array());
49
50 // Type search name in autocomplete.
51 $this->click('sort_name_navigation');
52 $this->type('css=input#sort_name_navigation', $firstName1);
53 $this->typeKeys('css=input#sort_name_navigation', $firstName1);
54
55 // Wait for result list.
56 $this->waitForElementPresent("css=ul.ui-autocomplete li");
57
58 // Visit contact summary page.
59 $this->click("css=ul.ui-autocomplete li");
60 $this->waitForPageToLoad($this->getTimeoutMsec());
61
62 foreach($customDataParams['customFields'] as $key => $value){
63 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-summary-row']/div[@class='crm-label'][contains(text(), '$key')]"));
64 $this->assertElementContainsText('address-block-1', "$value");
65 }
66 }
67
68 /*
69 * Helper function to provide data for custom data import.
70 */
71 /**
72 * @param $customDataParams
73 * @param $firstName1
74 *
75 * @return array
76 */
77 function _individualCustomCSVData($customDataParams, $firstName1) {
78
79 $headers = array(
80 'first_name' => 'First Name',
81 'last_name' => 'Last Name',
82 'address_1' => 'Additional Address 1',
83 'address_2' => 'Additional Address 2',
84 'city' => 'City',
85 'state' => 'State',
86 'country' => 'Country',
87 );
88 foreach( $customDataParams['headers'] as $key =>$value){
89 $headers[$key] = $value;
90 }
91
92 $rows = array( 0 =>
93
94 array(
95 'first_name' => $firstName1,
96 'last_name' => 'Anderson',
97 'address_1' => 'Add 1',
98 'address_2' => 'Add 2',
99 'city' => 'Watson',
100 'state' => 'NY',
101 'country' => 'United States',
102 ),
103 );
104 foreach ($customDataParams['rows'][0] as $key => $values) {
105 $rows[0][$key] = $values;
106 }
107 return array($headers, $rows);
108 }
109
110 /**
111 * @return array
112 */
113 function _addCustomData() {
114
115 $this->openCiviPage('admin/custom/group', 'reset=1');
116
117 //add new custom data
118 $this->click("//a[@id='newCustomDataGroup']/span");
119 $this->waitForPageToLoad($this->getTimeoutMsec());
120
121 //fill custom group title
122 $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7);
123 $this->click('title');
124 $this->type('title', $customGroupTitle);
125
126 //custom group extends
127 $this->click('extends[0]');
128 $this->select('extends[0]', "value=Address");
129 $this->click("//option[@value='Address']");
130 $this->click('_qf_Group_next-bottom');
131 $this->waitForElementPresent('newCustomField');
132
133 //Is custom group created?
134 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
135 $gid = $this->urlArg('gid');
136 $this->click('newCustomField');
137 $this->waitForElementPresent('_qf_Field_cancel-bottom');
138
139 // create custom field "alphanumeric text"
140 $customField = 'Custom field ' . substr(sha1(rand()), 0, 4);
141 $this->type('label', $customField);
142
143 // clicking save
144 $this->click('_qf_Field_done-bottom');
145
146 $this->waitForText('crm-notification-container',"Custom field '{$customField}' has been saved.");
147 $this->waitForElementPresent("xpath=//span[text()='$customField']");
148 $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField']/../../td[8]/span/a@href"));
149 $customFieldId = $customFieldId[1];
150
151 // create custom field - Integer
152 $this->click("newCustomField");
153 $this->waitForElementPresent('_qf_Field_done-bottom');
154 $customField1 = 'Customfield_int ' . substr(sha1(rand()), 0, 4);
155 $this->type('label', $customField1);
156 $this->select("data_type[0]","value=1");
157
158 // clicking save
159 $this->click('_qf_Field_done-bottom');
160 $this->waitForElementPresent('newCustomField');
161 $this->waitForText('crm-notification-container', "Custom field '{$customField1}' has been saved.");
162 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField1']");
163 $customFieldId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField1']/../../td[8]/span/a@href"));
164 $customFieldId1 = $customFieldId1[1];
165
166 // create custom field - Number
167 $this->click("newCustomField");
168 $this->waitForElementPresent('_qf_Field_done-bottom');
169 $customField2 = 'Customfield_Number ' . substr(sha1(rand()), 0, 4);
170 $this->type('label', $customField2);
171 $this->select("data_type[0]","value=2");
172
173 // clicking save
174 $this->click('_qf_Field_done-bottom');
175 $this->waitForElementPresent('newCustomField');
176 $this->waitForText('crm-notification-container', "Custom field '{$customField2}' has been saved.");
177 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField2']");
178 $customFieldId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField2']/../../td[8]/span/a@href"));
179 $customFieldId2 = $customFieldId2[1];
180
181 // create custom field - "alphanumeric select"
182 $this->click("newCustomField");
183 $this->waitForElementPresent('_qf_Field_done-bottom');
184 $customField3 = 'Customfield_alp_select' . substr(sha1(rand()), 0, 4);
185 $customFieldId3 = $this->_createMultipleValueCustomField($customField3,'Select');
186
187 // create custom field - "alphanumeric radio"
188 $this->click("newCustomField");
189 $this->waitForElementPresent('_qf_Field_done-bottom');
190 $customField4 = 'Customfield_alp_radio' . substr(sha1(rand()), 0, 4);
191 $customFieldId4 = $this->_createMultipleValueCustomField($customField4,'Radio');
192
193 // create custom field - "alphanumeric checkbox"
194 $this->click("newCustomField");
195 $this->waitForElementPresent('_qf_Field_done-bottom');
196 $customField5 = 'Customfield_alp_checkbox' . substr(sha1(rand()), 0, 4);
197 $customFieldId5 = $this->_createMultipleValueCustomField($customField5,'CheckBox');
198
199 // create custom field - "alphanumeric multiselect"
200 $this->click("newCustomField");
201 $this->waitForElementPresent('_qf_Field_done-bottom');
202 $customField6 = 'Customfield_alp_multiselect' . substr(sha1(rand()), 0, 4);
203 $customFieldId6 = $this->_createMultipleValueCustomField($customField6,'Multi-Select');
204
205 // create custom field - "alphanumeric advmultiselect"
206 $this->click("newCustomField");
207 $this->waitForElementPresent('_qf_Field_done-bottom');
208 $customField7 = 'Customfield_alp_advmultiselect' . substr(sha1(rand()), 0, 4);
209 $customFieldId7 = $this->_createMultipleValueCustomField($customField7,'AdvMulti-Select');
210
211 // create custom field - "alphanumeric autocompleteselect"
212 $this->click("newCustomField");
213 $this->waitForElementPresent('_qf_Field_done-bottom');
214 $customField8 = 'Customfield_alp_autocompleteselect' . substr(sha1(rand()), 0, 4);
215 $customFieldId8 = $this->_createMultipleValueCustomField($customField8,'Autocomplete-Select');
216
217 // create custom field - Money
218 $this->click("newCustomField");
219 $this->waitForElementPresent('_qf_Field_done-bottom');
220 $customField9 = 'Customfield_Money' . substr(sha1(rand()), 0, 4);
221 $this->type('label', $customField9);
222 $this->select("data_type[0]","value=3");
223
224 // clicking save
225 $this->click('_qf_Field_done-bottom');
226 $this->waitForElementPresent('newCustomField');
227 $this->waitForText('crm-notification-container', "Custom field '{$customField9}' has been saved.");
228 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField9']");
229 $customFieldId9 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField9']/../../td[8]/span/a@href"));
230 $customFieldId9 = $customFieldId9[1];
231
232 // create custom field - Date
233 $this->click("newCustomField");
234 $this->waitForElementPresent('_qf_Field_done-bottom');
235 $customField10 = 'Customfield_Date' . substr(sha1(rand()), 0, 4);
236 $this->type('label', $customField10);
237 $this->select("data_type[0]","value=5");
238 $this->select("date_format","value=yy-mm-dd");
239
240 // clicking save
241 $this->click('_qf_Field_done-bottom');
242 $this->waitForElementPresent('newCustomField');
243 $this->waitForText('crm-notification-container', "Custom field '{$customField10}' has been saved.");
244 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField10']");
245 $customFieldId10 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField10']/../../td[8]/span/a@href"));
246 $customFieldId10 = $customFieldId10[1];
247
248 return array('headers' =>
249
250 array("custom_{$customFieldId}" => "$customField :: $customGroupTitle",
251 "custom_{$customFieldId3}" => "$customField3 :: $customGroupTitle",
252 "custom_{$customFieldId4}" => "$customField4 :: $customGroupTitle",
253 "custom_{$customFieldId5}" => "$customField5 :: $customGroupTitle",
254 "custom_{$customFieldId6}" => "$customField6 :: $customGroupTitle",
255 "custom_{$customFieldId7}" => "$customField7 :: $customGroupTitle",
256 "custom_{$customFieldId8}" => "$customField8 :: $customGroupTitle",
257 "custom_{$customFieldId1}" => "$customField1 :: $customGroupTitle",
258 "custom_{$customFieldId2}" => "$customField2 :: $customGroupTitle",
259 "custom_{$customFieldId9}" => "$customField9 :: $customGroupTitle",
260 "custom_{$customFieldId10}" => "$customField10 :: $customGroupTitle",
261 ),
262 'rows' =>
263 array( 0 => array("custom_{$customFieldId}" => "This is a test field",
264 "custom_{$customFieldId3}" => "label1",
265 "custom_{$customFieldId4}" => "label1",
266 "custom_{$customFieldId5}" => "label1",
267 "custom_{$customFieldId6}" => "label1",
268 "custom_{$customFieldId7}" => "label1",
269 "custom_{$customFieldId8}" => "label1",
270 "custom_{$customFieldId1}" => 1,
271 "custom_{$customFieldId2}" => 12345,
272 "custom_{$customFieldId9}" => 123456,
273 "custom_{$customFieldId10}" => "2009-12-31",
274 ),
275 ),
276 'customFields' => array(
277 $customField => 'This is a test field',
278 $customField3 => 'label1',
279 $customField4 => 'label1',
280 $customField5 => 'label1',
281 $customField6 => 'label1',
282 $customField7 => 'label1',
283 $customField8 => 'label1',
284 $customField1 => '1',
285 $customField2 => '12345',
286 $customField9 => '123,456.00',
287 $customField10 => 'December 31st, 2009',
288 ),
289 );
290 }
291
292 /**
293 * @param $customFieldName
294 * @param $type
295 *
296 * @return array
297 */
298 function _createMultipleValueCustomField( $customFieldName, $type ){
299 $this->type('label', $customFieldName);
300 $this->select("data_type[0]","value=0");
301 $this->select("data_type[1]","value=".$type);
302 $this->type("option_label_1","label1");
303 $this->type("option_value_1","label1");
304 $this->type("option_label_2","label2");
305 $this->type("option_value_2","label2");
306
307 // clicking save
308 $this->click('_qf_Field_done-bottom');
309 $this->waitForElementPresent('newCustomField');
310 $this->waitForText('crm-notification-container', "Custom field '{$customFieldName}' has been saved.");
311 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customFieldName']");
312 $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customFieldName']/../../td[8]/span/a@href"));
313 $customFieldId = $customFieldId[1];
314 return $customFieldId;
315 }
316
317 }
318