| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.4 | |
| 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 | require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php'; |
| 28 | class WebTest_Import_AddressParsingTest extends ImportCiviSeleniumTestCase { |
| 29 | |
| 30 | protected function setUp() { |
| 31 | parent::setUp(); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Function to check for Valid Street Address |
| 36 | */ |
| 37 | function testValidStreetAddressParsing() { |
| 38 | $this->webtestLogin(); |
| 39 | |
| 40 | //Go to the URL of Address Setting to enable street address parsing option |
| 41 | $this->openCiviPage("admin/setting/preferences/address", "reset=1"); |
| 42 | |
| 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()); |
| 48 | } |
| 49 | |
| 50 | // Get sample import data. |
| 51 | list($headers, $rows) = $this->_validStreetAddressCSVData(); |
| 52 | |
| 53 | $this->importContacts($headers, $rows); |
| 54 | |
| 55 | // Get imported contact Ids |
| 56 | $importedContactIds = $this->_getImportedContactIds($rows); |
| 57 | |
| 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"); |
| 63 | |
| 64 | //Edit Address Elements |
| 65 | $this->click("link=Edit Address Elements"); |
| 66 | $this->waitForElementPresent("address_1_street_unit"); |
| 67 | |
| 68 | //verify all the address fields whether parsed correctly |
| 69 | $verifyData = array( |
| 70 | 'address_1_street_number' => '22', |
| 71 | 'address_1_street_name' => 'Adams Avenue', |
| 72 | 'address_1_street_unit' => 'Unit 3c', |
| 73 | ); |
| 74 | foreach ($verifyData as $key => $expectedvalue) { |
| 75 | $actualvalue = $this->getValue($key); |
| 76 | $this->assertEquals($expectedvalue, $actualvalue); |
| 77 | } |
| 78 | |
| 79 | //Go to the URL of Address Setting to disable street address parsing option |
| 80 | $this->openCiviPage("admin/setting/preferences/address", "reset=1"); |
| 81 | |
| 82 | //Disable street address parsing |
| 83 | $this->click("address_options[13]"); |
| 84 | $this->click("_qf_Address_next"); |
| 85 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Function to check for Invalid Street Address |
| 90 | */ |
| 91 | function testInvalidStreetAddressParsing() { |
| 92 | $this->webtestLogin(); |
| 93 | |
| 94 | //Go to the URL of Address Setting to enable street address parsing option |
| 95 | $this->openCiviPage("admin/setting/preferences/address", "reset=1"); |
| 96 | |
| 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()); |
| 102 | } |
| 103 | |
| 104 | // Get sample import data. |
| 105 | list($headers, $rows) = $this->_invalidStreetAddressCSVData(); |
| 106 | |
| 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.")); |
| 110 | |
| 111 | // Get imported contact Ids |
| 112 | $importedContactIds = $this->_getImportedContactIds($rows); |
| 113 | |
| 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"); |
| 119 | |
| 120 | //Edit Address Elements |
| 121 | $this->click("link=Edit Address Elements"); |
| 122 | $this->waitForElementPresent("address_1_street_unit"); |
| 123 | |
| 124 | //verify all the address fields whether parsed correctly |
| 125 | $verifyData = array( |
| 126 | 'address_1_street_number' => '', |
| 127 | 'address_1_street_name' => '', |
| 128 | 'address_1_street_unit' => '', |
| 129 | ); |
| 130 | foreach ($verifyData as $key => $expectedvalue) { |
| 131 | $actualvalue = $this->getValue($key); |
| 132 | $this->assertEquals($expectedvalue, $actualvalue); |
| 133 | } |
| 134 | |
| 135 | //Go to the URL of Address Setting to disable street address parsing option |
| 136 | $this->openCiviPage("admin/setting/preferences/address", "reset=1"); |
| 137 | |
| 138 | //Disable street address parsing |
| 139 | $this->click("address_options[13]"); |
| 140 | $this->click("_qf_Address_next"); |
| 141 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Function to check Street Address when Address Parsing is Disabled |
| 146 | */ |
| 147 | function testStreetAddress() { |
| 148 | $this->webtestLogin(); |
| 149 | |
| 150 | //Go to the URL of Address Setting to enable street address parsing option |
| 151 | $this->openCiviPage("admin/setting/preferences/address", "reset=1"); |
| 152 | |
| 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()); |
| 158 | } |
| 159 | |
| 160 | // Get sample import data. |
| 161 | list($headers, $rows) = $this->_validStreetAddressCSVData(); |
| 162 | |
| 163 | $this->importContacts($headers, $rows); |
| 164 | |
| 165 | // Get imported contact Ids |
| 166 | $importedContactIds = $this->_getImportedContactIds($rows); |
| 167 | |
| 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"); |
| 173 | |
| 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); |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Helper function to provide csv data with Valid Street Address. |
| 182 | */ |
| 183 | function _validStreetAddressCSVData() { |
| 184 | $headers = array( |
| 185 | 'first_name' => 'First Name', |
| 186 | 'middle_name' => 'Middle Name', |
| 187 | 'last_name' => 'Last Name', |
| 188 | 'email' => 'Email', |
| 189 | 'phone' => 'Phone', |
| 190 | 'street_address' => 'Street Address', |
| 191 | 'address_1' => 'Supplemental Address 1', |
| 192 | 'address_2' => 'Supplemental Address 2', |
| 193 | 'city' => 'City', |
| 194 | 'state' => 'State', |
| 195 | 'country' => 'Country', |
| 196 | ); |
| 197 | |
| 198 | $rows = array( |
| 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', |
| 207 | 'city' => 'Watson', |
| 208 | 'state' => 'NY', |
| 209 | 'country' => 'United States', |
| 210 | ), |
| 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', |
| 219 | 'city' => 'Watson', |
| 220 | 'state' => 'NY', |
| 221 | 'country' => 'United States', |
| 222 | ), |
| 223 | ); |
| 224 | |
| 225 | return array($headers, $rows); |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | * Helper function to provide csv data with Invalid Street Address. |
| 230 | */ |
| 231 | function _invalidStreetAddressCSVData() { |
| 232 | $headers = array( |
| 233 | 'first_name' => 'First Name', |
| 234 | 'middle_name' => 'Middle Name', |
| 235 | 'last_name' => 'Last Name', |
| 236 | 'email' => 'Email', |
| 237 | 'phone' => 'Phone', |
| 238 | 'street_address' => 'Street Address', |
| 239 | 'address_1' => 'Supplemental Address 1', |
| 240 | 'address_2' => 'Supplemental Address 2', |
| 241 | 'city' => 'City', |
| 242 | 'state' => 'State', |
| 243 | 'country' => 'Country', |
| 244 | ); |
| 245 | |
| 246 | $rows = array( |
| 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', |
| 255 | 'city' => 'Watson', |
| 256 | 'state' => 'NY', |
| 257 | 'country' => 'United States', |
| 258 | ), |
| 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', |
| 267 | 'city' => 'Watson', |
| 268 | 'state' => 'NY', |
| 269 | 'country' => 'United States', |
| 270 | ), |
| 271 | ); |
| 272 | |
| 273 | return array($headers, $rows); |
| 274 | } |
| 275 | } |
| 276 | |