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