3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
28 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
29 class WebTest_Import_CustomDataTest
extends ImportCiviSeleniumTestCase
{
31 protected function setUp() {
35 function testCustomDataImport() {
36 $this->webtestLogin();
38 $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7);
39 $firstName2 = 'An_' . substr(sha1(rand()), 0, 7);
40 $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7);
42 $firstName3 = 'Ma' . substr(sha1(rand()), 0, 4);
43 $this->webtestAddContact($firstName3, "Anderson", TRUE);
44 $sortName3 = "$firstName3 Anderson";
45 $this->waitForPageToLoad($this->getTimeoutMsec());
46 $url1 = explode('&cid=', $this->getLocation());
49 $firstName4 = 'Ma' . substr(sha1(rand()), 0, 4);
50 $this->webtestAddContact($firstName4, "Anderson", TRUE);
51 $sortName4 = "$firstName4 Anderson";
52 $this->waitForPageToLoad($this->getTimeoutMsec());
53 $url2 = explode('&cid=', $this->getLocation());
56 // Get sample import data.
57 list($headers, $rows, $customDataVerify) = $this->_individualCustomCSVData($customGroupTitle, $firstName1, $firstName2,
61 // Import and check Individual contacts in Skip mode.
63 'saveMapping' => TRUE,
64 'createGroup' => TRUE,
68 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
71 $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
72 $this->type('sort_name', $firstName1);
73 $this->click('_qf_Basic_refresh');
74 $this->waitForPageToLoad($this->getTimeoutMsec());
75 $this->click("xpath=//div[@class='crm-search-results']/table/tbody/tr/td[11]/span/a[text()='View']");
76 $this->waitForPageToLoad($this->getTimeoutMsec());
78 for ($cnt = 0; $cnt < 2; $cnt++
) {
79 foreach ($customDataVerify['rows'][$cnt] as $key => $values) {
80 $rows[$cnt][$key] = $values;
84 $CGTableId = preg_replace('/\s/', '_', trim($customGroupTitle));
85 if ($this->isElementPresent("xpath=//table[@id='{$CGTableId}_0']")) {
86 $this->click("xpath=//table[@id='{$CGTableId}_0']/tbody/tr[@class='columnheader']/td[@class='grouplabel']/a");
88 elseif ($this->isElementPresent("xpath=//table[@id='{$CGTableId}_1']")) {
89 $this->click("xpath=//table[@id='{$CGTableId}_1']/tbody/tr[@class='columnheader']/td[@class='grouplabel']/a");
92 // Verify if custom data added
94 foreach ($rows[0] as $key => $value) {
96 $value = date('F jS, Y');
101 $this->assertTrue($this->isTextPresent($value));
107 * Helper function to provide data for custom data import.
109 function _individualCustomCSVData($customGroupTitle, $firstName1, $firstName2, $id1, $id2) {
110 list($customDataParams, $customDataVerify) = $this->_addCustomData($customGroupTitle, $id1, $id2);
113 'first_name' => 'First Name',
114 'last_name' => 'Last Name',
118 foreach ($customDataParams['headers'] as $key => $values) {
119 $headers[$key] = $values;
124 'first_name' => $firstName1,
125 'last_name' => 'Anderson',
126 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
129 'first_name' => $firstName2,
130 'last_name' => 'Summerson',
131 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
135 for ($cnt = 0; $cnt < 2; $cnt++
) {
136 foreach ($customDataParams['rows'][$cnt] as $key => $values) {
137 $rows[$cnt][$key] = $values;
141 return array($headers, $rows, $customDataVerify);
144 function _addCustomData($customGroupTitle, $id1, $id2) {
146 $this->openCiviPage("admin/custom/group", "reset=1");
148 //add new custom data
149 $this->click("//a[@id='newCustomDataGroup']/span");
150 $this->waitForPageToLoad($this->getTimeoutMsec());
152 //fill custom group title
153 $this->click("title");
154 $this->type("title", $customGroupTitle);
156 //custom group extends
157 $this->click("extends[0]");
158 $this->select("extends[0]", "value=Contact");
159 $this->click("//option[@value='Contact']");
160 $this->click('_qf_Group_next-bottom');
161 $this->waitForElementPresent('_qf_Field_cancel-bottom');
163 //Is custom group created?
164 $this->assertTrue($this->isTextPresent("Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."));
165 $url = explode('gid=', $this->getLocation());
168 // create another custom field - Date
169 $dateFieldLabel = 'custom_field_date_' . substr(sha1(rand()), 0, 4);
170 $this->type('label', $dateFieldLabel);
171 $this->click('data_type[0]');
172 $this->select('data_type[0]', "label=Date");
173 $this->waitForElementPresent('start_date_years');
175 // enter years prior to current date
176 $this->type('start_date_years', 3);
178 // enter years upto the end year
179 $this->type('end_date_years', 3);
181 // select the date and time format
182 $this->select('date_format', "value=yy-mm-dd");
183 $this->select('time_format', "value=2");
185 //enter pre help message
186 $this->type("help_pre", "this is field pre help");
188 //enter post help message
189 $this->type("help_post", "this field post help");
192 $this->click("is_searchable");
195 $this->click('_qf_Field_next-bottom');
196 $this->waitForElementPresent('newCustomField');
198 $this->assertTrue($this->isTextPresent("Your custom field '{$dateFieldLabel}' has been saved."));
200 $dateFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$dateFieldLabel']/../../td[8]/span/a@href"));
201 $dateFieldId = $dateFieldId[1];
203 // create another custom field - Integer Radio
204 $this->click("//a[@id='newCustomField']/span");
205 $this->waitForPageToLoad($this->getTimeoutMsec());
206 $this->click("data_type[0]");
207 $this->select("data_type[0]", "value=1");
208 $this->click("//option[@value='1']");
209 $this->click("data_type[1]");
210 $this->select("data_type[1]", "value=Radio");
211 $this->click("//option[@value='Radio']");
213 $radioFieldLabel = 'custom_field_radio' . substr(sha1(rand()), 0, 4);
214 $this->type("label", $radioFieldLabel);
215 $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
216 $this->type("option_label_1", $radioOptionLabel1);
217 $this->type("option_value_1", "1");
218 $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
219 $this->type("option_label_2", $radioOptionLabel2);
220 $this->type("option_value_2", "2");
222 //select options per line
223 $this->type("options_per_line", "3");
226 $this->type("help_pre", "this is field pre help");
228 //enter post help msg
229 $this->type("help_post", "this is field post help");
232 $this->click("is_searchable");
235 $this->click("_qf_Field_next");
236 $this->waitForPageToLoad($this->getTimeoutMsec());
238 //Is custom field created
239 $this->assertTrue($this->isTextPresent("Your custom field '$radioFieldLabel' has been saved."));
240 $radioFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$radioFieldLabel']/../../td[8]/span/a@href"));
241 $radioFieldId = $radioFieldId[1];
243 // create another custom field - multiselect
244 $this->click("//a[@id='newCustomField']/span");
245 $this->waitForElementPresent('_qf_Field_cancel-bottom');
246 $multiSelectLabel = 'custom_field_multiSelect_' . substr(sha1(rand()), 0, 4);
247 $this->type('label', $multiSelectLabel);
248 $this->click('data_type[1]');
249 $this->select('data_type[1]', "label=Multi-Select");
250 $this->waitForElementPresent('option_label_1');
252 // enter multiple choice options
253 $multiSelectOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
254 $this->type('option_label_1', $multiSelectOptionLabel1);
255 $this->type('option_value_1', 1);
256 $multiSelectOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
257 $this->type('option_label_2', $multiSelectOptionLabel2);
258 $this->type('option_value_2', 2);
259 $this->click("link=another choice");
260 $multiSelectOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
261 $this->type('option_label_3', $multiSelectOptionLabel3);
262 $this->type('option_value_3', 3);
263 $this->click("link=another choice");
266 $this->type("help_pre", "this is field pre help");
268 //enter post help msg
269 $this->type("help_post", "this is field post help");
272 $this->click("is_searchable");
275 $this->click('_qf_Field_next-bottom');
276 $this->waitForPageToLoad($this->getTimeoutMsec());
277 $this->assertTrue($this->isTextPresent("Your custom field '{$multiSelectLabel}' has been saved."));
278 $multiSelectFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$multiSelectLabel']/../../td[8]/span/a@href"));
279 $multiSelectFieldId = $multiSelectFieldId[1];
281 // create another custom field - contact reference
282 $this->click("//a[@id='newCustomField']/span");
283 $this->waitForElementPresent('_qf_Field_cancel-bottom');
284 $contactReferenceLabel = 'custom_field_contactReference_' . substr(sha1(rand()), 0, 4);
285 $this->type('label', $contactReferenceLabel);
286 $this->click('data_type[0]');
287 $this->select('data_type[0]', "label=Contact Reference");
290 $this->type("help_pre", "this is field pre help");
292 //enter post help msg
293 $this->type("help_post", "this is field post help");
296 $this->click("is_searchable");
299 $this->click('_qf_Field_next-bottom');
300 $this->waitForPageToLoad($this->getTimeoutMsec());
302 $this->assertTrue($this->isTextPresent("Your custom field '{$contactReferenceLabel}' has been saved."));
303 $contactReferenceFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$contactReferenceLabel']/../../td[8]/span/a@href"));
304 $contactReferenceFieldId = $contactReferenceFieldId[1];
306 $customDataParams = array(
309 "custom_{$dateFieldId}" => "$dateFieldLabel :: $customGroupTitle",
310 "custom_{$radioFieldId}" => "$radioFieldLabel :: $customGroupTitle",
311 "custom_{$multiSelectFieldId}" => "$multiSelectLabel :: $customGroupTitle",
312 "custom_{$contactReferenceFieldId}" => "$contactReferenceLabel :: $customGroupTitle",
315 array(0 => array("custom_{$dateFieldId}" => date('Y-m-d'),
316 "custom_{$radioFieldId}" => '2',
317 "custom_{$multiSelectFieldId}" => '3',
318 "custom_{$contactReferenceFieldId}" => $id1,
320 1 => array("custom_{$dateFieldId}" => date('Y-m-d', mktime(0, 0, 0, 4, 5, date('Y'))),
321 "custom_{$radioFieldId}" => '1',
322 "custom_{$multiSelectFieldId}" => '2',
323 "custom_{$contactReferenceFieldId}" => $id2,
328 $customDataVerify = $customDataParams;
329 $customDataVerify['rows'][0]["custom_{$radioFieldId}"] = $radioOptionLabel2;
330 $customDataVerify['rows'][1]["custom_{$radioFieldId}"] = $radioOptionLabel1;
331 $customDataVerify['rows'][0]["custom_{$multiSelectFieldId}"] = $multiSelectOptionLabel3;
332 $customDataVerify['rows'][1]["custom_{$multiSelectFieldId}"] = $multiSelectOptionLabel2;
334 return array($customDataParams, $customDataVerify);