| 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 'CiviTest/CiviSeleniumTestCase.php'; |
| 28 | |
| 29 | /** |
| 30 | * Class WebTest_Contact_AddressParsingTest |
| 31 | */ |
| 32 | class WebTest_Contact_AddressParsingTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function teststreetAddressParsing() { |
| 39 | // Logging in. |
| 40 | $this->webtestLogin(); |
| 41 | |
| 42 | //Go to the URL of Address Setting to enable street address parsing option |
| 43 | $this->openCiviPage('admin/setting/preferences/address', 'reset=1'); |
| 44 | |
| 45 | //check the street address parsing is already enabled |
| 46 | if (!$this->isChecked("address_options[13]")) { |
| 47 | $this->click("address_options[13]"); |
| 48 | $this->clickLink("_qf_Address_next"); |
| 49 | } |
| 50 | |
| 51 | // Go to the URL to create an Individual contact. |
| 52 | $this->openCiviPage('contact/add', array('reset' => 1, 'ct' => "Individual")); |
| 53 | |
| 54 | //contact details section |
| 55 | $firstName = "John" . substr(sha1(rand()), 0, 7); |
| 56 | $lastName = "Smith" . substr(sha1(rand()), 0, 7); |
| 57 | |
| 58 | //fill in name |
| 59 | $this->type("first_name", $firstName); |
| 60 | $this->type("last_name", $lastName); |
| 61 | |
| 62 | //address section |
| 63 | $this->click("addressBlock"); |
| 64 | $this->waitForElementPresent("address_1_street_address"); |
| 65 | |
| 66 | //fill in address 1 |
| 67 | $this->click("//div[@id='addressBlockId']/div[1]"); |
| 68 | $this->type("address_1_street_address", "121A Sherman St. Apt. 12"); |
| 69 | $this->type("address_1_city", "Dumfries"); |
| 70 | $this->type("address_1_postal_code", "1234"); |
| 71 | $this->select("address_1_state_province_id", "value=1019"); |
| 72 | $this->type("address_1_geo_code_1", "1234"); |
| 73 | $this->type("address_1_geo_code_2", "5678"); |
| 74 | |
| 75 | //fill in address 2 |
| 76 | $this->click("//div[@id='addMoreAddress1']/a/span"); |
| 77 | $this->waitForElementPresent("address_2_street_address"); |
| 78 | $this->type("address_2_street_address", "121 Sherman Street #15"); |
| 79 | $this->type("address_2_city", "Birmingham"); |
| 80 | $this->type("address_2_postal_code", "3456"); |
| 81 | $this->select("address_2_state_province_id", "value=1002"); |
| 82 | $this->type("address_2_geo_code_1", "2678"); |
| 83 | $this->type("address_2_geo_code_2", "1456"); |
| 84 | |
| 85 | //fill in address 3 |
| 86 | $this->click("//div[@id='addMoreAddress2']/a/span"); |
| 87 | $this->waitForElementPresent("address_3_street_address"); |
| 88 | $this->type("address_3_street_address", "121 Sherman Rd Unit 155"); |
| 89 | $this->type("address_3_city", "Birmingham"); |
| 90 | $this->type("address_3_postal_code", "3456"); |
| 91 | $this->select("address_3_state_province_id", "value=1002"); |
| 92 | |
| 93 | //fill in address 4 |
| 94 | $this->click("//div[@id='addMoreAddress3']/a/span"); |
| 95 | $this->waitForElementPresent("address_4_street_address"); |
| 96 | $this->type("address_4_street_address", "121 SW Sherman Way Suite 15"); |
| 97 | $this->type("address_4_city", "Birmingham"); |
| 98 | $this->type("address_4_postal_code", "5491"); |
| 99 | $this->assertSelected('address_4_country_id', "UNITED STATES"); |
| 100 | $this->select("address_4_state_province_id", "value=1002"); |
| 101 | |
| 102 | // Store location type of each address |
| 103 | for ($i = 1; $i <= 4; ++$i) { |
| 104 | $location[$this->getSelectedLabel("address_{$i}_location_type_id")] = $i; |
| 105 | } |
| 106 | |
| 107 | // Submit form |
| 108 | $this->clickLink("_qf_Contact_upload_view"); |
| 109 | $this->waitForText('crm-notification-container', "{$firstName} {$lastName}"); |
| 110 | |
| 111 | //Get the ids of newly created contact |
| 112 | $contactId = $this->urlArg('cid'); |
| 113 | |
| 114 | //Go to the url of edit contact |
| 115 | $this->openCiviPage('contact/add', array('reset' => 1, 'action' => 'update', 'cid' => $contactId), 'addressBlock'); |
| 116 | $this->click("addressBlock"); |
| 117 | $this->click("//div[@id='addressBlockId']/div[1]"); |
| 118 | |
| 119 | // Match addresses by location type since the order may have changed |
| 120 | for ($i = 1; $i <= 4; ++$i) { |
| 121 | $this->waitForElementPresent("address_{$i}_street_address"); |
| 122 | $address[$i] = $location[$this->getSelectedLabel("address_{$i}_location_type_id")]; |
| 123 | // Open "Edit Address Elements" |
| 124 | $this->waitForElementPresent('addressBlockId'); |
| 125 | $this->click('addressBlockId'); |
| 126 | $this->click("//table[@id='address_table_{$i}']//a[text()='Edit Address Elements']"); |
| 127 | } |
| 128 | |
| 129 | //verify all the address fields were parsed correctly |
| 130 | $verifyData = array( |
| 131 | 1 => array( |
| 132 | 'street_number' => '121A', |
| 133 | 'street_name' => 'Sherman St.', |
| 134 | 'street_unit' => 'Apt. 12', |
| 135 | ), |
| 136 | 2 => array( |
| 137 | 'street_number' => '121', |
| 138 | 'street_name' => 'Sherman Street', |
| 139 | 'street_unit' => '#15', |
| 140 | ), |
| 141 | 3 => array( |
| 142 | 'street_number' => '121', |
| 143 | 'street_name' => 'Sherman Rd', |
| 144 | 'street_unit' => 'Unit 155', |
| 145 | ), |
| 146 | 4 => array( |
| 147 | 'street_number' => '121', |
| 148 | 'street_name' => 'SW Sherman Way', |
| 149 | 'street_unit' => 'Suite 15', |
| 150 | ), |
| 151 | ); |
| 152 | foreach ($verifyData as $loc => $values) { |
| 153 | $num = $address[$loc]; |
| 154 | foreach ($values as $key => $expectedvalue) { |
| 155 | $this->waitForValue("address_{$num}_$key", $expectedvalue); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | } |