add missing comments - tests directory
[civicrm-core.git] / tests / phpunit / WebTest / Import / ContactCustomDataTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28 class WebTest_Import_ContactCustomDataTest extends ImportCiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testCustomDataImport() {
35 $this->webtestLogin();
36
37 $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7);
38 // Add a custom group and custom field
39 $customDataParams = $this->_addCustomData();
40
41 // Add New Strict Rule
42 $newRuleTitle = 'IndividualStrict_' . substr(sha1(rand()), 0, 7);
43 $this->openCiviPage("contact/deduperules", "reset=1");
44
45 $this->click("xpath=//div[@id='browseValues_Individual']/div[2]/a/span");
46 $this->waitForElementPresent('_qf_DedupeRules_next-bottom');
47 $this->type('title', $newRuleTitle);
48 $this->click("CIVICRM_QFID_Supervised_used");
49 $this->select("where_0", "label=$customDataParams[1]");
50 $this->type('weight_0', '10');
51 $this->type('threshold', '10');
52 $this->click('_qf_DedupeRules_next-bottom');
53 $this->waitForPageToLoad($this->getTimeoutMsec());
54 $this->waitForText("crm-notification-container", "The rule '{$newRuleTitle}' has been saved.");
55
56 $rgId = explode('&rgid=', $this->getAttribute("xpath=//div[@id='browseValues_Individual']//table/tbody//tr/td[text()='{$newRuleTitle}']/../td[3]/span/a[text()='Use Rule']@href"));
57 $rgId = explode('&', $rgId[1]);
58
59 // Add Contact
60 $firstName2 = 'An_' . substr(sha1(rand()), 0, 7);
61 $this->webtestAddContact($firstName2, "Summerson");
62 $this->waitForPageToLoad($this->getTimeoutMsec());
63
64 // Edit and expand all tabs
65 $this->click('link=Edit');
66 $this->waitForElementPresent('_qf_Contact_cancel');
67 $this->click('link=Expand all tabs');
68
69 // Fill custom data
70 $this->waitForElementPresent("{$customDataParams[0]}_1");
71 $this->type("{$customDataParams[0]}_1", 'This is a test field');
72 $this->click('_qf_Contact_upload_view');
73
74 // Get sample import data.
75 list($headers, $rows) = $this->_individualCustomCSVData($customDataParams, $firstName1);
76
77 // Import and check Individual contacts in Skip mode.
78 $other = array(
79 'saveMapping' => TRUE,
80 'callbackImportSummary' => 'checkDuplicateContacts',
81 'dedupe' => $rgId[0],
82 );
83
84 // Check duplicates
85 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
86
87 // Import without duplicate checking
88 $other = array('saveMapping' => TRUE);
89 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking', array(), $other);
90
91 // Type search name in autocomplete.
92 $this->click('sort_name_navigation');
93 $this->type('css=input#sort_name_navigation', $firstName1);
94 $this->typeKeys('css=input#sort_name_navigation', $firstName1);
95
96 // Wait for result list.
97 $this->waitForElementPresent("css=ul.ui-autocomplete li");
98
99 // Visit contact summary page.
100 $this->click("css=ul.ui-autocomplete li");
101 $this->waitForPageToLoad($this->getTimeoutMsec());
102 $this->assertTrue($this->isTextPresent('This is a test field'));
103 }
104
105 /*
106 * Helper function to provide data for custom data import.
107 */
108 /**
109 * @param $customDataParams
110 * @param $firstName1
111 *
112 * @return array
113 */
114 function _individualCustomCSVData($customDataParams, $firstName1) {
115 $headers = array(
116 'first_name' => 'First Name',
117 'last_name' => 'Last Name',
118 "custom_{$customDataParams[0]}" => "{$customDataParams[1]} :: {$customDataParams[2]}",
119 );
120
121 $rows = array(
122 array('first_name' => $firstName1,
123 'last_name' => 'Anderson',
124 "custom_{$customDataParams[0]}" => 'This is a test field',
125 ),
126 );
127
128 return array($headers, $rows);
129 }
130
131 /**
132 * @param $originalHeaders
133 * @param $originalRows
134 * @param $checkSummary
135 */
136 function checkDuplicateContacts($originalHeaders, $originalRows, $checkSummary) {
137 $this->assertTrue($this->isTextPresent('CiviCRM has detected one record which is a duplicate of existing CiviCRM contact record. These records have not been imported.'));
138 }
139
140 /**
141 * @return array
142 */
143 function _addCustomData() {
144
145 $this->openCiviPage("admin/custom/group", "reset=1");
146
147 //add new custom data
148 $this->click("//a[@id='newCustomDataGroup']/span");
149 $this->waitForPageToLoad($this->getTimeoutMsec());
150
151 //fill custom group title
152 $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7);
153 $this->click('title');
154 $this->type('title', $customGroupTitle);
155
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');
162
163 //Is custom group created?
164 $this->waitForText('crm-notification-container', $customGroupTitle);
165 $gid = $this->urlArg('gid');
166
167 // create another custom field - Date
168 $customField = 'Custom field ' . substr(sha1(rand()), 0, 4);
169 $this->type('label', $customField);
170
171 //enter pre help message
172 $this->type("help_pre", "this is field pre help");
173
174 //enter post help message
175 $this->type("help_post", "this field post help");
176
177 //Is searchable?
178 $this->click("is_searchable");
179
180 // clicking save
181 $this->click('_qf_Field_next-bottom');
182 $this->waitForElementPresent('newCustomField');
183
184 $this->assertTrue($this->isTextPresent("Custom field '{$customField}' has been saved."));
185 $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField']/../../td[8]/span/a@href"));
186 $customFieldId = $customFieldId[1];
187
188 return array("custom_{$customFieldId}", $customField, $customGroupTitle);
189 }
190 }
191