Merge pull request #4579 from colemanw/CRM_Utils_Array
[civicrm-core.git] / tests / phpunit / WebTest / Profile / SearchTest.php
CommitLineData
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 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Profile_SearchTest
31 */
6a488035
TO
32class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testSearchProfile() {
6a488035
TO
39 $this->webtestLogin();
40
6d2387a1
PJ
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
6a488035 46 // Add new profile.
305515fb 47 $this->openCiviPage('admin/uf/group', 'reset=1');
76e86fd8 48
6a488035
TO
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
3379d026 57 $this->click('uf_group_type_Profile');
6a488035
TO
58 //click on save
59 $this->click('_qf_Group_next-bottom');
60 $this->waitForPageToLoad($this->getTimeoutMsec());
bf2c3b74 61 $this->waitForElementPresent("xpath=//a/span[text()='Add Field']");
6a488035
TO
62
63 //check for profile create
6c5f7368 64 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
6a488035
TO
65
66 // Get profile id (gid) from URL
a471a3b6 67 $profileId = $this->urlArg('gid');
6a488035
TO
68
69 // Add Last Name field.
bf2c3b74 70 $this->waitForElementPresent("field_name[0]");
6a488035
TO
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');
6a488035 82 //check for field add
6c5f7368
CW
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.');
305515fb 85
6a488035
TO
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');
6a488035 98 //check for field add
6c5f7368
CW
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.');
6a488035
TO
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');
bf2c3b74 112 $this->clickLink('_qf_Field_next_new-bottom', 'field_name[0]', FALSE);
113 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
6d2387a1
PJ
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
bf2c3b74 126 $this->clickLink('_qf_Field_next_new-bottom', 'field_name[0]', FALSE);
127 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
6d2387a1
PJ
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
bf2c3b74 139 $this->clickLink('_qf_Field_next_new-bottom', 'field_name[0]', FALSE);
140 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
6d2387a1
PJ
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
89d6437d 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
6a488035 162 // click on save
bf2c3b74 163 $this->clickLink('_qf_Field_next-bottom', "xpath=//div[@id='field_page']/div[1]/a[4]/span[text()='Use (create mode)']", FALSE);
6a488035 164
3379d026 165 $uselink = explode('?', $this->getAttribute("xpath=//*[@id='field_page']/div[1]/a[4]@href"));
39a2888d 166 $this->openCiviPage('profile/create', "$uselink[1]", '_qf_Edit_next');
6a488035 167 $lastName = substr(sha1(rand()), 0, 7);
89d6437d 168 $orgName = 'Organisation'.substr(sha1(rand()), 0, 7);
6a488035
TO
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');
6d2387a1
PJ
176
177 // fill country, state, county
178 $this->select('country-Primary', "United States");
39a2888d
CW
179
180 // wait for state data to be populated
181 $this->waitForElementPresent("xpath=//select[@id='state_province-Primary']/option[text()='California']");
6d2387a1 182 $this->select('state_province-Primary', "California");
39a2888d
CW
183
184 // wait for county data to be populated
185 $this->waitForElementPresent("xpath=//select[@id='county-Primary']/option[text()='Alameda']");
6d2387a1 186 $this->select('county-Primary', "Alameda");
39a2888d 187
89d6437d 188 $this->type('current_employer', $orgName);
189
39a2888d 190 $this->clickLink('_qf_Edit_next', NULL);
305515fb 191
3379d026 192 $this->assertElementContainsText("css=span.msg-text", 'Your information has been saved.');
6a488035
TO
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");
6d2387a1
PJ
203
204 // Fill state, county, country
205 $this->select('country-Primary', "United States");
39a2888d
CW
206
207 // wait for state data to be populated
208 $this->waitForElementPresent("xpath=//select[@id='state_province-Primary']/option[text()='California']");
6d2387a1 209 $this->select('state_province-Primary', "California");
39a2888d
CW
210
211 // wait for county data to be populated
212 $this->waitForElementPresent("xpath=//select[@id='county-Primary']/option[text()='Alameda']");
6d2387a1
PJ
213 $this->select('county-Primary', "Alameda");
214
6a488035 215 // Select Custom option
bf2c3b74 216 $this->select('custom_1', 'Education');
39a2888d 217 $this->clickLink('_qf_Search_refresh', NULL);
6a488035
TO
218
219 // Verify Data.
305515fb
PJ
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']"));
6d2387a1
PJ
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']"));
6a488035 227
89d6437d 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
6a488035 238 // Go back to Profile fields admin
39a2888d 239 $this->openCiviPage('admin/uf/group/field', "reset=1&action=browse&gid=$profileId", "xpath=//table/tbody/tr[1]/td[9]");
6a488035
TO
240
241 // Edit first profile field
3379d026 242 $this->clickLink("xpath=//table/tbody/tr[1]/td[9]/span[1]/a[1]", '_qf_Field_next-bottom', FALSE);
6a488035 243
39a2888d 244 $this->waitForElementPresent("visibility");
6a488035
TO
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]");
6c5f7368 247 $this->waitForText('crm-notification-container', 'Is this field hidden from other users');
6a488035
TO
248 $this->select('visibility', 'value=Public Pages and Listings');
249 }
42daf119 250}