Merge pull request #4579 from colemanw/CRM_Utils_Array
[civicrm-core.git] / tests / phpunit / WebTest / Profile / SearchTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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_Profile_SearchTest
31 */
32 class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testSearchProfile() {
39 $this->webtestLogin();
40
41 // enable county field
42 $this->openCiviPage('admin/setting/preferences/address', 'reset=1');
43 $this->check('address_options[7]');
44 $this->clickLink('_qf_Address_next-bottom');
45
46 // Add new profile.
47 $this->openCiviPage('admin/uf/group', 'reset=1');
48
49 $this->click('newCiviCRMProfile-bottom');
50
51 $this->waitForElementPresent('_qf_Group_next-bottom');
52
53 //Name of profile
54 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
55 $this->type('title', $profileTitle);
56
57 $this->click('uf_group_type_Profile');
58 //click on save
59 $this->click('_qf_Group_next-bottom');
60 $this->waitForPageToLoad($this->getTimeoutMsec());
61 $this->waitForElementPresent("xpath=//a/span[text()='Add Field']");
62
63 //check for profile create
64 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
65
66 // Get profile id (gid) from URL
67 $profileId = $this->urlArg('gid');
68
69 // Add Last Name field.
70 $this->waitForElementPresent("field_name[0]");
71 $this->click('field_name[0]');
72 $this->select('field_name[0]', 'value=Individual');
73 $this->click('field_name[1]');
74 $this->select('field_name[1]', 'value=last_name');
75 $this->click("//option[@value='Individual']");
76 $this->click('visibility');
77 $this->select('visibility', 'value=Public Pages');
78 $this->click('is_searchable');
79 $this->click('in_selector');
80 // click on save
81 $this->click('_qf_Field_next_new-bottom');
82 //check for field add
83 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Last Name' has been saved to '$profileTitle'.");
84 $this->waitForText('crm-notification-container', 'You can add another profile field.');
85
86 // Add Email field.
87 $this->click('field_name[0]');
88 $this->select('field_name[0]', 'value=Contact');
89 $this->click('field_name[1]');
90 $this->select('field_name[1]', 'value=email');
91 $this->click("//option[@value='Contact']");
92 $this->click('visibility');
93 $this->select('visibility', 'value=Public Pages');
94 $this->click('is_searchable');
95 $this->click('in_selector');
96 // click on save
97 $this->click('_qf_Field_next_new-bottom');
98 //check for field add
99 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Email' has been saved to '$profileTitle'.");
100 $this->waitForText('crm-notification-container', 'You can add another profile field.');
101
102 // Add Sample Custom Field.
103 $this->click('field_name[0]');
104 $this->select('field_name[0]', 'value=Individual');
105 $this->click('field_name[1]');
106 $this->select('field_name[1]', 'value=custom_1');
107 $this->click("//option[@value='Individual']");
108 $this->click('visibility');
109 $this->select('visibility', 'value=Public Pages');
110 $this->click('is_searchable');
111 $this->click('in_selector');
112 $this->clickLink('_qf_Field_next_new-bottom', 'field_name[0]', FALSE);
113 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
114
115 // Add state, country and county field
116 $this->click('field_name[0]');
117 $this->select('field_name[0]', 'value=Contact');
118 $this->click('field_name[1]');
119 $this->select('field_name[1]', 'value=country');
120 $this->select('field_name[2]', 'Primary');
121 $this->click('visibility');
122 $this->select('visibility', 'value=Public Pages and Listings');
123 $this->click('is_searchable');
124 $this->click('in_selector');
125 // click on save and new
126 $this->clickLink('_qf_Field_next_new-bottom', 'field_name[0]', FALSE);
127 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
128
129 $this->click('field_name[0]');
130 $this->select('field_name[0]', 'value=Contact');
131 $this->click('field_name[1]');
132 $this->select('field_name[1]', 'value=state_province');
133 $this->select('field_name[2]', 'Primary');
134 $this->click('visibility');
135 $this->select('visibility', 'value=Public Pages and Listings');
136 $this->click('is_searchable');
137 $this->click('in_selector');
138 // click on save and new
139 $this->clickLink('_qf_Field_next_new-bottom', 'field_name[0]', FALSE);
140 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
141
142 $this->click('field_name[0]');
143 $this->select('field_name[0]', 'value=Contact');
144 $this->click('field_name[1]');
145 $this->select('field_name[1]', 'value=county');
146 $this->select('field_name[2]', 'Primary');
147 $this->click('visibility');
148 $this->select('visibility', 'value=Public Pages and Listings');
149 $this->click('is_searchable');
150 $this->click('in_selector');
151
152 // click on save and new
153 $this->clickLink('_qf_Field_next_new-bottom', 'field_name[0]', FALSE);
154 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
155
156 $this->select('field_name[0]', 'value=Individual');
157 $this->select('field_name[1]', 'value=current_employer');
158 $this->select('visibility', 'value=Public Pages and Listings');
159 $this->click('is_searchable');
160 $this->click('in_selector');
161
162 // click on save
163 $this->clickLink('_qf_Field_next-bottom', "xpath=//div[@id='field_page']/div[1]/a[4]/span[text()='Use (create mode)']", FALSE);
164
165 $uselink = explode('?', $this->getAttribute("xpath=//*[@id='field_page']/div[1]/a[4]@href"));
166 $this->openCiviPage('profile/create', "$uselink[1]", '_qf_Edit_next');
167 $lastName = substr(sha1(rand()), 0, 7);
168 $orgName = 'Organisation'.substr(sha1(rand()), 0, 7);
169
170 // Fill Last Name
171 $this->type('last_name', $lastName);
172 // Fill Email
173 $this->type('email-Primary', "jhon@$lastName.com");
174 // Select Custom option
175 $this->click('CIVICRM_QFID_Edu_2');
176
177 // fill country, state, county
178 $this->select('country-Primary', "United States");
179
180 // wait for state data to be populated
181 $this->waitForElementPresent("xpath=//select[@id='state_province-Primary']/option[text()='California']");
182 $this->select('state_province-Primary', "California");
183
184 // wait for county data to be populated
185 $this->waitForElementPresent("xpath=//select[@id='county-Primary']/option[text()='Alameda']");
186 $this->select('county-Primary', "Alameda");
187
188 $this->type('current_employer', $orgName);
189
190 $this->clickLink('_qf_Edit_next', NULL);
191
192 $this->assertElementContainsText("css=span.msg-text", 'Your information has been saved.');
193
194 // Search Contact via profile.
195 $this->waitForElementPresent("xpath=//div[@id='crm-container']//div/a[text()='» Back to Listings']");
196 $this->click("xpath=//div[@id='crm-container']//div/a[text()='» Back to Listings']");
197 $this->waitForElementPresent("xpath=//div[@class='crm-block crm-form-block']");
198 $this->click("xpath=//div[@class='crm-block crm-form-block']");
199 // Fill Last Name
200 $this->type('last_name', $lastName);
201 // Fill Email
202 $this->type('email-Primary', "jhon@$lastName.com");
203
204 // Fill state, county, country
205 $this->select('country-Primary', "United States");
206
207 // wait for state data to be populated
208 $this->waitForElementPresent("xpath=//select[@id='state_province-Primary']/option[text()='California']");
209 $this->select('state_province-Primary', "California");
210
211 // wait for county data to be populated
212 $this->waitForElementPresent("xpath=//select[@id='county-Primary']/option[text()='Alameda']");
213 $this->select('county-Primary', "Alameda");
214
215 // Select Custom option
216 $this->select('custom_1', 'Education');
217 $this->clickLink('_qf_Search_refresh', NULL);
218
219 // Verify Data.
220 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[2][text()='$lastName']"));
221 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[3][text()='$lastName']"));
222 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[4][text()='jhon@$lastName.com']"));
223 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[5][text()='Education']"));
224 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[6][text()='United States']"));
225 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[7][text()='CA']"));
226 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[8][text()='Alameda']"));
227
228 // verify if the organization has been created -- CRM-15368
229 $this->click("css=input#sort_name_navigation");
230 $this->type("css=input#sort_name_navigation", "$orgName");
231 $this->typeKeys("css=input#sort_name_navigation", "$orgName");
232 $this->waitForElementPresent("css=ul.ui-autocomplete li");
233
234 // visit contact summary page
235 $this->click("css=ul.ui-autocomplete li");
236 $this->waitForPageToLoad($this->getTimeoutMsec());
237
238 // Go back to Profile fields admin
239 $this->openCiviPage('admin/uf/group/field', "reset=1&action=browse&gid=$profileId", "xpath=//table/tbody/tr[1]/td[9]");
240
241 // Edit first profile field
242 $this->clickLink("xpath=//table/tbody/tr[1]/td[9]/span[1]/a[1]", '_qf_Field_next-bottom', FALSE);
243
244 $this->waitForElementPresent("visibility");
245 $this->click("xpath=//tr[@id='profile_visibility']/td[1]/a");
246 $this->waitForElementPresent("xpath=//div[@id='crm-notification-container']/div/div[2]/p[2]");
247 $this->waitForText('crm-notification-container', 'Is this field hidden from other users');
248 $this->select('visibility', 'value=Public Pages and Listings');
249 }
250 }