3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
30 * Class WebTest_Import_CustomDataTest
32 class WebTest_Import_CustomDataTest
extends ImportCiviSeleniumTestCase
{
34 protected function setUp() {
38 function testCustomDataImport() {
39 $this->webtestLogin();
41 $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7);
42 $firstName2 = 'An_' . substr(sha1(rand()), 0, 7);
43 $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7);
45 $firstName3 = 'Ma' . substr(sha1(rand()), 0, 4);
46 $this->webtestAddContact($firstName3, "Anderson", TRUE);
47 $sortName3 = "$firstName3 Anderson";
48 $id1 = $this->urlArg('cid');
50 $firstName4 = 'Ma' . substr(sha1(rand()), 0, 4);
51 $this->webtestAddContact($firstName4, "Anderson", TRUE);
52 $sortName4 = "$firstName4 Anderson";
53 $id2 = $this->urlArg('cid');
55 // Get sample import data.
56 list($headers, $rows, $customDataVerify) = $this->_individualCustomCSVData($customGroupTitle, $firstName1, $firstName2,
60 // Import and check Individual contacts in Skip mode.
62 'saveMapping' => TRUE,
63 'createGroup' => TRUE,
67 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
70 $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
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());
77 for ($cnt = 0; $cnt < 2; $cnt++
) {
78 foreach ($customDataVerify['rows'][$cnt] as $key => $values) {
79 $rows[$cnt][$key] = $values;
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");
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");
91 // Verify if custom data added
93 foreach ($rows[0] as $key => $value) {
95 $value = date('F jS, Y');
100 $this->assertTrue($this->isTextPresent($value));
106 * Helper function to provide data for custom data import.
109 * @param $customGroupTitle
117 function _individualCustomCSVData($customGroupTitle, $firstName1, $firstName2, $id1, $id2) {
118 list($customDataParams, $customDataVerify) = $this->_addCustomData($customGroupTitle, $id1, $id2);
121 'first_name' => 'First Name',
122 'last_name' => 'Last Name',
126 foreach ($customDataParams['headers'] as $key => $values) {
127 $headers[$key] = $values;
132 'first_name' => $firstName1,
133 'last_name' => 'Anderson',
134 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
137 'first_name' => $firstName2,
138 'last_name' => 'Summerson',
139 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
143 for ($cnt = 0; $cnt < 2; $cnt++
) {
144 foreach ($customDataParams['rows'][$cnt] as $key => $values) {
145 $rows[$cnt][$key] = $values;
149 return array($headers, $rows, $customDataVerify);
153 * @param $customGroupTitle
159 function _addCustomData($customGroupTitle, $id1, $id2) {
161 $this->openCiviPage("admin/custom/group", "reset=1");
163 //add new custom data
164 $this->click("//a[@id='newCustomDataGroup']/span");
165 $this->waitForPageToLoad($this->getTimeoutMsec());
167 //fill custom group title
168 $this->click("title");
169 $this->type("title", $customGroupTitle);
171 //custom group extends
172 $this->click("extends[0]");
173 $this->select("extends[0]", "value=Contact");
174 $this->click("//option[@value='Contact']");
175 $this->click('_qf_Group_next-bottom');
176 $this->waitForElementPresent('newCustomField');
178 //Is custom group created?
179 $this->assertTrue($this->isTextPresent("Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."));
180 $this->click('newCustomField');
181 $this->waitForElementPresent('_qf_Field_cancel-bottom');
182 $url = explode('gid=', $this->getLocation());
185 // create another custom field - Date
186 $dateFieldLabel = 'custom_field_date_' . substr(sha1(rand()), 0, 4);
187 $this->type('label', $dateFieldLabel);
188 $this->click('data_type[0]');
189 $this->select('data_type[0]', "label=Date");
190 $this->waitForElementPresent('start_date_years');
192 // enter years prior to current date
193 $this->type('start_date_years', 3);
195 // enter years upto the end year
196 $this->type('end_date_years', 3);
198 // select the date and time format
199 $this->select('date_format', "value=yy-mm-dd");
200 $this->select('time_format', "value=2");
202 //enter pre help message
203 $this->type("help_pre", "this is field pre help");
205 //enter post help message
206 $this->type("help_post", "this field post help");
209 $this->click("is_searchable");
212 $this->click('_qf_Field_done-bottom');
213 $this->waitForElementPresent('newCustomField');
215 $this->waitForText('crm-notification-container', "Custom field '{$dateFieldLabel}' has been saved.");
217 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$dateFieldLabel']");
218 $dateFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$dateFieldLabel']/../../td[8]/span/a@href"));
219 $dateFieldId = $dateFieldId[1];
221 // create another custom field - Integer Radio
222 $this->click("//a[@id='newCustomField']/span");
223 $this->waitForElementPresent('_qf_Field_cancel-bottom');
224 $this->click("data_type[0]");
225 $this->select("data_type[0]", "value=1");
226 $this->click("//option[@value='1']");
227 $this->click("data_type[1]");
228 $this->select("data_type[1]", "value=Radio");
229 $this->click("//option[@value='Radio']");
231 $radioFieldLabel = 'custom_field_radio' . substr(sha1(rand()), 0, 4);
232 $this->type("label", $radioFieldLabel);
233 $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
234 $this->type("option_label_1", $radioOptionLabel1);
235 $this->type("option_value_1", "1");
236 $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
237 $this->type("option_label_2", $radioOptionLabel2);
238 $this->type("option_value_2", "2");
240 //select options per line
241 $this->type("options_per_line", "3");
244 $this->type("help_pre", "this is field pre help");
246 //enter post help msg
247 $this->type("help_post", "this is field post help");
250 $this->click("is_searchable");
253 $this->click("_qf_Field_done");
254 $this->waitForElementPresent('newCustomField');
256 //Is custom field created
257 $this->waitForText("crm-notification-container", "Custom field '$radioFieldLabel' has been saved.");
258 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$radioFieldLabel']/parent::td/parent::tr/td[8]/span/a");
259 $radioFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$radioFieldLabel']/../../td[8]/span/a@href"));
260 $radioFieldId = $radioFieldId[1];
262 // create another custom field - multiselect
263 $this->click("//a[@id='newCustomField']/span");
264 $this->waitForElementPresent('_qf_Field_cancel-bottom');
265 $multiSelectLabel = 'custom_field_multiSelect_' . substr(sha1(rand()), 0, 4);
266 $this->type('label', $multiSelectLabel);
267 $this->click('data_type[1]');
268 $this->select('data_type[1]', "label=Multi-Select");
269 $this->waitForElementPresent('option_label_1');
271 // enter multiple choice options
272 $multiSelectOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
273 $this->type('option_label_1', $multiSelectOptionLabel1);
274 $this->type('option_value_1', 1);
275 $multiSelectOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
276 $this->type('option_label_2', $multiSelectOptionLabel2);
277 $this->type('option_value_2', 2);
278 $this->click("link=another choice");
279 $multiSelectOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
280 $this->type('option_label_3', $multiSelectOptionLabel3);
281 $this->type('option_value_3', 3);
282 $this->click("link=another choice");
285 $this->type("help_pre", "this is field pre help");
287 //enter post help msg
288 $this->type("help_post", "this is field post help");
291 $this->click("is_searchable");
294 $this->click('_qf_Field_done-bottom');
295 $this->waitForElementPresent('newCustomField');
296 $this->waitForText("crm-notification-container", "Custom field '{$multiSelectLabel}' has been saved.");
297 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$multiSelectLabel']/parent::td/parent::tr/");
298 $multiSelectFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$multiSelectLabel']/parent::td/parent::tr/td[8]/span/a@href"));
299 $multiSelectFieldId = $multiSelectFieldId[1];
301 // create another custom field - contact reference
302 $this->click("//a[@id='newCustomField']/span");
303 $this->waitForElementPresent('_qf_Field_cancel-bottom');
304 $contactReferenceLabel = 'custom_field_contactReference_' . substr(sha1(rand()), 0, 4);
305 $this->type('label', $contactReferenceLabel);
306 $this->click('data_type[0]');
307 $this->select('data_type[0]', "label=Contact Reference");
310 $this->type("help_pre", "this is field pre help");
312 //enter post help msg
313 $this->type("help_post", "this is field post help");
316 $this->click("is_searchable");
319 $this->click('_qf_Field_done-bottom');
320 $this->waitForElementPresent('newCustomField');
322 $this->waitForText("crm-notification-container", "Custom field '{$contactReferenceLabel}' has been saved.");
323 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$contactReferenceLabel']/parent::td/parent::tr/");
324 $contactReferenceFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$contactReferenceLabel']/parent::td/parent::tr/td[8]/span/a@href"));
325 $contactReferenceFieldId = $contactReferenceFieldId[1];
327 $customDataParams = array(
330 "custom_{$dateFieldId}" => "$dateFieldLabel :: $customGroupTitle",
331 "custom_{$radioFieldId}" => "$radioFieldLabel :: $customGroupTitle",
332 "custom_{$multiSelectFieldId}" => "$multiSelectLabel :: $customGroupTitle",
333 "custom_{$contactReferenceFieldId}" => "$contactReferenceLabel :: $customGroupTitle",
336 array(0 => array("custom_{$dateFieldId}" => date('Y-m-d'),
337 "custom_{$radioFieldId}" => '2',
338 "custom_{$multiSelectFieldId}" => '3',
339 "custom_{$contactReferenceFieldId}" => $id1,
341 1 => array("custom_{$dateFieldId}" => date('Y-m-d', mktime(0, 0, 0, 4, 5, date('Y'))),
342 "custom_{$radioFieldId}" => '1',
343 "custom_{$multiSelectFieldId}" => '2',
344 "custom_{$contactReferenceFieldId}" => $id2,
349 $customDataVerify = $customDataParams;
350 $customDataVerify['rows'][0]["custom_{$radioFieldId}"] = $radioOptionLabel2;
351 $customDataVerify['rows'][1]["custom_{$radioFieldId}"] = $radioOptionLabel1;
352 $customDataVerify['rows'][0]["custom_{$multiSelectFieldId}"] = $multiSelectOptionLabel3;
353 $customDataVerify['rows'][1]["custom_{$multiSelectFieldId}"] = $multiSelectOptionLabel2;
355 return array($customDataParams, $customDataVerify);