Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 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 | ||
00be9182 | 38 | public 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 | |
9b873358 | 62 | foreach ($customDataParams['customFields'] as $key => $value) { |
6a488035 | 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 | ||
4cbe18b8 | 68 | /** |
c490a46a CW |
69 | * Helper function to provide data for custom data import. |
70 | * | |
100fef9d CW |
71 | * @param array $customDataParams |
72 | * @param string $firstName1 | |
4cbe18b8 EM |
73 | * |
74 | * @return array | |
75 | */ | |
00be9182 | 76 | public function _individualCustomCSVData($customDataParams, $firstName1) { |
76e86fd8 | 77 | |
6a488035 | 78 | $headers = array( |
c490a46a CW |
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 | ); | |
9b873358 | 87 | foreach ($customDataParams['headers'] as $key => $value) { |
6a488035 TO |
88 | $headers[$key] = $value; |
89 | } | |
76e86fd8 | 90 | |
6c6e6187 | 91 | $rows = array( |
bed98343 | 92 | 0 => array( |
93 | 'first_name' => $firstName1, | |
94 | 'last_name' => 'Anderson', | |
95 | 'address_1' => 'Add 1', | |
96 | 'address_2' => 'Add 2', | |
97 | 'city' => 'Watson', | |
98 | 'state' => 'NY', | |
86797006 | 99 | 'country' => 'UNITED STATES', |
bed98343 | 100 | ), |
c490a46a | 101 | ); |
6a488035 TO |
102 | foreach ($customDataParams['rows'][0] as $key => $values) { |
103 | $rows[0][$key] = $values; | |
104 | } | |
105 | return array($headers, $rows); | |
106 | } | |
76e86fd8 | 107 | |
4cbe18b8 EM |
108 | /** |
109 | * @return array | |
110 | */ | |
00be9182 | 111 | public function _addCustomData() { |
42daf119 | 112 | |
e3ae42f3 | 113 | $this->openCiviPage('admin/custom/group', 'reset=1'); |
6a488035 TO |
114 | |
115 | //add new custom data | |
116 | $this->click("//a[@id='newCustomDataGroup']/span"); | |
117 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
118 | ||
119 | //fill custom group title | |
120 | $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7); | |
121 | $this->click('title'); | |
122 | $this->type('title', $customGroupTitle); | |
123 | ||
124 | //custom group extends | |
125 | $this->click('extends[0]'); | |
126 | $this->select('extends[0]', "value=Address"); | |
127 | $this->click("//option[@value='Address']"); | |
7df6dc24 | 128 | $this->clickLink('_qf_Group_next-bottom'); |
6a488035 TO |
129 | |
130 | //Is custom group created? | |
6c5f7368 | 131 | $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."); |
a471a3b6 | 132 | $gid = $this->urlArg('gid'); |
60f44e0c | 133 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); |
6a488035 TO |
134 | |
135 | // create custom field "alphanumeric text" | |
136 | $customField = 'Custom field ' . substr(sha1(rand()), 0, 4); | |
137 | $this->type('label', $customField); | |
138 | ||
139 | // clicking save | |
60f44e0c | 140 | $this->click('_qf_Field_done-bottom'); |
76e86fd8 | 141 | |
6c6e6187 | 142 | $this->waitForText('crm-notification-container', "Custom field '{$customField}' has been saved."); |
4a058f26 | 143 | $this->assertTrue($this->isTextPresent($customField), 'Missing text: ' . $customField); |
f08c3858 | 144 | $this->waitForAjaxContent(); |
4a058f26 | 145 | $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/div[text()='$customField']/../../td[8]/span/a@href")); |
6a488035 TO |
146 | $customFieldId = $customFieldId[1]; |
147 | ||
148 | // create custom field - Integer | |
149 | $this->click("newCustomField"); | |
60f44e0c | 150 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 TO |
151 | $customField1 = 'Customfield_int ' . substr(sha1(rand()), 0, 4); |
152 | $this->type('label', $customField1); | |
6c6e6187 | 153 | $this->select("data_type[0]", "value=1"); |
6a488035 TO |
154 | |
155 | // clicking save | |
60f44e0c | 156 | $this->click('_qf_Field_done-bottom'); |
6a488035 | 157 | $this->waitForElementPresent('newCustomField'); |
6cbe4dc3 | 158 | $this->waitForText('crm-notification-container', "Custom field '{$customField1}' has been saved."); |
4a058f26 | 159 | $this->assertTrue($this->isTextPresent($customField1), 'Missing text: ' . $customField1); |
f08c3858 | 160 | $this->waitForAjaxContent(); |
4a058f26 | 161 | $customFieldId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/div[text()='$customField1']/../../td[8]/span/a@href")); |
6a488035 TO |
162 | $customFieldId1 = $customFieldId1[1]; |
163 | ||
6a488035 TO |
164 | // create custom field - Number |
165 | $this->click("newCustomField"); | |
60f44e0c | 166 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 TO |
167 | $customField2 = 'Customfield_Number ' . substr(sha1(rand()), 0, 4); |
168 | $this->type('label', $customField2); | |
6c6e6187 | 169 | $this->select("data_type[0]", "value=2"); |
6a488035 TO |
170 | |
171 | // clicking save | |
60f44e0c | 172 | $this->click('_qf_Field_done-bottom'); |
6a488035 | 173 | $this->waitForElementPresent('newCustomField'); |
6cbe4dc3 | 174 | $this->waitForText('crm-notification-container', "Custom field '{$customField2}' has been saved."); |
4a058f26 | 175 | $this->assertTrue($this->isTextPresent($customField2), 'Missing text: ' . $customField2); |
f08c3858 | 176 | $this->waitForAjaxContent(); |
4a058f26 | 177 | $customFieldId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/div[text()='$customField2']/../../td[8]/span/a@href")); |
6a488035 TO |
178 | $customFieldId2 = $customFieldId2[1]; |
179 | ||
180 | // create custom field - "alphanumeric select" | |
181 | $this->click("newCustomField"); | |
60f44e0c | 182 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 | 183 | $customField3 = 'Customfield_alp_select' . substr(sha1(rand()), 0, 4); |
6c6e6187 | 184 | $customFieldId3 = $this->_createMultipleValueCustomField($customField3, 'Select'); |
76e86fd8 | 185 | |
6a488035 TO |
186 | // create custom field - "alphanumeric radio" |
187 | $this->click("newCustomField"); | |
60f44e0c | 188 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 | 189 | $customField4 = 'Customfield_alp_radio' . substr(sha1(rand()), 0, 4); |
6c6e6187 | 190 | $customFieldId4 = $this->_createMultipleValueCustomField($customField4, 'Radio'); |
6a488035 TO |
191 | |
192 | // create custom field - "alphanumeric checkbox" | |
193 | $this->click("newCustomField"); | |
60f44e0c | 194 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 | 195 | $customField5 = 'Customfield_alp_checkbox' . substr(sha1(rand()), 0, 4); |
6c6e6187 | 196 | $customFieldId5 = $this->_createMultipleValueCustomField($customField5, 'CheckBox'); |
6a488035 TO |
197 | |
198 | // create custom field - "alphanumeric multiselect" | |
199 | $this->click("newCustomField"); | |
60f44e0c | 200 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 | 201 | $customField6 = 'Customfield_alp_multiselect' . substr(sha1(rand()), 0, 4); |
6c6e6187 | 202 | $customFieldId6 = $this->_createMultipleValueCustomField($customField6, 'Multi-Select'); |
76e86fd8 | 203 | |
c490a46a | 204 | // create custom field - "alphanumeric advmultiselect" |
6a488035 | 205 | $this->click("newCustomField"); |
60f44e0c | 206 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 | 207 | $customField7 = 'Customfield_alp_advmultiselect' . substr(sha1(rand()), 0, 4); |
6c6e6187 | 208 | $customFieldId7 = $this->_createMultipleValueCustomField($customField7, 'AdvMulti-Select'); |
6a488035 TO |
209 | |
210 | // create custom field - "alphanumeric autocompleteselect" | |
211 | $this->click("newCustomField"); | |
60f44e0c | 212 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 | 213 | $customField8 = 'Customfield_alp_autocompleteselect' . substr(sha1(rand()), 0, 4); |
6c6e6187 | 214 | $customFieldId8 = $this->_createMultipleValueCustomField($customField8, 'Autocomplete-Select'); |
76e86fd8 | 215 | |
6a488035 TO |
216 | // create custom field - Money |
217 | $this->click("newCustomField"); | |
60f44e0c | 218 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 TO |
219 | $customField9 = 'Customfield_Money' . substr(sha1(rand()), 0, 4); |
220 | $this->type('label', $customField9); | |
6c6e6187 | 221 | $this->select("data_type[0]", "value=3"); |
6a488035 TO |
222 | |
223 | // clicking save | |
60f44e0c | 224 | $this->click('_qf_Field_done-bottom'); |
6a488035 | 225 | $this->waitForElementPresent('newCustomField'); |
6cbe4dc3 | 226 | $this->waitForText('crm-notification-container', "Custom field '{$customField9}' has been saved."); |
4a058f26 | 227 | $this->assertTrue($this->isTextPresent($customField9), 'Missing text: ' . $customField9); |
f08c3858 | 228 | $this->waitForAjaxContent(); |
4a058f26 | 229 | $customFieldId9 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/div[text()='$customField9']/../../td[8]/span/a@href")); |
6a488035 TO |
230 | $customFieldId9 = $customFieldId9[1]; |
231 | ||
232 | // create custom field - Date | |
233 | $this->click("newCustomField"); | |
60f44e0c | 234 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 TO |
235 | $customField10 = 'Customfield_Date' . substr(sha1(rand()), 0, 4); |
236 | $this->type('label', $customField10); | |
6c6e6187 TO |
237 | $this->select("data_type[0]", "value=5"); |
238 | $this->select("date_format", "value=yy-mm-dd"); | |
6a488035 TO |
239 | |
240 | // clicking save | |
60f44e0c | 241 | $this->click('_qf_Field_done-bottom'); |
6a488035 | 242 | $this->waitForElementPresent('newCustomField'); |
6cbe4dc3 | 243 | $this->waitForText('crm-notification-container', "Custom field '{$customField10}' has been saved."); |
4a058f26 | 244 | $this->assertTrue($this->isTextPresent($customField9), 'Missing text: ' . $customField9); |
f08c3858 | 245 | $this->waitForAjaxContent(); |
4a058f26 | 246 | $customFieldId10 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/div[text()='$customField10']/../../td[8]/span/a@href")); |
6a488035 TO |
247 | $customFieldId10 = $customFieldId10[1]; |
248 | ||
c490a46a CW |
249 | return array( |
250 | 'headers' => array( | |
251 | "custom_{$customFieldId}" => "$customField :: $customGroupTitle", | |
252 | "custom_{$customFieldId3}" => "$customField3 :: $customGroupTitle", | |
253 | "custom_{$customFieldId4}" => "$customField4 :: $customGroupTitle", | |
254 | "custom_{$customFieldId5}" => "$customField5 :: $customGroupTitle", | |
255 | "custom_{$customFieldId6}" => "$customField6 :: $customGroupTitle", | |
256 | "custom_{$customFieldId7}" => "$customField7 :: $customGroupTitle", | |
257 | "custom_{$customFieldId8}" => "$customField8 :: $customGroupTitle", | |
258 | "custom_{$customFieldId1}" => "$customField1 :: $customGroupTitle", | |
259 | "custom_{$customFieldId2}" => "$customField2 :: $customGroupTitle", | |
260 | "custom_{$customFieldId9}" => "$customField9 :: $customGroupTitle", | |
261 | "custom_{$customFieldId10}" => "$customField10 :: $customGroupTitle", | |
262 | ), | |
263 | 'rows' => array( | |
264 | 0 => array( | |
265 | "custom_{$customFieldId}" => "This is a test field", | |
266 | "custom_{$customFieldId3}" => "label1", | |
267 | "custom_{$customFieldId4}" => "label1", | |
268 | "custom_{$customFieldId5}" => "label1", | |
269 | "custom_{$customFieldId6}" => "label1", | |
270 | "custom_{$customFieldId7}" => "label1", | |
271 | "custom_{$customFieldId8}" => "label1", | |
272 | "custom_{$customFieldId1}" => 1, | |
273 | "custom_{$customFieldId2}" => 12345, | |
274 | "custom_{$customFieldId9}" => 123456, | |
275 | "custom_{$customFieldId10}" => "2009-12-31", | |
276 | ), | |
277 | ), | |
278 | 'customFields' => array( | |
92915c55 | 279 | $customField => 'This is a test field', |
c490a46a CW |
280 | $customField3 => 'label1', |
281 | $customField4 => 'label1', | |
282 | $customField5 => 'label1', | |
283 | $customField6 => 'label1', | |
284 | $customField7 => 'label1', | |
285 | $customField8 => 'label1', | |
286 | $customField1 => '1', | |
287 | $customField2 => '12345', | |
288 | $customField9 => '123,456.00', | |
a9004647 | 289 | //CRM-16068 -- changing assertion to match the date format selected during custom field creation. |
290 | $customField10 => '2009-12-31', | |
c490a46a CW |
291 | ), |
292 | ); | |
6a488035 | 293 | } |
76e86fd8 | 294 | |
4cbe18b8 | 295 | /** |
100fef9d | 296 | * @param string $customFieldName |
4cbe18b8 EM |
297 | * @param $type |
298 | * | |
299 | * @return array | |
300 | */ | |
9b873358 | 301 | public function _createMultipleValueCustomField($customFieldName, $type) { |
6a488035 | 302 | $this->type('label', $customFieldName); |
6c6e6187 | 303 | $this->select("data_type[0]", "value=0"); |
92fcb95f | 304 | $this->select("data_type[1]", "value=" . $type); |
6c6e6187 TO |
305 | $this->type("option_label_1", "label1"); |
306 | $this->type("option_value_1", "label1"); | |
307 | $this->type("option_label_2", "label2"); | |
308 | $this->type("option_value_2", "label2"); | |
76e86fd8 | 309 | |
6a488035 | 310 | // clicking save |
60f44e0c | 311 | $this->click('_qf_Field_done-bottom'); |
6a488035 | 312 | $this->waitForElementPresent('newCustomField'); |
6cbe4dc3 | 313 | $this->waitForText('crm-notification-container', "Custom field '{$customFieldName}' has been saved."); |
4a058f26 | 314 | $this->assertTrue($this->isTextPresent($customFieldName), 'Missing text: ' . $customFieldName); |
f08c3858 | 315 | $this->waitForAjaxContent(); |
4a058f26 | 316 | $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/div[text()='$customFieldName']/../../td[8]/span/a@href")); |
6a488035 TO |
317 | $customFieldId = $customFieldId[1]; |
318 | return $customFieldId; | |
319 | } | |
320 | ||
6a488035 | 321 | } |