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