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 TO |
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() { | |
6a488035 TO |
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); | |
071a6d2e | 43 | $this->openCiviPage("contact/deduperules", "reset=1"); |
6a488035 TO |
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); | |
fc2fa8f8 | 48 | $this->click("CIVICRM_QFID_Supervised_used"); |
6a488035 TO |
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()); | |
fc2fa8f8 | 54 | $this->waitForText("crm-notification-container", "The rule '{$newRuleTitle}' has been saved."); |
6a488035 TO |
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. | |
fc2fa8f8 | 97 | $this->waitForElementPresent("css=ul.ui-autocomplete li"); |
6a488035 TO |
98 | |
99 | // Visit contact summary page. | |
fc2fa8f8 | 100 | $this->click("css=ul.ui-autocomplete li"); |
6a488035 TO |
101 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
102 | $this->assertTrue($this->isTextPresent('This is a test field')); | |
103 | } | |
104 | ||
6a488035 TO |
105 | /* |
106 | * Helper function to provide data for custom data import. | |
107 | */ | |
108 | function _individualCustomCSVData($customDataParams, $firstName1) { | |
109 | $headers = array( | |
110 | 'first_name' => 'First Name', | |
111 | 'last_name' => 'Last Name', | |
112 | "custom_{$customDataParams[0]}" => "{$customDataParams[1]} :: {$customDataParams[2]}", | |
113 | ); | |
114 | ||
115 | $rows = array( | |
116 | array('first_name' => $firstName1, | |
117 | 'last_name' => 'Anderson', | |
118 | "custom_{$customDataParams[0]}" => 'This is a test field', | |
119 | ), | |
120 | ); | |
121 | ||
122 | return array($headers, $rows); | |
123 | } | |
124 | ||
125 | function checkDuplicateContacts($originalHeaders, $originalRows, $checkSummary) { | |
126 | $this->assertTrue($this->isTextPresent('CiviCRM has detected one record which is a duplicate of existing CiviCRM contact record. These records have not been imported.')); | |
127 | } | |
128 | ||
129 | function _addCustomData() { | |
42daf119 | 130 | |
071a6d2e | 131 | $this->openCiviPage("admin/custom/group", "reset=1"); |
6a488035 TO |
132 | |
133 | //add new custom data | |
134 | $this->click("//a[@id='newCustomDataGroup']/span"); | |
135 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
136 | ||
137 | //fill custom group title | |
138 | $customGroupTitle = 'Custom ' . substr(sha1(rand()), 0, 7); | |
139 | $this->click('title'); | |
140 | $this->type('title', $customGroupTitle); | |
141 | ||
142 | //custom group extends | |
143 | $this->click('extends[0]'); | |
144 | $this->select('extends[0]', "value=Contact"); | |
145 | $this->click("//option[@value='Contact']"); | |
146 | $this->click('_qf_Group_next-bottom'); | |
147 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
148 | ||
149 | //Is custom group created? | |
a471a3b6 CW |
150 | $this->waitForText('crm-notification-container', $customGroupTitle); |
151 | $gid = $this->urlArg('gid'); | |
6a488035 TO |
152 | |
153 | // create another custom field - Date | |
154 | $customField = 'Custom field ' . substr(sha1(rand()), 0, 4); | |
155 | $this->type('label', $customField); | |
156 | ||
157 | //enter pre help message | |
158 | $this->type("help_pre", "this is field pre help"); | |
159 | ||
160 | //enter post help message | |
161 | $this->type("help_post", "this field post help"); | |
162 | ||
163 | //Is searchable? | |
164 | $this->click("is_searchable"); | |
165 | ||
166 | // clicking save | |
167 | $this->click('_qf_Field_next-bottom'); | |
168 | $this->waitForElementPresent('newCustomField'); | |
169 | ||
fc2fa8f8 | 170 | $this->assertTrue($this->isTextPresent("Custom field '{$customField}' has been saved.")); |
6a488035 TO |
171 | $customFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$customField']/../../td[8]/span/a@href")); |
172 | $customFieldId = $customFieldId[1]; | |
173 | ||
174 | return array("custom_{$customFieldId}", $customField, $customGroupTitle); | |
175 | } | |
176 | } | |
177 |