Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
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_AddressParsingTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Import_AddressParsingTest extends ImportCiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
071a6d2e | 38 | /** |
eceb18cc | 39 | * Check for Valid Street Address. |
071a6d2e | 40 | */ |
00be9182 | 41 | public function testValidStreetAddressParsing() { |
6a488035 TO |
42 | $this->webtestLogin(); |
43 | ||
44 | //Go to the URL of Address Setting to enable street address parsing option | |
071a6d2e | 45 | $this->openCiviPage("admin/setting/preferences/address", "reset=1"); |
6a488035 TO |
46 | |
47 | //check the street address parsing is already enabled | |
48 | if (!$this->isChecked("address_options[13]")) { | |
49 | $this->click("address_options[13]"); | |
50 | $this->click("_qf_Address_next"); | |
51 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
52 | } | |
53 | ||
54 | // Get sample import data. | |
55 | list($headers, $rows) = $this->_validStreetAddressCSVData(); | |
56 | ||
57 | $this->importContacts($headers, $rows); | |
58 | ||
59 | // Get imported contact Ids | |
60 | $importedContactIds = $this->_getImportedContactIds($rows); | |
61 | ||
62 | //Go to the url of edit contact | |
071a6d2e | 63 | $this->openCiviPage("contact/add", "reset=1&action=update&cid={$importedContactIds[1]}"); |
6a488035 TO |
64 | $this->click("addressBlock"); |
65 | $this->click("//div[@id='addressBlockId']/div[1]"); | |
66 | $this->waitForElementPresent("address_1_street_address"); | |
67 | ||
68 | //Edit Address Elements | |
69 | $this->click("link=Edit Address Elements"); | |
70 | $this->waitForElementPresent("address_1_street_unit"); | |
71 | ||
72 | //verify all the address fields whether parsed correctly | |
73 | $verifyData = array( | |
74 | 'address_1_street_number' => '22', | |
75 | 'address_1_street_name' => 'Adams Avenue', | |
76 | 'address_1_street_unit' => 'Unit 3c', | |
77 | ); | |
78 | foreach ($verifyData as $key => $expectedvalue) { | |
79 | $actualvalue = $this->getValue($key); | |
80 | $this->assertEquals($expectedvalue, $actualvalue); | |
81 | } | |
bf2c3b74 | 82 | $this->clickLink('_qf_Contact_upload_view-top'); |
6a488035 TO |
83 | |
84 | //Go to the URL of Address Setting to disable street address parsing option | |
071a6d2e | 85 | $this->openCiviPage("admin/setting/preferences/address", "reset=1"); |
6a488035 TO |
86 | |
87 | //Disable street address parsing | |
88 | $this->click("address_options[13]"); | |
89 | $this->click("_qf_Address_next"); | |
90 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
91 | } | |
92 | ||
c490a46a | 93 | /** |
eceb18cc | 94 | * Check for Invalid Street Address. |
c490a46a | 95 | */ |
00be9182 | 96 | public function testInvalidStreetAddressParsing() { |
6a488035 TO |
97 | $this->webtestLogin(); |
98 | ||
99 | //Go to the URL of Address Setting to enable street address parsing option | |
071a6d2e | 100 | $this->openCiviPage("admin/setting/preferences/address", "reset=1"); |
6a488035 TO |
101 | |
102 | //check the street address parsing is already enabled | |
103 | if (!$this->isChecked("address_options[13]")) { | |
104 | $this->click("address_options[13]"); | |
105 | $this->click("_qf_Address_next"); | |
106 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
107 | } | |
108 | ||
109 | // Get sample import data. | |
110 | list($headers, $rows) = $this->_invalidStreetAddressCSVData(); | |
111 | ||
112 | $this->importContacts($headers, $rows); | |
113 | $this->assertTrue($this->isTextPresent("Records imported successfully but unable to parse some of the street addresses")); | |
114 | $this->assertTrue($this->isTextPresent("You can Download Street Address Records . You may then edit those contact records and update the street address accordingly.")); | |
115 | ||
116 | // Get imported contact Ids | |
117 | $importedContactIds = $this->_getImportedContactIds($rows); | |
118 | ||
119 | //Go to the url of edit contact | |
071a6d2e | 120 | $this->openCiviPage("contact/add", "reset=1&action=update&cid={$importedContactIds[1]}"); |
6a488035 TO |
121 | $this->click("addressBlock"); |
122 | $this->click("//div[@id='addressBlockId']/div[1]"); | |
123 | $this->waitForElementPresent("address_1_street_address"); | |
124 | ||
125 | //Edit Address Elements | |
126 | $this->click("link=Edit Address Elements"); | |
127 | $this->waitForElementPresent("address_1_street_unit"); | |
128 | ||
129 | //verify all the address fields whether parsed correctly | |
130 | $verifyData = array( | |
131 | 'address_1_street_number' => '', | |
132 | 'address_1_street_name' => '', | |
133 | 'address_1_street_unit' => '', | |
134 | ); | |
135 | foreach ($verifyData as $key => $expectedvalue) { | |
136 | $actualvalue = $this->getValue($key); | |
137 | $this->assertEquals($expectedvalue, $actualvalue); | |
138 | } | |
139 | ||
140 | //Go to the URL of Address Setting to disable street address parsing option | |
071a6d2e | 141 | $this->openCiviPage("admin/setting/preferences/address", "reset=1"); |
6a488035 TO |
142 | |
143 | //Disable street address parsing | |
144 | $this->click("address_options[13]"); | |
145 | $this->click("_qf_Address_next"); | |
146 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
147 | } | |
148 | ||
071a6d2e | 149 | /** |
eceb18cc | 150 | * Check Street Address when Address Parsing is Disabled. |
071a6d2e | 151 | */ |
00be9182 | 152 | public function testStreetAddress() { |
6a488035 TO |
153 | $this->webtestLogin(); |
154 | ||
155 | //Go to the URL of Address Setting to enable street address parsing option | |
071a6d2e | 156 | $this->openCiviPage("admin/setting/preferences/address", "reset=1"); |
6a488035 TO |
157 | |
158 | //check the street address parsing is already disabled | |
159 | if ($this->isChecked("address_options[13]")) { | |
160 | $this->click("address_options[13]"); | |
161 | $this->click("_qf_Address_next"); | |
162 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
163 | } | |
164 | ||
165 | // Get sample import data. | |
166 | list($headers, $rows) = $this->_validStreetAddressCSVData(); | |
167 | ||
168 | $this->importContacts($headers, $rows); | |
169 | ||
170 | // Get imported contact Ids | |
171 | $importedContactIds = $this->_getImportedContactIds($rows); | |
172 | ||
173 | //Go to the url of edit contact | |
071a6d2e | 174 | $this->openCiviPage("contact/add", "reset=1&action=update&cid={$importedContactIds[1]}"); |
6a488035 TO |
175 | $this->click("addressBlock"); |
176 | $this->click("//div[@id='addressBlockId']/div[1]"); | |
177 | $this->waitForElementPresent("address_1_street_address"); | |
178 | ||
179 | //verify the address field | |
180 | $verifyData = array('address_1_street_address' => '22 Adams Avenue Unit 3c'); | |
181 | $actualvalue = $this->getValue('address_1_street_address'); | |
182 | $this->assertEquals('22 Adams Avenue Unit 3c', $actualvalue); | |
183 | } | |
184 | ||
4cbe18b8 | 185 | /** |
c490a46a CW |
186 | * Helper function to provide csv data with Valid Street Address. |
187 | * | |
4cbe18b8 EM |
188 | * @return array |
189 | */ | |
00be9182 | 190 | public function _validStreetAddressCSVData() { |
6a488035 TO |
191 | $headers = array( |
192 | 'first_name' => 'First Name', | |
193 | 'middle_name' => 'Middle Name', | |
194 | 'last_name' => 'Last Name', | |
195 | 'email' => 'Email', | |
196 | 'phone' => 'Phone', | |
197 | 'street_address' => 'Street Address', | |
0e6f669d | 198 | 'address_1' => 'Supplemental Address 1', |
199 | 'address_2' => 'Supplemental Address 2', | |
6a488035 TO |
200 | 'city' => 'City', |
201 | 'state' => 'State', | |
202 | 'country' => 'Country', | |
203 | ); | |
204 | ||
205 | $rows = array( | |
6c6e6187 | 206 | array( |
92915c55 | 207 | 'first_name' => 'A' . substr(sha1(rand()), 0, 7), |
6a488035 TO |
208 | 'middle_name' => substr(sha1(rand()), 0, 7), |
209 | 'last_name' => substr(sha1(rand()), 0, 7) . 'and', | |
210 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
211 | 'phone' => '6949912154', | |
212 | 'street_address' => '54A Excelsior Ave. Apt 1C', | |
213 | 'address_1' => 'Add 1', | |
214 | 'address_2' => 'Add 2', | |
215 | 'city' => 'Watson', | |
216 | 'state' => 'NY', | |
86797006 | 217 | 'country' => 'UNITED STATES', |
6a488035 | 218 | ), |
6c6e6187 | 219 | array( |
92915c55 | 220 | 'first_name' => 'S' . substr(sha1(rand()), 0, 7), |
6a488035 TO |
221 | 'middle_name' => substr(sha1(rand()), 0, 7), |
222 | 'last_name' => substr(sha1(rand()), 0, 7) . 'sum', | |
223 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
224 | 'phone' => '6944412154', | |
225 | 'street_address' => '22 Adams Avenue Unit 3c', | |
226 | 'address_1' => 'Add 1', | |
227 | 'address_2' => 'Add 2', | |
228 | 'city' => 'Watson', | |
229 | 'state' => 'NY', | |
86797006 | 230 | 'country' => 'UNITED STATES', |
6a488035 TO |
231 | ), |
232 | ); | |
233 | ||
234 | return array($headers, $rows); | |
235 | } | |
236 | ||
4cbe18b8 | 237 | /** |
c490a46a CW |
238 | * Helper function to provide csv data with Invalid Street Address. |
239 | * | |
4cbe18b8 EM |
240 | * @return array |
241 | */ | |
00be9182 | 242 | public function _invalidStreetAddressCSVData() { |
6a488035 TO |
243 | $headers = array( |
244 | 'first_name' => 'First Name', | |
245 | 'middle_name' => 'Middle Name', | |
246 | 'last_name' => 'Last Name', | |
247 | 'email' => 'Email', | |
248 | 'phone' => 'Phone', | |
249 | 'street_address' => 'Street Address', | |
0e6f669d | 250 | 'address_1' => 'Supplemental Address 1', |
251 | 'address_2' => 'Supplemental Address 2', | |
6a488035 TO |
252 | 'city' => 'City', |
253 | 'state' => 'State', | |
254 | 'country' => 'Country', | |
255 | ); | |
256 | ||
257 | $rows = array( | |
c490a46a CW |
258 | array( |
259 | 'first_name' => 'A' . substr(sha1(rand()), 0, 7), | |
6a488035 TO |
260 | 'middle_name' => substr(sha1(rand()), 0, 7), |
261 | 'last_name' => substr(sha1(rand()), 0, 7) . 'and', | |
262 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
263 | 'phone' => '6949912154', | |
264 | 'street_address' => 'West St. Apt 1', | |
265 | 'address_1' => 'Add 1', | |
266 | 'address_2' => 'Add 2', | |
267 | 'city' => 'Watson', | |
268 | 'state' => 'NY', | |
86797006 | 269 | 'country' => 'UNITED STATES', |
6a488035 | 270 | ), |
c490a46a CW |
271 | array( |
272 | 'first_name' => 'S' . substr(sha1(rand()), 0, 7), | |
6a488035 TO |
273 | 'middle_name' => substr(sha1(rand()), 0, 7), |
274 | 'last_name' => substr(sha1(rand()), 0, 7) . 'sum', | |
275 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
276 | 'phone' => '6944412154', | |
277 | 'street_address' => 'SW 440N Lincoln Dr S', | |
278 | 'address_1' => 'Add 1', | |
279 | 'address_2' => 'Add 2', | |
280 | 'city' => 'Watson', | |
281 | 'state' => 'NY', | |
86797006 | 282 | 'country' => 'UNITED STATES', |
6a488035 TO |
283 | ), |
284 | ); | |
285 | ||
286 | return array($headers, $rows); | |
287 | } | |
96025800 | 288 | |
6a488035 | 289 | } |