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