Merge remote-tracking branch 'origin/abtest' into master-abtest
[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 * Function to 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 * Function to 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 * Function to 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 /**
189 * @return array
190 */
191 function _validStreetAddressCSVData() {
192 $headers = array(
193 'first_name' => 'First Name',
194 'middle_name' => 'Middle Name',
195 'last_name' => 'Last Name',
196 'email' => 'Email',
197 'phone' => 'Phone',
198 'street_address' => 'Street Address',
199 'address_1' => 'Supplemental Address 1',
200 'address_2' => 'Supplemental Address 2',
201 'city' => 'City',
202 'state' => 'State',
203 'country' => 'Country',
204 );
205
206 $rows = array(
207 array('first_name' => 'A' . substr(sha1(rand()), 0, 7),
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',
217 'country' => 'United States',
218 ),
219 array('first_name' => 'S' . substr(sha1(rand()), 0, 7),
220 'middle_name' => substr(sha1(rand()), 0, 7),
221 'last_name' => substr(sha1(rand()), 0, 7) . 'sum',
222 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
223 'phone' => '6944412154',
224 'street_address' => '22 Adams Avenue Unit 3c',
225 'address_1' => 'Add 1',
226 'address_2' => 'Add 2',
227 'city' => 'Watson',
228 'state' => 'NY',
229 'country' => 'United States',
230 ),
231 );
232
233 return array($headers, $rows);
234 }
235
236 /*
237 * Helper function to provide csv data with Invalid Street Address.
238 */
239 /**
240 * @return array
241 */
242 function _invalidStreetAddressCSVData() {
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',
250 'address_1' => 'Supplemental Address 1',
251 'address_2' => 'Supplemental Address 2',
252 'city' => 'City',
253 'state' => 'State',
254 'country' => 'Country',
255 );
256
257 $rows = array(
258 array('first_name' => 'A' . substr(sha1(rand()), 0, 7),
259 'middle_name' => substr(sha1(rand()), 0, 7),
260 'last_name' => substr(sha1(rand()), 0, 7) . 'and',
261 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
262 'phone' => '6949912154',
263 'street_address' => 'West St. Apt 1',
264 'address_1' => 'Add 1',
265 'address_2' => 'Add 2',
266 'city' => 'Watson',
267 'state' => 'NY',
268 'country' => 'United States',
269 ),
270 array('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