Commit | Line | Data |
---|---|---|
6a488035 TO |
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 is the path where our testing install resides. | |
37 | // The rest of URL is defined in CiviSeleniumTestCase base class, in | |
38 | // class attributes. | |
39 | $this->open($this->sboxPath); | |
40 | ||
41 | // Logging in. Remember to wait for page to load. In most cases, | |
42 | // you can rely on 30000 as the value that allows your test to pass, however, | |
43 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
44 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
45 | // page contents loaded and you can continue your test execution. | |
46 | $this->webtestLogin(); | |
47 | ||
48 | $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7); | |
49 | // Add a custom group and custom field | |
50 | $customDataParams = $this->_addCustomData(); | |
51 | ||
52 | // Get sample import data. | |
53 | list($headers, $rows) = $this->_individualCustomCSVData($customDataParams, $firstName1); | |
54 | ||
55 | $this->importContacts($headers, $rows, 'Individual', 'Skip', array()); | |
56 | ||
57 | // Type search name in autocomplete. | |
58 | $this->click('sort_name_navigation'); | |
59 | $this->type('css=input#sort_name_navigation', $firstName1); | |
60 | $this->typeKeys('css=input#sort_name_navigation', $firstName1); | |
61 | ||
62 | // Wait for result list. | |
63 | $this->waitForElementPresent("css=div.ac_results-inner li"); | |
64 | ||
65 | // Visit contact summary page. | |
66 | $this->click("css=div.ac_results-inner li"); | |
67 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
68 | ||
69 | foreach($customDataParams['customFields'] as $key => $value){ | |
70 | $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-summary-row']/div[@class='crm-label'][contains(text(), '$key')]")); | |
71 | $this->assertTrue($this->isTextPresent("$value")); | |
72 | } | |
73 | } | |
74 | ||
75 | ||
76 | /* | |
77 | * Helper function to provide data for custom data import. | |
78 | */ | |
79 | function _individualCustomCSVData($customDataParams, $firstName1) { | |
80 | ||
81 | $headers = array( | |
82 | 'first_name' => 'First Name', | |
83 | 'last_name' => 'Last Name', | |
84 | 'address_1' => 'Additional Address 1', | |
85 | 'address_2' => 'Additional Address 2', | |
86 | 'city' => 'City', | |
87 | 'state' => 'State', | |
88 | 'country' => 'Country', | |
89 | ); | |
90 | foreach( $customDataParams['headers'] as $key =>$value){ | |
91 | $headers[$key] = $value; | |
92 | } | |
93 | ||
94 | $rows = array( 0 => | |
95 | array( | |
96 | 'first_name' => $firstName1, | |
97 | 'last_name' => 'Anderson', | |
98 | 'address_1' => 'Add 1', | |
99 | 'address_2' => 'Add 2', | |
100 | 'city' => 'Watson', | |
101 | 'state' => 'NY', | |
102 | 'country' => 'United States', | |
103 | ), | |
104 | ); | |
105 | foreach ($customDataParams['rows'][0] as $key => $values) { | |
106 | $rows[0][$key] = $values; | |
107 | } | |
108 | return array($headers, $rows); | |
109 | } | |
110 | ||
111 | function _addCustomData() { | |
112 | // Go directly to the URL of the screen that you will be testing (New Custom Group). | |
113 | $this->open($this->sboxPath . "civicrm/admin/custom/group?reset=1"); | |
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']"); | |
128 | $this->click('_qf_Group_next-bottom'); | |
129 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
130 | ||
131 | //Is custom group created? | |
132 | $this->assertTrue($this->isTextPresent("Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.")); | |
133 | $url = explode('gid=', $this->getLocation()); | |
134 | $gid = $url[1]; | |
135 | ||
136 | // create custom field "alphanumeric text" | |
137 | $customField = 'Custom field ' . substr(sha1(rand()), 0, 4); | |
138 | $this->type('label', $customField); | |
139 | ||
140 | // clicking save | |
141 | $this->click('_qf_Field_next-bottom'); | |
142 | $this->waitForElementPresent('newCustomField'); | |
143 | ||
144 | $this->assertTrue($this->isTextPresent("Your custom field '{$customField}' has been saved.")); | |
145 | $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField']/../../td[8]/span/a@href")); | |
146 | $customFieldId = $customFieldId[1]; | |
147 | ||
148 | // create custom field - Integer | |
149 | $this->click("newCustomField"); | |
150 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
151 | $customField1 = 'Customfield_int ' . substr(sha1(rand()), 0, 4); | |
152 | $this->type('label', $customField1); | |
153 | $this->select("data_type[0]","value=1"); | |
154 | ||
155 | // clicking save | |
156 | $this->click('_qf_Field_next-bottom'); | |
157 | $this->waitForElementPresent('newCustomField'); | |
158 | $this->assertTrue($this->isTextPresent("Your custom field '{$customField1}' has been saved.")); | |
159 | $customFieldId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField1']/../../td[8]/span/a@href")); | |
160 | $customFieldId1 = $customFieldId1[1]; | |
161 | ||
162 | ||
163 | // create custom field - Number | |
164 | $this->click("newCustomField"); | |
165 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
166 | $customField2 = 'Customfield_Number ' . substr(sha1(rand()), 0, 4); | |
167 | $this->type('label', $customField2); | |
168 | $this->select("data_type[0]","value=2"); | |
169 | ||
170 | // clicking save | |
171 | $this->click('_qf_Field_next-bottom'); | |
172 | $this->waitForElementPresent('newCustomField'); | |
173 | $this->assertTrue($this->isTextPresent("Your custom field '{$customField2}' has been saved.")); | |
174 | $customFieldId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField2']/../../td[8]/span/a@href")); | |
175 | $customFieldId2 = $customFieldId2[1]; | |
176 | ||
177 | // create custom field - "alphanumeric select" | |
178 | $this->click("newCustomField"); | |
179 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
180 | $customField3 = 'Customfield_alp_select' . substr(sha1(rand()), 0, 4); | |
181 | $customFieldId3 = $this->_createMultipleValueCustomField($customField3,'Select'); | |
182 | ||
183 | // create custom field - "alphanumeric radio" | |
184 | $this->click("newCustomField"); | |
185 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
186 | $customField4 = 'Customfield_alp_radio' . substr(sha1(rand()), 0, 4); | |
187 | $customFieldId4 = $this->_createMultipleValueCustomField($customField4,'Radio'); | |
188 | ||
189 | // create custom field - "alphanumeric checkbox" | |
190 | $this->click("newCustomField"); | |
191 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
192 | $customField5 = 'Customfield_alp_checkbox' . substr(sha1(rand()), 0, 4); | |
193 | $customFieldId5 = $this->_createMultipleValueCustomField($customField5,'CheckBox'); | |
194 | ||
195 | // create custom field - "alphanumeric multiselect" | |
196 | $this->click("newCustomField"); | |
197 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
198 | $customField6 = 'Customfield_alp_multiselect' . substr(sha1(rand()), 0, 4); | |
199 | $customFieldId6 = $this->_createMultipleValueCustomField($customField6,'Multi-Select'); | |
200 | ||
201 | // create custom field - "alphanumeric advmultiselect" | |
202 | $this->click("newCustomField"); | |
203 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
204 | $customField7 = 'Customfield_alp_advmultiselect' . substr(sha1(rand()), 0, 4); | |
205 | $customFieldId7 = $this->_createMultipleValueCustomField($customField7,'AdvMulti-Select'); | |
206 | ||
207 | // create custom field - "alphanumeric autocompleteselect" | |
208 | $this->click("newCustomField"); | |
209 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
210 | $customField8 = 'Customfield_alp_autocompleteselect' . substr(sha1(rand()), 0, 4); | |
211 | $customFieldId8 = $this->_createMultipleValueCustomField($customField8,'Autocomplete-Select'); | |
212 | ||
213 | // create custom field - Money | |
214 | $this->click("newCustomField"); | |
215 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
216 | $customField9 = 'Customfield_Money' . substr(sha1(rand()), 0, 4); | |
217 | $this->type('label', $customField9); | |
218 | $this->select("data_type[0]","value=3"); | |
219 | ||
220 | // clicking save | |
221 | $this->click('_qf_Field_next-bottom'); | |
222 | $this->waitForElementPresent('newCustomField'); | |
223 | $this->assertTrue($this->isTextPresent("Your custom field '{$customField9}' has been saved.")); | |
224 | $customFieldId9 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField9']/../../td[8]/span/a@href")); | |
225 | $customFieldId9 = $customFieldId9[1]; | |
226 | ||
227 | // create custom field - Date | |
228 | $this->click("newCustomField"); | |
229 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
230 | $customField10 = 'Customfield_Date' . substr(sha1(rand()), 0, 4); | |
231 | $this->type('label', $customField10); | |
232 | $this->select("data_type[0]","value=5"); | |
233 | $this->select("date_format","value=yy-mm-dd"); | |
234 | ||
235 | // clicking save | |
236 | $this->click('_qf_Field_next-bottom'); | |
237 | $this->waitForElementPresent('newCustomField'); | |
238 | $this->assertTrue($this->isTextPresent("Your custom field '{$customField10}' has been saved.")); | |
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 | array("custom_{$customFieldId}" => "$customField :: $customGroupTitle", | |
244 | "custom_{$customFieldId3}" => "$customField3 :: $customGroupTitle", | |
245 | "custom_{$customFieldId4}" => "$customField4 :: $customGroupTitle", | |
246 | "custom_{$customFieldId5}" => "$customField5 :: $customGroupTitle", | |
247 | "custom_{$customFieldId6}" => "$customField6 :: $customGroupTitle", | |
248 | "custom_{$customFieldId7}" => "$customField7 :: $customGroupTitle", | |
249 | "custom_{$customFieldId8}" => "$customField8 :: $customGroupTitle", | |
250 | "custom_{$customFieldId1}" => "$customField1 :: $customGroupTitle", | |
251 | "custom_{$customFieldId2}" => "$customField2 :: $customGroupTitle", | |
252 | "custom_{$customFieldId9}" => "$customField9 :: $customGroupTitle", | |
253 | "custom_{$customFieldId10}" => "$customField10 :: $customGroupTitle", | |
254 | ), | |
255 | 'rows' => | |
256 | array( 0 => array("custom_{$customFieldId}" => "This is a test field", | |
257 | "custom_{$customFieldId3}" => "label1", | |
258 | "custom_{$customFieldId4}" => "label1", | |
259 | "custom_{$customFieldId5}" => "label1", | |
260 | "custom_{$customFieldId6}" => "label1", | |
261 | "custom_{$customFieldId7}" => "label1", | |
262 | "custom_{$customFieldId8}" => "label1", | |
263 | "custom_{$customFieldId1}" => 1, | |
264 | "custom_{$customFieldId2}" => 12345, | |
265 | "custom_{$customFieldId9}" => 123456, | |
266 | "custom_{$customFieldId10}" => "2009-12-31", | |
267 | ), | |
268 | ), | |
269 | 'customFields' => array( | |
270 | $customField => 'This is a test field', | |
271 | $customField3 => 'label1', | |
272 | $customField4 => 'label1', | |
273 | $customField5 => 'label1', | |
274 | $customField6 => 'label1', | |
275 | $customField7 => 'label1', | |
276 | $customField8 => 'label1', | |
277 | $customField1 => '1', | |
278 | $customField2 => '12345', | |
279 | $customField9 => '123,456.00', | |
280 | $customField10 => 'December 31st, 2009', | |
281 | ), | |
282 | ); | |
283 | } | |
284 | ||
285 | function _createMultipleValueCustomField( $customFieldName, $type ){ | |
286 | $this->type('label', $customFieldName); | |
287 | $this->select("data_type[0]","value=0"); | |
288 | $this->select("data_type[1]","value=".$type); | |
289 | $this->type("option_label_1","label1"); | |
290 | $this->type("option_value_1","label1"); | |
291 | $this->type("option_label_2","label2"); | |
292 | $this->type("option_value_2","label2"); | |
293 | ||
294 | // clicking save | |
295 | $this->click('_qf_Field_next-bottom'); | |
296 | $this->waitForElementPresent('newCustomField'); | |
297 | $this->assertTrue($this->isTextPresent("Your custom field '{$customFieldName}' has been saved.")); | |
298 | $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customFieldName']/../../td[8]/span/a@href")); | |
299 | $customFieldId = $customFieldId[1]; | |
300 | return $customFieldId; | |
301 | } | |
302 | ||
303 | ||
304 | } | |
305 |