Merge pull request #3179 from webpartners/master
[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
62 //check for profile create
63 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
64
65 // Get profile id (gid) from URL
66 $profileId = $this->urlArg('gid');
67
68 // Add Last Name field.
69 $this->click('field_name[0]');
70 $this->select('field_name[0]', 'value=Individual');
71 $this->click('field_name[1]');
72 $this->select('field_name[1]', 'value=last_name');
73 $this->click("//option[@value='Individual']");
74 $this->click('visibility');
75 $this->select('visibility', 'value=Public Pages');
76 $this->click('is_searchable');
77 $this->click('in_selector');
78 // click on save
79 $this->click('_qf_Field_next_new-bottom');
80 $this->waitForPageToLoad($this->getTimeoutMsec());
81 //check for field add
82 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Last Name' has been saved to '$profileTitle'.");
83 $this->waitForText('crm-notification-container', 'You can add another profile field.');
84
85 // Add Email field.
86 $this->click('field_name[0]');
87 $this->select('field_name[0]', 'value=Contact');
88 $this->click('field_name[1]');
89 $this->select('field_name[1]', 'value=email');
90 $this->click("//option[@value='Contact']");
91 $this->click('visibility');
92 $this->select('visibility', 'value=Public Pages');
93 $this->click('is_searchable');
94 $this->click('in_selector');
95 // click on save
96 $this->click('_qf_Field_next_new-bottom');
97 $this->waitForPageToLoad($this->getTimeoutMsec());
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');
113
114 // Add state, country and county field
115 $this->click('field_name[0]');
116 $this->select('field_name[0]', 'value=Contact');
117 $this->click('field_name[1]');
118 $this->select('field_name[1]', 'value=country');
119 $this->select('field_name[2]', 'Primary');
120 $this->click('visibility');
121 $this->select('visibility', 'value=Public Pages and Listings');
122 $this->click('is_searchable');
123 $this->click('in_selector');
124 // click on save and new
125 $this->clickLink('_qf_Field_next_new-bottom');
126
127 $this->click('field_name[0]');
128 $this->select('field_name[0]', 'value=Contact');
129 $this->click('field_name[1]');
130 $this->select('field_name[1]', 'value=state_province');
131 $this->select('field_name[2]', 'Primary');
132 $this->click('visibility');
133 $this->select('visibility', 'value=Public Pages and Listings');
134 $this->click('is_searchable');
135 $this->click('in_selector');
136 // click on save and new
137 $this->clickLink('_qf_Field_next_new-bottom');
138
139 $this->click('field_name[0]');
140 $this->select('field_name[0]', 'value=Contact');
141 $this->click('field_name[1]');
142 $this->select('field_name[1]', 'value=county');
143 $this->select('field_name[2]', 'Primary');
144 $this->click('visibility');
145 $this->select('visibility', 'value=Public Pages and Listings');
146 $this->click('is_searchable');
147 $this->click('in_selector');
148
149 // click on save
150 $this->clickLink('_qf_Field_next-bottom', "xpath=//div[@id='field_page']/div[1]/a[4]/span[text()='Use (create mode)']");
151
152 $uselink = explode('?', $this->getAttribute("xpath=//*[@id='field_page']/div[1]/a[4]@href"));
153 $this->openCiviPage('profile/create', "$uselink[1]", '_qf_Edit_cancel');
154 $this->waitForElementPresent('_qf_Edit_next');
155 $lastName = substr(sha1(rand()), 0, 7);
156
157 // Fill Last Name
158 $this->type('last_name', $lastName);
159 // Fill Email
160 $this->type('email-Primary', "jhon@$lastName.com");
161 // Select Custom option
162 $this->click('CIVICRM_QFID_Edu_2');
163
164 // fill country, state, county
165 $this->select('country-Primary', "United States");
166 // adding sleep gives time for state data
167 // to get populated in state combo box
168 sleep(1);
169 $this->select('state_province-Primary', "California");
170 // adding sleep gives time for county data
171 // to get populated in county combo box
172 sleep(1);
173 $this->select('county-Primary', "Alameda");
174 $this->click('_qf_Edit_next');
175 $this->waitForPageToLoad($this->getTimeoutMsec());
176
177 $this->assertElementContainsText("css=span.msg-text", 'Your information has been saved.');
178
179 // Search Contact via profile.
180 $this->waitForElementPresent("xpath=//div[@id='crm-container']//div/a[text()='» Back to Listings']");
181 $this->click("xpath=//div[@id='crm-container']//div/a[text()='» Back to Listings']");
182 $this->waitForElementPresent("xpath=//div[@class='crm-block crm-form-block']");
183 $this->click("xpath=//div[@class='crm-block crm-form-block']");
184 // Fill Last Name
185 $this->type('last_name', $lastName);
186 // Fill Email
187 $this->type('email-Primary', "jhon@$lastName.com");
188
189 // Fill state, county, country
190 $this->select('country-Primary', "United States");
191 // adding sleep gives time for state data
192 // to get populated in state combo box
193 sleep(1);
194 $this->select('state_province-Primary', "California");
195 // adding sleep gives time for county data
196 // to get populated in county combo box
197 sleep(1);
198 $this->select('county-Primary', "Alameda");
199
200 // Select Custom option
201 $this->click('CIVICRM_QFID_Edu_2');
202 $this->click('_qf_Search_refresh');
203 $this->waitForPageToLoad($this->getTimeoutMsec());
204
205 // Verify Data.
206 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[2][text()='$lastName']"));
207 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[3][text()='$lastName']"));
208 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[4][text()='jhon@$lastName.com']"));
209 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[5][text()='Education']"));
210 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[6][text()='United States']"));
211 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[7][text()='CA']"));
212 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[8][text()='Alameda']"));
213
214 // Go back to Profile fields admin
215 $this->openCiviPage('admin/uf/group/field', "reset=1&action=browse&gid=$profileId");
216
217 // Edit first profile field
218 $this->waitForElementPresent("xpath=//table/tbody/tr[1]/td[9]");
219 $this->clickLink("xpath=//table/tbody/tr[1]/td[9]/span[1]/a[1]", '_qf_Field_next-bottom', FALSE);
220
221 // sleep 5 to make sure jQuery is not hiding field after page load
222 // Because it tends to cause problems, all uses of sleep() must be justified in comments
223 // Sleep should never be used for wait for anything to load from the server
224 // Justification for this instance: FIXME
225 sleep(5);
226 $this->assertTrue($this->isElementPresent("visibility"), 'Visibility field not present when editing existing profile field.');
227 $this->click("xpath=//tr[@id='profile_visibility']/td[1]/a");
228 $this->waitForElementPresent("xpath=//div[@id='crm-notification-container']/div/div[2]/p[2]");
229 $this->waitForText('crm-notification-container', 'Is this field hidden from other users');
230 $this->select('visibility', 'value=Public Pages and Listings');
231 }
232 }