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