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