Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | ||
6a488035 | 27 | require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Import_AddressImportTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Import_AddressImportTest extends ImportCiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testCustomAddressDataImport() { | |
6a488035 TO |
39 | $this->webtestLogin(); |
40 | ||
41 | $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7); | |
42 | // Add a custom group and custom field | |
43 | $customDataParams = $this->_addCustomData(); | |
76e86fd8 | 44 | |
6a488035 TO |
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. | |
6cbe4dc3 | 56 | $this->waitForElementPresent("css=ul.ui-autocomplete li"); |
76e86fd8 | 57 | |
6a488035 | 58 | // Visit contact summary page. |
6cbe4dc3 | 59 | $this->click("css=ul.ui-autocomplete li"); |
6a488035 | 60 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
76e86fd8 | 61 | |
6a488035 TO |
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')]")); | |
e3ae42f3 | 64 | $this->assertElementContainsText('address-block-1', "$value"); |
6a488035 TO |
65 | } |
66 | } | |
67 | ||
6a488035 TO |
68 | /* |
69 | * Helper function to provide data for custom data import. | |
70 | */ | |
4cbe18b8 EM |
71 | /** |
72 | * @param $customDataParams | |
73 | * @param $firstName1 | |
74 | * | |
75 | * @return array | |
76 | */ | |
6a488035 | 77 | function _individualCustomCSVData($customDataParams, $firstName1) { |
76e86fd8 | 78 | |
6a488035 TO |
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 | } | |
76e86fd8 CW |
91 | |
92 | $rows = array( 0 => | |
93 | ||
6a488035 TO |
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 | } | |
76e86fd8 | 109 | |
4cbe18b8 EM |
110 | /** |
111 | * @return array | |
112 | */ | |
6a488035 | 113 | function _addCustomData() { |
42daf119 | 114 | |
e3ae42f3 | 115 | $this->openCiviPage('admin/custom/group', 'reset=1'); |
6a488035 TO |
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('_qf_Field_cancel-bottom'); | |
132 | ||
133 | //Is custom group created? | |
6c5f7368 | 134 | $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."); |
a471a3b6 | 135 | $gid = $this->urlArg('gid'); |
6a488035 TO |
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_next-bottom'); | |
143 | $this->waitForElementPresent('newCustomField'); | |
76e86fd8 | 144 | |
6cbe4dc3 | 145 | $this->waitForText('crm-notification-container',"Custom field '{$customField}' has been saved."); |
6a488035 TO |
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"); | |
6cbe4dc3 | 151 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6a488035 TO |
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_next-bottom'); | |
158 | $this->waitForElementPresent('newCustomField'); | |
6cbe4dc3 AS |
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']"); | |
6a488035 TO |
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 | ||
6a488035 TO |
164 | // create custom field - Number |
165 | $this->click("newCustomField"); | |
6cbe4dc3 | 166 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6a488035 TO |
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_next-bottom'); | |
173 | $this->waitForElementPresent('newCustomField'); | |
6cbe4dc3 AS |
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']"); | |
6a488035 TO |
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"); | |
6cbe4dc3 | 181 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6a488035 TO |
182 | $customField3 = 'Customfield_alp_select' . substr(sha1(rand()), 0, 4); |
183 | $customFieldId3 = $this->_createMultipleValueCustomField($customField3,'Select'); | |
76e86fd8 | 184 | |
6a488035 TO |
185 | // create custom field - "alphanumeric radio" |
186 | $this->click("newCustomField"); | |
6cbe4dc3 | 187 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6a488035 TO |
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"); | |
6cbe4dc3 | 193 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6a488035 TO |
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"); | |
6cbe4dc3 | 199 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6a488035 TO |
200 | $customField6 = 'Customfield_alp_multiselect' . substr(sha1(rand()), 0, 4); |
201 | $customFieldId6 = $this->_createMultipleValueCustomField($customField6,'Multi-Select'); | |
76e86fd8 | 202 | |
6a488035 TO |
203 | // create custom field - "alphanumeric advmultiselect" |
204 | $this->click("newCustomField"); | |
6cbe4dc3 | 205 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6a488035 TO |
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"); | |
6cbe4dc3 | 211 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6a488035 TO |
212 | $customField8 = 'Customfield_alp_autocompleteselect' . substr(sha1(rand()), 0, 4); |
213 | $customFieldId8 = $this->_createMultipleValueCustomField($customField8,'Autocomplete-Select'); | |
76e86fd8 | 214 | |
6a488035 TO |
215 | // create custom field - Money |
216 | $this->click("newCustomField"); | |
6cbe4dc3 | 217 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6a488035 TO |
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_next-bottom'); | |
224 | $this->waitForElementPresent('newCustomField'); | |
6cbe4dc3 AS |
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']"); | |
6a488035 TO |
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"); | |
6cbe4dc3 | 232 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6a488035 TO |
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_next-bottom'); | |
240 | $this->waitForElementPresent('newCustomField'); | |
6cbe4dc3 AS |
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']"); | |
6a488035 TO |
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 | ||
76e86fd8 CW |
246 | return array('headers' => |
247 | ||
6a488035 TO |
248 | array("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' => | |
261 | array( 0 => array("custom_{$customFieldId}" => "This is a test field", | |
262 | "custom_{$customFieldId3}" => "label1", | |
263 | "custom_{$customFieldId4}" => "label1", | |
264 | "custom_{$customFieldId5}" => "label1", | |
265 | "custom_{$customFieldId6}" => "label1", | |
266 | "custom_{$customFieldId7}" => "label1", | |
267 | "custom_{$customFieldId8}" => "label1", | |
268 | "custom_{$customFieldId1}" => 1, | |
269 | "custom_{$customFieldId2}" => 12345, | |
270 | "custom_{$customFieldId9}" => 123456, | |
271 | "custom_{$customFieldId10}" => "2009-12-31", | |
272 | ), | |
273 | ), | |
274 | 'customFields' => array( | |
275 | $customField => 'This is a test field', | |
276 | $customField3 => 'label1', | |
277 | $customField4 => 'label1', | |
278 | $customField5 => 'label1', | |
279 | $customField6 => 'label1', | |
280 | $customField7 => 'label1', | |
281 | $customField8 => 'label1', | |
282 | $customField1 => '1', | |
283 | $customField2 => '12345', | |
284 | $customField9 => '123,456.00', | |
285 | $customField10 => 'December 31st, 2009', | |
286 | ), | |
287 | ); | |
288 | } | |
76e86fd8 | 289 | |
4cbe18b8 EM |
290 | /** |
291 | * @param $customFieldName | |
292 | * @param $type | |
293 | * | |
294 | * @return array | |
295 | */ | |
6a488035 TO |
296 | function _createMultipleValueCustomField( $customFieldName, $type ){ |
297 | $this->type('label', $customFieldName); | |
298 | $this->select("data_type[0]","value=0"); | |
299 | $this->select("data_type[1]","value=".$type); | |
300 | $this->type("option_label_1","label1"); | |
301 | $this->type("option_value_1","label1"); | |
302 | $this->type("option_label_2","label2"); | |
303 | $this->type("option_value_2","label2"); | |
76e86fd8 | 304 | |
6a488035 TO |
305 | // clicking save |
306 | $this->click('_qf_Field_next-bottom'); | |
307 | $this->waitForElementPresent('newCustomField'); | |
6cbe4dc3 AS |
308 | $this->waitForText('crm-notification-container', "Custom field '{$customFieldName}' has been saved."); |
309 | $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customFieldName']"); | |
6a488035 TO |
310 | $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customFieldName']/../../td[8]/span/a@href")); |
311 | $customFieldId = $customFieldId[1]; | |
312 | return $customFieldId; | |
313 | } | |
314 | ||
6a488035 TO |
315 | } |
316 |