3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28 class WebTest_Import_AddressParsingTest
extends ImportCiviSeleniumTestCase
{
30 protected function setUp() {
35 * Function to check for Valid Street Address
37 function testValidStreetAddressParsing() {
38 $this->webtestLogin();
40 //Go to the URL of Address Setting to enable street address parsing option
41 $this->openCiviPage("admin/setting/preferences/address", "reset=1");
43 //check the street address parsing is already enabled
44 if (!$this->isChecked("address_options[13]")) {
45 $this->click("address_options[13]");
46 $this->click("_qf_Address_next");
47 $this->waitForPageToLoad($this->getTimeoutMsec());
50 // Get sample import data.
51 list($headers, $rows) = $this->_validStreetAddressCSVData();
53 $this->importContacts($headers, $rows);
55 // Get imported contact Ids
56 $importedContactIds = $this->_getImportedContactIds($rows);
58 //Go to the url of edit contact
59 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$importedContactIds[1]}");
60 $this->click("addressBlock");
61 $this->click("//div[@id='addressBlockId']/div[1]");
62 $this->waitForElementPresent("address_1_street_address");
64 //Edit Address Elements
65 $this->click("link=Edit Address Elements");
66 $this->waitForElementPresent("address_1_street_unit");
68 //verify all the address fields whether parsed correctly
70 'address_1_street_number' => '22',
71 'address_1_street_name' => 'Adams Avenue',
72 'address_1_street_unit' => 'Unit 3c',
74 foreach ($verifyData as $key => $expectedvalue) {
75 $actualvalue = $this->getValue($key);
76 $this->assertEquals($expectedvalue, $actualvalue);
79 //Go to the URL of Address Setting to disable street address parsing option
80 $this->openCiviPage("admin/setting/preferences/address", "reset=1");
82 //Disable street address parsing
83 $this->click("address_options[13]");
84 $this->click("_qf_Address_next");
85 $this->waitForPageToLoad($this->getTimeoutMsec());
89 * Function to check for Invalid Street Address
91 function testInvalidStreetAddressParsing() {
92 $this->webtestLogin();
94 //Go to the URL of Address Setting to enable street address parsing option
95 $this->openCiviPage("admin/setting/preferences/address", "reset=1");
97 //check the street address parsing is already enabled
98 if (!$this->isChecked("address_options[13]")) {
99 $this->click("address_options[13]");
100 $this->click("_qf_Address_next");
101 $this->waitForPageToLoad($this->getTimeoutMsec());
104 // Get sample import data.
105 list($headers, $rows) = $this->_invalidStreetAddressCSVData();
107 $this->importContacts($headers, $rows);
108 $this->assertTrue($this->isTextPresent("Records imported successfully but unable to parse some of the street addresses"));
109 $this->assertTrue($this->isTextPresent("You can Download Street Address Records . You may then edit those contact records and update the street address accordingly."));
111 // Get imported contact Ids
112 $importedContactIds = $this->_getImportedContactIds($rows);
114 //Go to the url of edit contact
115 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$importedContactIds[1]}");
116 $this->click("addressBlock");
117 $this->click("//div[@id='addressBlockId']/div[1]");
118 $this->waitForElementPresent("address_1_street_address");
120 //Edit Address Elements
121 $this->click("link=Edit Address Elements");
122 $this->waitForElementPresent("address_1_street_unit");
124 //verify all the address fields whether parsed correctly
126 'address_1_street_number' => '',
127 'address_1_street_name' => '',
128 'address_1_street_unit' => '',
130 foreach ($verifyData as $key => $expectedvalue) {
131 $actualvalue = $this->getValue($key);
132 $this->assertEquals($expectedvalue, $actualvalue);
135 //Go to the URL of Address Setting to disable street address parsing option
136 $this->openCiviPage("admin/setting/preferences/address", "reset=1");
138 //Disable street address parsing
139 $this->click("address_options[13]");
140 $this->click("_qf_Address_next");
141 $this->waitForPageToLoad($this->getTimeoutMsec());
145 * Function to check Street Address when Address Parsing is Disabled
147 function testStreetAddress() {
148 $this->webtestLogin();
150 //Go to the URL of Address Setting to enable street address parsing option
151 $this->openCiviPage("admin/setting/preferences/address", "reset=1");
153 //check the street address parsing is already disabled
154 if ($this->isChecked("address_options[13]")) {
155 $this->click("address_options[13]");
156 $this->click("_qf_Address_next");
157 $this->waitForPageToLoad($this->getTimeoutMsec());
160 // Get sample import data.
161 list($headers, $rows) = $this->_validStreetAddressCSVData();
163 $this->importContacts($headers, $rows);
165 // Get imported contact Ids
166 $importedContactIds = $this->_getImportedContactIds($rows);
168 //Go to the url of edit contact
169 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$importedContactIds[1]}");
170 $this->click("addressBlock");
171 $this->click("//div[@id='addressBlockId']/div[1]");
172 $this->waitForElementPresent("address_1_street_address");
174 //verify the address field
175 $verifyData = array('address_1_street_address' => '22 Adams Avenue Unit 3c');
176 $actualvalue = $this->getValue('address_1_street_address');
177 $this->assertEquals('22 Adams Avenue Unit 3c', $actualvalue);
181 * Helper function to provide csv data with Valid Street Address.
183 function _validStreetAddressCSVData() {
185 'first_name' => 'First Name',
186 'middle_name' => 'Middle Name',
187 'last_name' => 'Last Name',
190 'street_address' => 'Street Address',
191 'address_1' => 'Supplemental Address 1',
192 'address_2' => 'Supplemental Address 2',
195 'country' => 'Country',
199 array('first_name' => 'A' . substr(sha1(rand()), 0, 7),
200 'middle_name' => substr(sha1(rand()), 0, 7),
201 'last_name' => substr(sha1(rand()), 0, 7) . 'and',
202 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
203 'phone' => '6949912154',
204 'street_address' => '54A Excelsior Ave. Apt 1C',
205 'address_1' => 'Add 1',
206 'address_2' => 'Add 2',
209 'country' => 'United States',
211 array('first_name' => 'S' . substr(sha1(rand()), 0, 7),
212 'middle_name' => substr(sha1(rand()), 0, 7),
213 'last_name' => substr(sha1(rand()), 0, 7) . 'sum',
214 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
215 'phone' => '6944412154',
216 'street_address' => '22 Adams Avenue Unit 3c',
217 'address_1' => 'Add 1',
218 'address_2' => 'Add 2',
221 'country' => 'United States',
225 return array($headers, $rows);
229 * Helper function to provide csv data with Invalid Street Address.
231 function _invalidStreetAddressCSVData() {
233 'first_name' => 'First Name',
234 'middle_name' => 'Middle Name',
235 'last_name' => 'Last Name',
238 'street_address' => 'Street Address',
239 'address_1' => 'Supplemental Address 1',
240 'address_2' => 'Supplemental Address 2',
243 'country' => 'Country',
247 array('first_name' => 'A' . substr(sha1(rand()), 0, 7),
248 'middle_name' => substr(sha1(rand()), 0, 7),
249 'last_name' => substr(sha1(rand()), 0, 7) . 'and',
250 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
251 'phone' => '6949912154',
252 'street_address' => 'West St. Apt 1',
253 'address_1' => 'Add 1',
254 'address_2' => 'Add 2',
257 'country' => 'United States',
259 array('first_name' => 'S' . substr(sha1(rand()), 0, 7),
260 'middle_name' => substr(sha1(rand()), 0, 7),
261 'last_name' => substr(sha1(rand()), 0, 7) . 'sum',
262 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
263 'phone' => '6944412154',
264 'street_address' => 'SW 440N Lincoln Dr S',
265 'address_1' => 'Add 1',
266 'address_2' => 'Add 2',
269 'country' => 'United States',
273 return array($headers, $rows);