Merge pull request #4920 from pratikshad/Fixed-webtests
[civicrm-core.git] / tests / phpunit / WebTest / Contact / AdvanceSearchPaneTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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_Contact_AdvanceSearchPaneTest
31 */
32 class WebTest_Contact_AdvanceSearchPaneTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /**
39 * Test individual pane seperatly.
40 */
41 public function testIndividualPanes() {
42 $this->webtestLogin();
43
44 // Get all default advance search panes.
45 $allpanes = $this->_advanceSearchPanes();
46
47 // Test Individual panes.
48 foreach (array_keys($allpanes) as $pane) {
49 // Go to the Advance Search
50 $this->openCiviPage('contact/search/advanced', 'reset=1');
51
52 // Select some fields from pane.
53 $this->_selectPaneFields($pane);
54
55 $this->click('_qf_Advanced_refresh');
56
57 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
58
59 // check the opened panes.
60 $this->_checkOpenedPanes(array($pane));
61 }
62 }
63
64 /**
65 * Test by selecting all panes at a time.
66 */
67 public function testAllPanes() {
68 $this->webtestLogin();
69
70 // Get all default advance search panes.
71 $allpanes = $this->_advanceSearchPanes();
72
73 // Go to the Advance Search
74 $this->openCiviPage('contact/search/advanced', 'reset=1');
75
76 // Select some fields from all default panes.
77 foreach (array_keys($allpanes) as $pane) {
78 $this->_selectPaneFields($pane);
79 }
80
81 $this->click('_qf_Advanced_refresh');
82
83 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
84
85 // check all opened panes.
86 $this->_checkOpenedPanes(array_keys($allpanes));
87 }
88
89 /**
90 * @param array $openedPanes
91 */
92 public function _checkOpenedPanes($openedPanes = array()) {
93 if (!$this->isTextPresent('None found.')) {
94 $this->click('css=div.crm-advanced_search_form-accordion div.crm-accordion-header');
95 }
96
97 $allPanes = $this->_advanceSearchPanes();
98
99 foreach ($allPanes as $paneRef => $pane) {
100 if (in_array($paneRef, $openedPanes)) {
101 // assert for element present.
102 $this->waitForElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}");
103 }
104 else {
105 $this->assertTrue(!$this->isElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}"));
106 }
107 }
108 }
109
110 /**
111 * @param $paneRef
112 * @param array $selectFields
113 */
114 public function _selectPaneFields($paneRef, $selectFields = array()) {
115 $pane = $this->_advanceSearchPanes($paneRef);
116
117 $this->click("css=div.crm-accordion-wrapper {$pane['headerLocator']}");
118 $this->waitForElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}");
119
120 foreach ($pane['fields'] as $fld => $field) {
121 if (!empty($selectFields) && !in_array($fld, $selectFields)) {
122 continue;
123 }
124
125 $fldLocator = isset($field['locator']) ? $field['locator'] : '';
126
127 switch ($field['type']) {
128 case 'text':
129 $this->type($fldLocator, current($field['values']));
130 break;
131
132 case 'select':
133 foreach ($field['values'] as $op) {
134 $this->select($fldLocator, 'label=' . $op);
135 }
136 break;
137
138 case 'checkbox':
139 foreach ($field['values'] as $op) {
140 if (!$this->isChecked($op)) {
141 $this->click($op);
142 }
143 }
144 break;
145
146 case 'radio':
147 foreach ($field['values'] as $op) {
148 $this->click($op);
149 }
150 break;
151
152 case 'multiselect2':
153 foreach ($field['values'] as $op) {
154 $this->waitForElementPresent($fldLocator);
155 $this->multiselect2($fldLocator, $op);
156 }
157 break;
158
159 case 'date':
160 $this->webtestFillDate($fldLocator, current($field['values']));
161 break;
162 }
163 }
164 }
165
166 /**
167 * @param null $paneRef
168 *
169 * @return array
170 */
171 public function _advanceSearchPanes($paneRef = NULL) {
172 static $_advance_search_panes;
173
174 if (!isset($_advance_search_panes) || empty($_advance_search_panes)) {
175 $_advance_search_panes = array(
176 'location' => array(
177 'headerLocator' => 'div#location',
178 'bodyLocator' => 'select#country',
179 'title' => 'Address Fields',
180 'fields' => array(
181 'Location Type' => array(
182 'type' => 'multiselect2',
183 'locator' => 'location_type',
184 'values' => array(array('Home', 'Work')),
185 ),
186 'Country' => array(
187 'type' => 'select',
188 'locator' => 'country',
189 'values' => array('United States'),
190 ),
191 'State' => array(
192 'type' => 'multiselect2',
193 'locator' => 'state_province',
194 'values' => array(
195 array('Alabama', 'California', 'New Jersey', 'New York'),
196 ),
197 ),
198 ),
199 ),
200 'custom' => array(
201 'headerLocator' => 'div#custom',
202 'bodyLocator' => 'div#constituent_information',
203 'title' => 'Custom Data',
204 'fields' => array(
205 'Marital Status' => array(
206 'type' => 'select',
207 'locator' => 'custom_2',
208 'values' => array('Single'),
209 ),
210 ),
211 ),
212 'activity' => array(
213 'headerLocator' => 'div#activity',
214 'bodyLocator' => 'input#activity_subject',
215 'title' => 'Activities',
216 'fields' => array(
217 'Activity Type' => array(
218 'type' => 'checkbox',
219 'values' => array(
220 'activity_type_id[6]',
221 'activity_type_id[3]',
222 'activity_type_id[5]',
223 'activity_type_id[7]',
224 ),
225 ),
226 'Activity Subject' => array(
227 'type' => 'text',
228 'locator' => 'activity_subject',
229 'values' => array('Test Subject'),
230 ),
231 'Activity Status' => array(
232 'type' => 'checkbox',
233 'values' => array('activity_status[1]', 'activity_status[2]'),
234 ),
235 ),
236 ),
237 'relationship' => array(
238 'headerLocator' => 'div#relationship',
239 'bodyLocator' => 'select#relation_type_id',
240 'title' => 'Relationships',
241 'fields' => array(
242 'Relation Type' => array(
243 'type' => 'select',
244 'locator' => 'relation_type_id',
245 'values' => array('Employee of'),
246 ),
247 'Relation Target' => array(
248 'type' => 'text',
249 'locator' => 'relation_target_name',
250 'values' => array('Test Contact'),
251 ),
252 ),
253 ),
254 'demographics' => array(
255 'headerLocator' => 'div#demographics',
256 'bodyLocator' => 'input#birth_date_low_display',
257 'title' => 'Demographics',
258 'fields' => array(
259 'Birth Date Range' => array(
260 'type' => 'select',
261 'locator' => 'birth_date_relative',
262 'values' => array('Choose Date Range'),
263 ),
264 'Birth Date from' => array(
265 'type' => 'date',
266 'locator' => 'birth_date_low',
267 'values' => array('10 September 1980'),
268 ),
269 'Birth Date to' => array(
270 'type' => 'date',
271 'locator' => 'birth_date_high',
272 'values' => array('10 September 2000'),
273 ),
274 ),
275 ),
276 'note' => array(
277 'headerLocator' => 'div#notes',
278 'bodyLocator' => 'input#note',
279 'title' => 'Notes',
280 'fields' => array(
281 'note' => array(
282 'type' => 'text',
283 'locator' => 'css=div#notes-search input#note',
284 'values' => array('Test Note'),
285 ),
286 ),
287 ),
288 'change_log' => array(
289 'headerLocator' => 'div#changeLog',
290 'bodyLocator' => 'input#changed_by',
291 'title' => 'Change Log',
292 'fields' => array(
293 'Modified By' => array(
294 'type' => 'text',
295 'locator' => 'changed_by',
296 'values' => array('Test User'),
297 ),
298 ),
299 ),
300 'contribution' => array(
301 'headerLocator' => 'div#CiviContribute',
302 'bodyLocator' => 'select#financial_type_id',
303 'title' => 'Contributions',
304 'fields' => array(
305 'Amount from' => array(
306 'type' => 'text',
307 'locator' => 'contribution_amount_low',
308 'values' => array('10'),
309 ),
310 'Amount to' => array(
311 'type' => 'text',
312 'locator' => 'contribution_amount_high',
313 'values' => array('1000'),
314 ),
315 'Financial Type' => array(
316 'type' => 'select',
317 'locator' => 'financial_type_id',
318 'values' => array('Donation'),
319 ),
320 'Contribution Status' => array(
321 'type' => 'checkbox',
322 'values' => array('contribution_status_id[1]', 'contribution_status_id[2]'),
323 ),
324 ),
325 ),
326 'membership' => array(
327 'headerLocator' => 'div#CiviMember',
328 'bodyLocator' => 'input#member_source',
329 'title' => 'Memberships',
330 'fields' => array(
331 'Membership Type' => array(
332 'type' => 'checkbox',
333 'values' => array('member_membership_type_id[1]', 'member_membership_type_id[2]'),
334 ),
335 'Membership Status' => array(
336 'type' => 'checkbox',
337 'values' => array('member_status_id[1]', 'member_status_id[2]'),
338 ),
339 ),
340 ),
341 'event' => array(
342 'headerLocator' => 'div#CiviEvent',
343 'bodyLocator' => 'input#event_id',
344 'title' => 'Events',
345 'fields' => array(
346 'Participant Status' => array(
347 'type' => 'checkbox',
348 'values' => array('participant_status_id[1]', 'participant_status_id[2]'),
349 ),
350 'Participant Role' => array(
351 'type' => 'checkbox',
352 'values' => array('participant_role_id[1]', 'participant_role_id[2]'),
353 ),
354 ),
355 ),
356 );
357 }
358
359 if ($paneRef) {
360 return $_advance_search_panes[$paneRef];
361 }
362
363 return $_advance_search_panes;
364 }
365 }