98a8e4565edf0a39113c362fb5884db8096d0969
[civicrm-core.git] / tests / phpunit / WebTest / Import / AddressParsingTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
27 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Import_AddressParsingTest
31 */
32 class WebTest_Import_AddressParsingTest extends ImportCiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /**
39 * check for Valid Street Address
40 */
41 function testValidStreetAddressParsing() {
42 $this->webtestLogin();
43
44 //Go to the URL of Address Setting to enable street address parsing option
45 $this->openCiviPage("admin/setting/preferences/address", "reset=1");
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
63 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$importedContactIds[1]}");
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 }
82 $this->clickLink('_qf_Contact_upload_view-top');
83
84 //Go to the URL of Address Setting to disable street address parsing option
85 $this->openCiviPage("admin/setting/preferences/address", "reset=1");
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
93 /**
94 * check for Invalid Street Address
95 */
96 function testInvalidStreetAddressParsing() {
97 $this->webtestLogin();
98
99 //Go to the URL of Address Setting to enable street address parsing option
100 $this->openCiviPage("admin/setting/preferences/address", "reset=1");
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
120 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$importedContactIds[1]}");
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
141 $this->openCiviPage("admin/setting/preferences/address", "reset=1");
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
149 /**
150 * Check Street Address when Address Parsing is Disabled
151 */
152 function testStreetAddress() {
153 $this->webtestLogin();
154
155 //Go to the URL of Address Setting to enable street address parsing option
156 $this->openCiviPage("admin/setting/preferences/address", "reset=1");
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
174 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$importedContactIds[1]}");
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
185 /**
186 * Helper function to provide csv data with Valid Street Address.
187 *
188 * @return array
189 */
190 function _validStreetAddressCSVData() {
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',
198 'address_1' => 'Supplemental Address 1',
199 'address_2' => 'Supplemental Address 2',
200 'city' => 'City',
201 'state' => 'State',
202 'country' => 'Country',
203 );
204
205 $rows = array(
206 array('first_name' => 'A' . substr(sha1(rand()), 0, 7),
207 'middle_name' => substr(sha1(rand()), 0, 7),
208 'last_name' => substr(sha1(rand()), 0, 7) . 'and',
209 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
210 'phone' => '6949912154',
211 'street_address' => '54A Excelsior Ave. Apt 1C',
212 'address_1' => 'Add 1',
213 'address_2' => 'Add 2',
214 'city' => 'Watson',
215 'state' => 'NY',
216 'country' => 'United States',
217 ),
218 array('first_name' => 'S' . substr(sha1(rand()), 0, 7),
219 'middle_name' => substr(sha1(rand()), 0, 7),
220 'last_name' => substr(sha1(rand()), 0, 7) . 'sum',
221 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
222 'phone' => '6944412154',
223 'street_address' => '22 Adams Avenue Unit 3c',
224 'address_1' => 'Add 1',
225 'address_2' => 'Add 2',
226 'city' => 'Watson',
227 'state' => 'NY',
228 'country' => 'United States',
229 ),
230 );
231
232 return array($headers, $rows);
233 }
234
235 /**
236 * Helper function to provide csv data with Invalid Street Address.
237 *
238 * @return array
239 */
240 function _invalidStreetAddressCSVData() {
241 $headers = array(
242 'first_name' => 'First Name',
243 'middle_name' => 'Middle Name',
244 'last_name' => 'Last Name',
245 'email' => 'Email',
246 'phone' => 'Phone',
247 'street_address' => 'Street Address',
248 'address_1' => 'Supplemental Address 1',
249 'address_2' => 'Supplemental Address 2',
250 'city' => 'City',
251 'state' => 'State',
252 'country' => 'Country',
253 );
254
255 $rows = array(
256 array(
257 'first_name' => 'A' . substr(sha1(rand()), 0, 7),
258 'middle_name' => substr(sha1(rand()), 0, 7),
259 'last_name' => substr(sha1(rand()), 0, 7) . 'and',
260 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
261 'phone' => '6949912154',
262 'street_address' => 'West St. Apt 1',
263 'address_1' => 'Add 1',
264 'address_2' => 'Add 2',
265 'city' => 'Watson',
266 'state' => 'NY',
267 'country' => 'United States',
268 ),
269 array(
270 'first_name' => 'S' . substr(sha1(rand()), 0, 7),
271 'middle_name' => substr(sha1(rand()), 0, 7),
272 'last_name' => substr(sha1(rand()), 0, 7) . 'sum',
273 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
274 'phone' => '6944412154',
275 'street_address' => 'SW 440N Lincoln Dr S',
276 'address_1' => 'Add 1',
277 'address_2' => 'Add 2',
278 'city' => 'Watson',
279 'state' => 'NY',
280 'country' => 'United States',
281 ),
282 );
283
284 return array($headers, $rows);
285 }
286 }
287