Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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 | ||
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 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"); | |
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( | |
124 | array('first_name' => $firstName1, | |
125 | 'last_name' => 'Anderson', | |
126 | "custom_{$customDataParams[0]}" => 'This is a test field', | |
127 | ), | |
128 | ); | |
129 | ||
130 | return array($headers, $rows); | |
131 | } | |
132 | ||
4cbe18b8 EM |
133 | /** |
134 | * @param $originalHeaders | |
135 | * @param $originalRows | |
136 | * @param $checkSummary | |
137 | */ | |
00be9182 | 138 | public function checkDuplicateContacts($originalHeaders, $originalRows, $checkSummary) { |
6a488035 TO |
139 | $this->assertTrue($this->isTextPresent('CiviCRM has detected one record which is a duplicate of existing CiviCRM contact record. These records have not been imported.')); |
140 | } | |
141 | ||
4cbe18b8 EM |
142 | /** |
143 | * @return array | |
144 | */ | |
00be9182 | 145 | public function _addCustomData() { |
42daf119 | 146 | |
071a6d2e | 147 | $this->openCiviPage("admin/custom/group", "reset=1"); |
6a488035 TO |
148 | |
149 | //add new custom data | |
150 | $this->click("//a[@id='newCustomDataGroup']/span"); | |
151 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
152 | ||
153 | //fill custom group title | |
154 | $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7); | |
155 | $this->click('title'); | |
156 | $this->type('title', $customGroupTitle); | |
157 | ||
158 | //custom group extends | |
159 | $this->click('extends[0]'); | |
160 | $this->select('extends[0]', "value=Contact"); | |
161 | $this->click("//option[@value='Contact']"); | |
7df6dc24 | 162 | $this->clickLink('_qf_Group_next-bottom'); |
6a488035 TO |
163 | |
164 | //Is custom group created? | |
a471a3b6 | 165 | $this->waitForText('crm-notification-container', $customGroupTitle); |
22cef1b4 | 166 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); |
a471a3b6 | 167 | $gid = $this->urlArg('gid'); |
6a488035 TO |
168 | |
169 | // create another custom field - Date | |
170 | $customField = 'Custom field ' . substr(sha1(rand()), 0, 4); | |
171 | $this->type('label', $customField); | |
172 | ||
173 | //enter pre help message | |
174 | $this->type("help_pre", "this is field pre help"); | |
175 | ||
176 | //enter post help message | |
177 | $this->type("help_post", "this field post help"); | |
178 | ||
179 | //Is searchable? | |
180 | $this->click("is_searchable"); | |
181 | ||
182 | // clicking save | |
22cef1b4 | 183 | $this->click('_qf_Field_done-bottom'); |
cebea087 | 184 | $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td"); |
6a488035 | 185 | |
22cef1b4 | 186 | $this->waitForText('crm-notification-container', "Custom field '{$customField}' has been saved."); |
6a488035 TO |
187 | $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField']/../../td[8]/span/a@href")); |
188 | $customFieldId = $customFieldId[1]; | |
189 | ||
190 | return array("custom_{$customFieldId}", $customField, $customGroupTitle); | |
191 | } | |
192 | } |