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