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_CustomDataTest extends ImportCiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | function testCustomDataImport() { | |
6a488035 TO |
35 | $this->webtestLogin(); |
36 | ||
37 | $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7); | |
38 | $firstName2 = 'An_' . substr(sha1(rand()), 0, 7); | |
39 | $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7); | |
40 | ||
41 | $firstName3 = 'Ma' . substr(sha1(rand()), 0, 4); | |
42 | $this->webtestAddContact($firstName3, "Anderson", TRUE); | |
43 | $sortName3 = "$firstName3 Anderson"; | |
a471a3b6 | 44 | $id1 = $this->urlArg('cid'); |
6a488035 TO |
45 | |
46 | $firstName4 = 'Ma' . substr(sha1(rand()), 0, 4); | |
47 | $this->webtestAddContact($firstName4, "Anderson", TRUE); | |
48 | $sortName4 = "$firstName4 Anderson"; | |
a471a3b6 | 49 | $id2 = $this->urlArg('cid'); |
6a488035 TO |
50 | |
51 | // Get sample import data. | |
52 | list($headers, $rows, $customDataVerify) = $this->_individualCustomCSVData($customGroupTitle, $firstName1, $firstName2, | |
53 | $id1, $id2 | |
54 | ); | |
55 | ||
56 | // Import and check Individual contacts in Skip mode. | |
57 | $other = array( | |
58 | 'saveMapping' => TRUE, | |
59 | 'createGroup' => TRUE, | |
60 | 'createTag' => TRUE, | |
61 | ); | |
62 | ||
63 | $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other); | |
64 | ||
65 | // Find the contact | |
42daf119 | 66 | $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh'); |
6a488035 TO |
67 | $this->type('sort_name', $firstName1); |
68 | $this->click('_qf_Basic_refresh'); | |
69 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
70 | $this->click("xpath=//div[@class='crm-search-results']/table/tbody/tr/td[11]/span/a[text()='View']"); | |
71 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
72 | ||
73 | for ($cnt = 0; $cnt < 2; $cnt++) { | |
74 | foreach ($customDataVerify['rows'][$cnt] as $key => $values) { | |
75 | $rows[$cnt][$key] = $values; | |
76 | } | |
77 | } | |
78 | ||
79 | $CGTableId = preg_replace('/\s/', '_', trim($customGroupTitle)); | |
80 | if ($this->isElementPresent("xpath=//table[@id='{$CGTableId}_0']")) { | |
81 | $this->click("xpath=//table[@id='{$CGTableId}_0']/tbody/tr[@class='columnheader']/td[@class='grouplabel']/a"); | |
82 | } | |
83 | elseif ($this->isElementPresent("xpath=//table[@id='{$CGTableId}_1']")) { | |
84 | $this->click("xpath=//table[@id='{$CGTableId}_1']/tbody/tr[@class='columnheader']/td[@class='grouplabel']/a"); | |
85 | } | |
86 | ||
87 | // Verify if custom data added | |
88 | $cnt = 1; | |
89 | foreach ($rows[0] as $key => $value) { | |
90 | if ($cnt == 4) { | |
91 | $value = date('F jS, Y'); | |
92 | } | |
93 | elseif ($cnt == 7) { | |
94 | $value = $sortName3; | |
95 | } | |
96 | $this->assertTrue($this->isTextPresent($value)); | |
97 | $cnt++; | |
98 | } | |
99 | } | |
100 | ||
101 | /* | |
102 | * Helper function to provide data for custom data import. | |
103 | */ | |
104 | function _individualCustomCSVData($customGroupTitle, $firstName1, $firstName2, $id1, $id2) { | |
105 | list($customDataParams, $customDataVerify) = $this->_addCustomData($customGroupTitle, $id1, $id2); | |
106 | ||
107 | $headers = array( | |
108 | 'first_name' => 'First Name', | |
109 | 'last_name' => 'Last Name', | |
110 | 'email' => 'Email', | |
111 | ); | |
112 | ||
113 | foreach ($customDataParams['headers'] as $key => $values) { | |
114 | $headers[$key] = $values; | |
115 | } | |
116 | ||
117 | $rows = array( | |
118 | array( | |
119 | 'first_name' => $firstName1, | |
120 | 'last_name' => 'Anderson', | |
121 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
122 | ), | |
123 | array( | |
124 | 'first_name' => $firstName2, | |
125 | 'last_name' => 'Summerson', | |
126 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
127 | ), | |
128 | ); | |
129 | ||
130 | for ($cnt = 0; $cnt < 2; $cnt++) { | |
131 | foreach ($customDataParams['rows'][$cnt] as $key => $values) { | |
132 | $rows[$cnt][$key] = $values; | |
133 | } | |
134 | } | |
135 | ||
136 | return array($headers, $rows, $customDataVerify); | |
137 | } | |
138 | ||
139 | function _addCustomData($customGroupTitle, $id1, $id2) { | |
42daf119 | 140 | |
071a6d2e | 141 | $this->openCiviPage("admin/custom/group", "reset=1"); |
6a488035 TO |
142 | |
143 | //add new custom data | |
144 | $this->click("//a[@id='newCustomDataGroup']/span"); | |
145 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
146 | ||
147 | //fill custom group title | |
148 | $this->click("title"); | |
149 | $this->type("title", $customGroupTitle); | |
150 | ||
151 | //custom group extends | |
152 | $this->click("extends[0]"); | |
153 | $this->select("extends[0]", "value=Contact"); | |
154 | $this->click("//option[@value='Contact']"); | |
155 | $this->click('_qf_Group_next-bottom'); | |
156 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
157 | ||
158 | //Is custom group created? | |
159 | $this->assertTrue($this->isTextPresent("Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.")); | |
160 | $url = explode('gid=', $this->getLocation()); | |
161 | $gid = $url[1]; | |
162 | ||
163 | // create another custom field - Date | |
164 | $dateFieldLabel = 'custom_field_date_' . substr(sha1(rand()), 0, 4); | |
165 | $this->type('label', $dateFieldLabel); | |
166 | $this->click('data_type[0]'); | |
167 | $this->select('data_type[0]', "label=Date"); | |
168 | $this->waitForElementPresent('start_date_years'); | |
169 | ||
170 | // enter years prior to current date | |
171 | $this->type('start_date_years', 3); | |
172 | ||
173 | // enter years upto the end year | |
174 | $this->type('end_date_years', 3); | |
175 | ||
176 | // select the date and time format | |
177 | $this->select('date_format', "value=yy-mm-dd"); | |
178 | $this->select('time_format', "value=2"); | |
179 | ||
180 | //enter pre help message | |
181 | $this->type("help_pre", "this is field pre help"); | |
182 | ||
183 | //enter post help message | |
184 | $this->type("help_post", "this field post help"); | |
185 | ||
186 | //Is searchable? | |
187 | $this->click("is_searchable"); | |
188 | ||
189 | // clicking save | |
190 | $this->click('_qf_Field_next-bottom'); | |
191 | $this->waitForElementPresent('newCustomField'); | |
192 | ||
193 | $this->assertTrue($this->isTextPresent("Your custom field '{$dateFieldLabel}' has been saved.")); | |
76e86fd8 | 194 | |
6a488035 TO |
195 | $dateFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$dateFieldLabel']/../../td[8]/span/a@href")); |
196 | $dateFieldId = $dateFieldId[1]; | |
197 | ||
198 | // create another custom field - Integer Radio | |
199 | $this->click("//a[@id='newCustomField']/span"); | |
200 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
201 | $this->click("data_type[0]"); | |
202 | $this->select("data_type[0]", "value=1"); | |
203 | $this->click("//option[@value='1']"); | |
204 | $this->click("data_type[1]"); | |
205 | $this->select("data_type[1]", "value=Radio"); | |
206 | $this->click("//option[@value='Radio']"); | |
207 | ||
208 | $radioFieldLabel = 'custom_field_radio' . substr(sha1(rand()), 0, 4); | |
209 | $this->type("label", $radioFieldLabel); | |
210 | $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5); | |
211 | $this->type("option_label_1", $radioOptionLabel1); | |
212 | $this->type("option_value_1", "1"); | |
213 | $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5); | |
214 | $this->type("option_label_2", $radioOptionLabel2); | |
215 | $this->type("option_value_2", "2"); | |
216 | ||
217 | //select options per line | |
218 | $this->type("options_per_line", "3"); | |
219 | ||
220 | //enter pre help msg | |
221 | $this->type("help_pre", "this is field pre help"); | |
222 | ||
223 | //enter post help msg | |
224 | $this->type("help_post", "this is field post help"); | |
225 | ||
226 | //Is searchable? | |
227 | $this->click("is_searchable"); | |
228 | ||
229 | //clicking save | |
230 | $this->click("_qf_Field_next"); | |
231 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
232 | ||
233 | //Is custom field created | |
234 | $this->assertTrue($this->isTextPresent("Your custom field '$radioFieldLabel' has been saved.")); | |
235 | $radioFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$radioFieldLabel']/../../td[8]/span/a@href")); | |
236 | $radioFieldId = $radioFieldId[1]; | |
237 | ||
238 | // create another custom field - multiselect | |
239 | $this->click("//a[@id='newCustomField']/span"); | |
240 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
241 | $multiSelectLabel = 'custom_field_multiSelect_' . substr(sha1(rand()), 0, 4); | |
242 | $this->type('label', $multiSelectLabel); | |
243 | $this->click('data_type[1]'); | |
244 | $this->select('data_type[1]', "label=Multi-Select"); | |
245 | $this->waitForElementPresent('option_label_1'); | |
246 | ||
247 | // enter multiple choice options | |
248 | $multiSelectOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5); | |
249 | $this->type('option_label_1', $multiSelectOptionLabel1); | |
250 | $this->type('option_value_1', 1); | |
251 | $multiSelectOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5); | |
252 | $this->type('option_label_2', $multiSelectOptionLabel2); | |
253 | $this->type('option_value_2', 2); | |
254 | $this->click("link=another choice"); | |
255 | $multiSelectOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5); | |
256 | $this->type('option_label_3', $multiSelectOptionLabel3); | |
257 | $this->type('option_value_3', 3); | |
258 | $this->click("link=another choice"); | |
259 | ||
260 | //enter pre help msg | |
261 | $this->type("help_pre", "this is field pre help"); | |
262 | ||
263 | //enter post help msg | |
264 | $this->type("help_post", "this is field post help"); | |
265 | ||
266 | //Is searchable? | |
267 | $this->click("is_searchable"); | |
268 | ||
269 | // clicking save | |
270 | $this->click('_qf_Field_next-bottom'); | |
271 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
272 | $this->assertTrue($this->isTextPresent("Your custom field '{$multiSelectLabel}' has been saved.")); | |
273 | $multiSelectFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$multiSelectLabel']/../../td[8]/span/a@href")); | |
274 | $multiSelectFieldId = $multiSelectFieldId[1]; | |
275 | ||
276 | // create another custom field - contact reference | |
277 | $this->click("//a[@id='newCustomField']/span"); | |
278 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
279 | $contactReferenceLabel = 'custom_field_contactReference_' . substr(sha1(rand()), 0, 4); | |
280 | $this->type('label', $contactReferenceLabel); | |
281 | $this->click('data_type[0]'); | |
282 | $this->select('data_type[0]', "label=Contact Reference"); | |
283 | ||
284 | //enter pre help msg | |
285 | $this->type("help_pre", "this is field pre help"); | |
286 | ||
287 | //enter post help msg | |
288 | $this->type("help_post", "this is field post help"); | |
289 | ||
290 | //Is searchable? | |
291 | $this->click("is_searchable"); | |
292 | ||
293 | // clicking save | |
294 | $this->click('_qf_Field_next-bottom'); | |
295 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
296 | ||
297 | $this->assertTrue($this->isTextPresent("Your custom field '{$contactReferenceLabel}' has been saved.")); | |
298 | $contactReferenceFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$contactReferenceLabel']/../../td[8]/span/a@href")); | |
299 | $contactReferenceFieldId = $contactReferenceFieldId[1]; | |
300 | ||
301 | $customDataParams = array( | |
302 | 'headers' => | |
303 | array( | |
304 | "custom_{$dateFieldId}" => "$dateFieldLabel :: $customGroupTitle", | |
305 | "custom_{$radioFieldId}" => "$radioFieldLabel :: $customGroupTitle", | |
306 | "custom_{$multiSelectFieldId}" => "$multiSelectLabel :: $customGroupTitle", | |
307 | "custom_{$contactReferenceFieldId}" => "$contactReferenceLabel :: $customGroupTitle", | |
308 | ), | |
309 | 'rows' => | |
310 | array(0 => array("custom_{$dateFieldId}" => date('Y-m-d'), | |
311 | "custom_{$radioFieldId}" => '2', | |
312 | "custom_{$multiSelectFieldId}" => '3', | |
313 | "custom_{$contactReferenceFieldId}" => $id1, | |
314 | ), | |
315 | 1 => array("custom_{$dateFieldId}" => date('Y-m-d', mktime(0, 0, 0, 4, 5, date('Y'))), | |
316 | "custom_{$radioFieldId}" => '1', | |
317 | "custom_{$multiSelectFieldId}" => '2', | |
318 | "custom_{$contactReferenceFieldId}" => $id2, | |
319 | ), | |
320 | ), | |
321 | ); | |
322 | ||
323 | $customDataVerify = $customDataParams; | |
324 | $customDataVerify['rows'][0]["custom_{$radioFieldId}"] = $radioOptionLabel2; | |
325 | $customDataVerify['rows'][1]["custom_{$radioFieldId}"] = $radioOptionLabel1; | |
326 | $customDataVerify['rows'][0]["custom_{$multiSelectFieldId}"] = $multiSelectOptionLabel3; | |
327 | $customDataVerify['rows'][1]["custom_{$multiSelectFieldId}"] = $multiSelectOptionLabel2; | |
328 | ||
329 | return array($customDataParams, $customDataVerify); | |
330 | } | |
331 | } | |
332 |