INFRA-132 - Spaces around "."
[civicrm-core.git] / tests / phpunit / WebTest / Import / AddressImportTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 public 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 * @param array $customDataParams
72 * @param string $firstName1
73 *
74 * @return array
75 */
76 public function _individualCustomCSVData($customDataParams, $firstName1) {
77
78 $headers = array(
79 'first_name' => 'First Name',
80 'last_name' => 'Last Name',
81 'address_1' => 'Additional Address 1',
82 'address_2' => 'Additional Address 2',
83 'city' => 'City',
84 'state' => 'State',
85 'country' => 'Country',
86 );
87 foreach ($customDataParams['headers'] as $key => $value) {
88 $headers[$key] = $value;
89 }
90
91 $rows = array(
92 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 public 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->clickLink('_qf_Group_next-bottom');
131
132 //Is custom group created?
133 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
134 $gid = $this->urlArg('gid');
135 $this->waitForElementPresent('_qf_Field_cancel-bottom');
136
137 // create custom field "alphanumeric text"
138 $customField = 'Custom field ' . substr(sha1(rand()), 0, 4);
139 $this->type('label', $customField);
140
141 // clicking save
142 $this->click('_qf_Field_done-bottom');
143
144 $this->waitForText('crm-notification-container', "Custom field '{$customField}' has been saved.");
145 $this->waitForElementPresent("xpath=//span[text()='$customField']");
146 $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField']/../../td[8]/span/a@href"));
147 $customFieldId = $customFieldId[1];
148
149 // create custom field - Integer
150 $this->click("newCustomField");
151 $this->waitForElementPresent('_qf_Field_done-bottom');
152 $customField1 = 'Customfield_int ' . substr(sha1(rand()), 0, 4);
153 $this->type('label', $customField1);
154 $this->select("data_type[0]", "value=1");
155
156 // clicking save
157 $this->click('_qf_Field_done-bottom');
158 $this->waitForElementPresent('newCustomField');
159 $this->waitForText('crm-notification-container', "Custom field '{$customField1}' has been saved.");
160 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField1']");
161 $customFieldId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField1']/../../td[8]/span/a@href"));
162 $customFieldId1 = $customFieldId1[1];
163
164 // create custom field - Number
165 $this->click("newCustomField");
166 $this->waitForElementPresent('_qf_Field_done-bottom');
167 $customField2 = 'Customfield_Number ' . substr(sha1(rand()), 0, 4);
168 $this->type('label', $customField2);
169 $this->select("data_type[0]", "value=2");
170
171 // clicking save
172 $this->click('_qf_Field_done-bottom');
173 $this->waitForElementPresent('newCustomField');
174 $this->waitForText('crm-notification-container', "Custom field '{$customField2}' has been saved.");
175 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField2']");
176 $customFieldId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField2']/../../td[8]/span/a@href"));
177 $customFieldId2 = $customFieldId2[1];
178
179 // create custom field - "alphanumeric select"
180 $this->click("newCustomField");
181 $this->waitForElementPresent('_qf_Field_done-bottom');
182 $customField3 = 'Customfield_alp_select' . substr(sha1(rand()), 0, 4);
183 $customFieldId3 = $this->_createMultipleValueCustomField($customField3, 'Select');
184
185 // create custom field - "alphanumeric radio"
186 $this->click("newCustomField");
187 $this->waitForElementPresent('_qf_Field_done-bottom');
188 $customField4 = 'Customfield_alp_radio' . substr(sha1(rand()), 0, 4);
189 $customFieldId4 = $this->_createMultipleValueCustomField($customField4, 'Radio');
190
191 // create custom field - "alphanumeric checkbox"
192 $this->click("newCustomField");
193 $this->waitForElementPresent('_qf_Field_done-bottom');
194 $customField5 = 'Customfield_alp_checkbox' . substr(sha1(rand()), 0, 4);
195 $customFieldId5 = $this->_createMultipleValueCustomField($customField5, 'CheckBox');
196
197 // create custom field - "alphanumeric multiselect"
198 $this->click("newCustomField");
199 $this->waitForElementPresent('_qf_Field_done-bottom');
200 $customField6 = 'Customfield_alp_multiselect' . substr(sha1(rand()), 0, 4);
201 $customFieldId6 = $this->_createMultipleValueCustomField($customField6, 'Multi-Select');
202
203 // create custom field - "alphanumeric advmultiselect"
204 $this->click("newCustomField");
205 $this->waitForElementPresent('_qf_Field_done-bottom');
206 $customField7 = 'Customfield_alp_advmultiselect' . substr(sha1(rand()), 0, 4);
207 $customFieldId7 = $this->_createMultipleValueCustomField($customField7, 'AdvMulti-Select');
208
209 // create custom field - "alphanumeric autocompleteselect"
210 $this->click("newCustomField");
211 $this->waitForElementPresent('_qf_Field_done-bottom');
212 $customField8 = 'Customfield_alp_autocompleteselect' . substr(sha1(rand()), 0, 4);
213 $customFieldId8 = $this->_createMultipleValueCustomField($customField8, 'Autocomplete-Select');
214
215 // create custom field - Money
216 $this->click("newCustomField");
217 $this->waitForElementPresent('_qf_Field_done-bottom');
218 $customField9 = 'Customfield_Money' . substr(sha1(rand()), 0, 4);
219 $this->type('label', $customField9);
220 $this->select("data_type[0]", "value=3");
221
222 // clicking save
223 $this->click('_qf_Field_done-bottom');
224 $this->waitForElementPresent('newCustomField');
225 $this->waitForText('crm-notification-container', "Custom field '{$customField9}' has been saved.");
226 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField9']");
227 $customFieldId9 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField9']/../../td[8]/span/a@href"));
228 $customFieldId9 = $customFieldId9[1];
229
230 // create custom field - Date
231 $this->click("newCustomField");
232 $this->waitForElementPresent('_qf_Field_done-bottom');
233 $customField10 = 'Customfield_Date' . substr(sha1(rand()), 0, 4);
234 $this->type('label', $customField10);
235 $this->select("data_type[0]", "value=5");
236 $this->select("date_format", "value=yy-mm-dd");
237
238 // clicking save
239 $this->click('_qf_Field_done-bottom');
240 $this->waitForElementPresent('newCustomField');
241 $this->waitForText('crm-notification-container', "Custom field '{$customField10}' has been saved.");
242 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField10']");
243 $customFieldId10 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField10']/../../td[8]/span/a@href"));
244 $customFieldId10 = $customFieldId10[1];
245
246 return array(
247 'headers' => array(
248 "custom_{$customFieldId}" => "$customField :: $customGroupTitle",
249 "custom_{$customFieldId3}" => "$customField3 :: $customGroupTitle",
250 "custom_{$customFieldId4}" => "$customField4 :: $customGroupTitle",
251 "custom_{$customFieldId5}" => "$customField5 :: $customGroupTitle",
252 "custom_{$customFieldId6}" => "$customField6 :: $customGroupTitle",
253 "custom_{$customFieldId7}" => "$customField7 :: $customGroupTitle",
254 "custom_{$customFieldId8}" => "$customField8 :: $customGroupTitle",
255 "custom_{$customFieldId1}" => "$customField1 :: $customGroupTitle",
256 "custom_{$customFieldId2}" => "$customField2 :: $customGroupTitle",
257 "custom_{$customFieldId9}" => "$customField9 :: $customGroupTitle",
258 "custom_{$customFieldId10}" => "$customField10 :: $customGroupTitle",
259 ),
260 'rows' => array(
261 0 => array(
262 "custom_{$customFieldId}" => "This is a test field",
263 "custom_{$customFieldId3}" => "label1",
264 "custom_{$customFieldId4}" => "label1",
265 "custom_{$customFieldId5}" => "label1",
266 "custom_{$customFieldId6}" => "label1",
267 "custom_{$customFieldId7}" => "label1",
268 "custom_{$customFieldId8}" => "label1",
269 "custom_{$customFieldId1}" => 1,
270 "custom_{$customFieldId2}" => 12345,
271 "custom_{$customFieldId9}" => 123456,
272 "custom_{$customFieldId10}" => "2009-12-31",
273 ),
274 ),
275 'customFields' => array(
276 $customField => 'This is a test field',
277 $customField3 => 'label1',
278 $customField4 => 'label1',
279 $customField5 => 'label1',
280 $customField6 => 'label1',
281 $customField7 => 'label1',
282 $customField8 => 'label1',
283 $customField1 => '1',
284 $customField2 => '12345',
285 $customField9 => '123,456.00',
286 $customField10 => 'December 31st, 2009',
287 ),
288 );
289 }
290
291 /**
292 * @param string $customFieldName
293 * @param $type
294 *
295 * @return array
296 */
297 public function _createMultipleValueCustomField($customFieldName, $type) {
298 $this->type('label', $customFieldName);
299 $this->select("data_type[0]", "value=0");
300 $this->select("data_type[1]", "value=" . $type);
301 $this->type("option_label_1", "label1");
302 $this->type("option_value_1", "label1");
303 $this->type("option_label_2", "label2");
304 $this->type("option_value_2", "label2");
305
306 // clicking save
307 $this->click('_qf_Field_done-bottom');
308 $this->waitForElementPresent('newCustomField');
309 $this->waitForText('crm-notification-container', "Custom field '{$customFieldName}' has been saved.");
310 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customFieldName']");
311 $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customFieldName']/../../td[8]/span/a@href"));
312 $customFieldId = $customFieldId[1];
313 return $customFieldId;
314 }
315
316 }