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