Merge pull request #205 from colemanw/clicklink
[civicrm-core.git] / tests / phpunit / WebTest / Contact / AddressParsingTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class 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]");
44 $this->click("_qf_Address_next");
45 $this->waitForPageToLoad($this->getTimeoutMsec());
46 }
47
48 // Go to the URL to create an Individual contact.
49 $this->openCiviPage('contact/add', array('reset' => 1, 'ct' => "Individual"));
50
51 //contact details section
52 $firstName = "John" . substr(sha1(rand()), 0, 7);
53 $lastName = "Smith" . substr(sha1(rand()), 0, 7);
54
55 //fill in first name
56 $this->type("first_name", $firstName);
57
58 //fill in last name
59 $this->type("last_name", $lastName);
60
61 //address section
62 $this->click("addressBlock");
63 $this->waitForElementPresent("address_1_street_address");
64
65 //fill in address 1
66 $this->click("//div[@id='addressBlockId']/div[1]");
67 $this->type("address_1_street_address", "121A Sherman St. Apt. 12");
68 $this->type("address_1_city", "Dumfries");
69 $this->type("address_1_postal_code", "1234");
70 $this->select("address_1_state_province_id", "value=1019");
71 $this->type("address_1_geo_code_1", "1234");
72 $this->type("address_1_geo_code_2", "5678");
73
74 //fill in address 2
75 $this->click("//div[@id='addMoreAddress1']/a/span");
76 $this->waitForElementPresent("address_2_street_address");
77 $this->type("address_2_street_address", "121 Sherman Street #15");
78 $this->type("address_2_city", "Birmingham");
79 $this->type("address_2_postal_code", "3456");
80 $this->select("address_2_state_province_id", "value=1002");
81 $this->type("address_2_geo_code_1", "2678");
82 $this->type("address_2_geo_code_2", "1456");
83
84 //fill in address 3
85 $this->click("//div[@id='addMoreAddress2']/a/span");
86 $this->waitForElementPresent("address_3_street_address");
87 $this->type("address_3_street_address", "121 Sherman Rd Unit 155");
88 $this->type("address_3_city", "Birmingham");
89 $this->type("address_3_postal_code", "3456");
90 $this->select("address_3_state_province_id", "value=1002");
91
92 //fill in address 4
93 $this->click("//div[@id='addMoreAddress3']/a/span");
94 $this->waitForElementPresent("address_4_street_address");
95 $this->type("address_4_street_address", "121 SW Sherman Way Suite 15");
96 $this->type("address_4_city", "Birmingham");
97 $this->type("address_4_postal_code", "5491");
98 $this->assertTrue($this->isTextPresent("- select - United States"));
99 $this->select("address_4_state_province_id", "value=1002");
100
101 // Store location type of each address
102 for ($i = 1; $i <= 4; ++$i) {
103 $location[$this->getSelectedLabel("address_{$i}_location_type_id")] = $i;
104 }
105
106 // Clicking save.
107 $this->click("_qf_Contact_upload_view");
108 $this->waitForPageToLoad($this->getTimeoutMsec());
109 $this->assertTrue($this->isTextPresent("{$firstName} {$lastName} has been created."));
110
111 //Get the is of newly created contact
112 $matches = array();
113 preg_match('/id=([0-9]+)/', $this->getLocation(), $matches);
114 $contactId = $matches[1];
115
116 //Go to the url of edit contact
117 $this->openCiviPage('contact/add', array('reset' => 1, 'action' => 'update', 'cid' => $contactId), 'addressBlock');
118 $this->click("addressBlock");
119 $this->click("//div[@id='addressBlockId']/div[1]");
120 $this->waitForElementPresent("address_1_street_address");
121 $this->waitForElementPresent("address_4_street_address");
122
123 // Match addresses by location type since the order may have changed
124 for ($i = 1; $i <= 4; ++$i) {
125 $address[$i] = $location[$this->getSelectedLabel("address_{$i}_location_type_id")];
126 // Open "Edit Address Elements"
127 $this->click("//table[@id='address_{$i}']//a[@href='#']");
128 }
129
130 //verify all the address fields whether parsed correctly
131 $verifyData = array(
132 1 => array(
133 'street_number' => '121A',
134 'street_name' => 'Sherman St.',
135 'street_unit' => 'Apt. 12',
136 ),
137 2 => array(
138 'street_number' => '121',
139 'street_name' => 'Sherman Street',
140 'street_unit' => '#15',
141 ),
142 3 => array(
143 'street_number' => '121',
144 'street_name' => 'Sherman Rd',
145 'street_unit' => 'Unit 155',
146 ),
147 4 => array(
148 'street_number' => '121',
149 'street_name' => 'SW Sherman Way',
150 'street_unit' => 'Suite 15',
151 )
152 );
153 foreach ($verifyData as $loc => $values) {
154 $num = $address[$loc];
155 foreach ($values as $key => $expectedvalue) {
156 $actualvalue = $this->getValue("address_{$num}_$key");
157 $this->assertEquals($expectedvalue, $actualvalue);
158 }
159 }
160 }
161}
162