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