| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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 | public 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 | public 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 | public 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 | public 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( |
| 207 | '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( |
| 220 | 'first_name' => 'S' . substr(sha1(rand()), 0, 7), |
| 221 | 'middle_name' => substr(sha1(rand()), 0, 7), |
| 222 | 'last_name' => substr(sha1(rand()), 0, 7) . 'sum', |
| 223 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', |
| 224 | 'phone' => '6944412154', |
| 225 | 'street_address' => '22 Adams Avenue Unit 3c', |
| 226 | 'address_1' => 'Add 1', |
| 227 | 'address_2' => 'Add 2', |
| 228 | 'city' => 'Watson', |
| 229 | 'state' => 'NY', |
| 230 | 'country' => 'UNITED STATES', |
| 231 | ), |
| 232 | ); |
| 233 | |
| 234 | return array($headers, $rows); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Helper function to provide csv data with Invalid Street Address. |
| 239 | * |
| 240 | * @return array |
| 241 | */ |
| 242 | public 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( |
| 259 | 'first_name' => 'A' . substr(sha1(rand()), 0, 7), |
| 260 | 'middle_name' => substr(sha1(rand()), 0, 7), |
| 261 | 'last_name' => substr(sha1(rand()), 0, 7) . 'and', |
| 262 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', |
| 263 | 'phone' => '6949912154', |
| 264 | 'street_address' => 'West St. Apt 1', |
| 265 | 'address_1' => 'Add 1', |
| 266 | 'address_2' => 'Add 2', |
| 267 | 'city' => 'Watson', |
| 268 | 'state' => 'NY', |
| 269 | 'country' => 'UNITED STATES', |
| 270 | ), |
| 271 | array( |
| 272 | 'first_name' => 'S' . substr(sha1(rand()), 0, 7), |
| 273 | 'middle_name' => substr(sha1(rand()), 0, 7), |
| 274 | 'last_name' => substr(sha1(rand()), 0, 7) . 'sum', |
| 275 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', |
| 276 | 'phone' => '6944412154', |
| 277 | 'street_address' => 'SW 440N Lincoln Dr S', |
| 278 | 'address_1' => 'Add 1', |
| 279 | 'address_2' => 'Add 2', |
| 280 | 'city' => 'Watson', |
| 281 | 'state' => 'NY', |
| 282 | 'country' => 'UNITED STATES', |
| 283 | ), |
| 284 | ); |
| 285 | |
| 286 | return array($headers, $rows); |
| 287 | } |
| 288 | |
| 289 | } |