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