add missing comments - tests directory
[civicrm-core.git] / tests / phpunit / WebTest / Contact / SearchbyDateFilterTest.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 class WebTest_Contact_SearchbyDateFilterTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 /*
35 * Function to test individual pane seperatly.
36 */
37 function testAdvancedSearch() {
38 $this->webtestLogin();
39
40 // Get all default advance search panes.
41 $allpanes = $this->_advanceSearchPanesDateFilter();
42
43 // Test Individual panes.
44 foreach (array_keys($allpanes) as $pane) {
45 // Go to the Advance Search
46 $this->openCiviPage("contact/search/advanced", "reset=1");
47
48 // Select some fields from pane.
49 $this->_selectPaneFields($pane);
50
51 $this->click('_qf_Advanced_refresh');
52
53 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
54 // check the opened panes.
55 $this->_checkOpenedPanes(array($pane));
56 }
57
58 }
59
60 function testIndividualSearchPage(){
61 $this->webtestLogin();
62
63 $this->openCiviPage("contribute/search", "reset=1");
64 $this->select("contribution_date_relative","value=previous_before.quarter");
65 $this->click("_qf_Search_refresh");
66 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
67 $this->select("contribution_date_relative","value=previous_2.quarter");
68 $this->click("_qf_Search_refresh");
69 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
70 $this->select("contribution_date_relative","value=earlier.quarter");
71 $this->click("_qf_Search_refresh");
72 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
73 $this->select("contribution_date_relative","value=ending.year");
74
75 $this->click("_qf_Search_refresh");
76 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
77
78 $this->openCiviPage("member/search", "reset=1");
79 $this->select("member_end_date_relative","value=previous_before.month");
80 $this->click("_qf_Search_refresh");
81 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
82 $this->select("member_end_date_relative","value=previous_2.month");
83 $this->click("_qf_Search_refresh");
84 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
85 $this->select("member_end_date_relative","value=earlier.month");
86 $this->click("_qf_Search_refresh");
87 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
88 $this->select("member_end_date_relative","value=ending.month");
89 $this->click("_qf_Search_refresh");
90 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
91
92 $this->openCiviPage("event/search", "reset=1");
93 $this->select("event_relative","value=previous_before.week");
94 $this->click("_qf_Search_refresh");
95 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
96 $this->select("event_relative","value=previous_2.week");
97 $this->click("_qf_Search_refresh");
98 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
99 $this->select("event_relative","value=earlier.week");
100 $this->click("_qf_Search_refresh");
101 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
102 $this->select("event_relative","value=ending.week");
103 $this->click("_qf_Search_refresh");
104 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
105
106 $this->openCiviPage("activity/search", "reset=1");
107 $this->select("activity_date_relative","value=previous_before.day");
108 $this->click("_qf_Search_refresh");
109 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
110 $this->select("activity_date_relative","value=previous_2.day");
111 $this->click("_qf_Search_refresh");
112 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
113 $this->select("activity_date_relative","value=earlier.day");
114 $this->click("_qf_Search_refresh");
115 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
116 $this->select("activity_date_relative","value=ending.quarter");
117 $this->click("_qf_Search_refresh");
118 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
119
120 $this->openCiviPage("pledge/search", "reset=1");
121 $this->select("pledge_payment_date_relative","value=greater.week");
122 $this->click("_qf_Search_refresh");
123 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
124 $this->click("xpath=//form[@id='Search']/div[2]/div/div");
125 $this->select("pledge_payment_date_relative","value=greater.day");
126 $this->click("_qf_Search_refresh");
127 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
128 $this->click("xpath=//form[@id='Search']/div[2]/div/div");
129 $this->select("pledge_payment_date_relative","value=greater.quarter");
130 $this->click("_qf_Search_refresh");
131 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
132 $this->click("xpath=//form[@id='Search']/div[2]/div/div");
133 $this->select("pledge_payment_date_relative","value=greater.month");
134 $this->click("_qf_Search_refresh");
135 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
136
137 $this->openCiviPage("mailing", "reset=1");
138 $this->select("mailing_relative","value=previous_before.year");
139 $this->click("_qf_Search_refresh");
140 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
141 $this->select("mailing_relative","value=previous_2.year");
142 $this->click("_qf_Search_refresh");
143 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
144 $this->select("mailing_relative","value=earlier.year");
145 $this->click("_qf_Search_refresh");
146 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
147 $this->select("mailing_relative","value=greater.year");
148 $this->click("_qf_Search_refresh");
149 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
150 }
151
152 /**
153 * @param array $openedPanes
154 */
155 function _checkOpenedPanes($openedPanes = array(
156 )) {
157 if (!$this->isTextPresent('No matches found')) {
158 $this->click('css=div.crm-advanced_search_form-accordion div.crm-accordion-header');
159 }
160
161 $allPanes = $this->_advanceSearchPanesDateFilter();
162
163 foreach ($allPanes as $paneRef => $pane) {
164 if (in_array($paneRef, $openedPanes)) {
165 // assert for element present.
166 $this->waitForElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}");
167 }
168 else {
169 $this->assertTrue(!$this->isElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}"));
170 }
171 }
172 }
173
174 /**
175 * @param $paneRef
176 * @param array $selectFields
177 */
178 function _selectPaneFields($paneRef, $selectFields = array(
179 )) {
180 $pane = $this->_advanceSearchPanesDateFilter($paneRef);
181
182 $this->click("css=div.crm-accordion-wrapper {$pane['headerLocator']}");
183 $this->waitForElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}");
184
185 foreach ($pane['fields'] as $fld => $field) {
186 if (!empty($selectFields) && !in_array($fld, $selectFields)) {
187 continue;
188 }
189
190 $fldLocator = isset($field['locator']) ? $field['locator'] : '';
191
192 switch ($field['type']) {
193 case 'text':
194 $this->type($fldLocator, current($field['values']));
195 break;
196
197 case 'select':
198 foreach ($field['values'] as $op) {
199 $this->select($fldLocator, 'label=' . $op);
200 }
201 break;
202
203 case 'checkbox':
204 foreach ($field['values'] as $op) {
205 if (!$this->isChecked($op)) {
206 $this->click($op);
207 }
208 }
209 break;
210
211 case 'radio':
212 foreach ($field['values'] as $op) {
213 $this->click($op);
214 }
215 break;
216
217 case 'date':
218 $this->webtestFillDate($fldLocator, current($field['values']));
219 break;
220 }
221 }
222 }
223
224 /**
225 * @param null $paneRef
226 *
227 * @return array
228 */
229 function _advanceSearchPanesDateFilter($paneRef = NULL) {
230 static $_advance_search_panes;
231
232 if (!isset($_advance_search_panes) || empty($_advance_search_panes)) {
233 $_advance_search_panes = array(
234 'activity' =>
235 array(
236 'headerLocator' => 'div#activity',
237 'bodyLocator' => 'select#activity_date_relative',
238 'title' => 'Activities',
239 'fields' =>
240 array(
241 'Activity Dates' =>
242 array(
243 'type' => 'select',
244 'locator' => 'activity_date_relative',
245 'values' => array('This Year'),
246 ),
247 ),
248 ),
249 'demographics' =>
250 array(
251 'headerLocator' => 'div#demographics',
252 'bodyLocator' => 'input#birth_date_low_display',
253 'title' => 'Demographics',
254 'fields' =>
255 array(
256 'Deceased Dates' =>
257 array(
258 'type' => 'select',
259 'locator' => 'deceased_date_relative',
260 'values' => array('This Quarter'),
261 ),
262 ),
263 ),
264 'change_log' =>
265 array(
266 'headerLocator' => 'div#changeLog',
267 'bodyLocator' => 'input#changed_by',
268 'title' => 'Change Log',
269 'fields' =>
270 array(
271 'Modified Between' =>
272 array(
273 'type' => 'select',
274 'locator' => 'log_date_relative',
275 'values' => array('This Week'),
276 ),
277 ),
278 ),
279 'mailing' =>
280 array(
281 'headerLocator' => 'div#CiviMail',
282 'bodyLocator' => 'select#mailing_date_relative',
283 'title' => 'Mailings',
284 'fields' =>
285 array(
286 'Mailing Date' =>
287 array(
288 'type' => 'select',
289 'locator' => 'mailing_date_relative',
290 'values' => array('Prior to Previous Quarter'),
291 ),
292 ),
293 ),
294
295 'contribution' =>
296 array(
297 'headerLocator' => 'div#CiviContribute',
298 'bodyLocator' => 'select#financial_type_id',
299 'title' => 'Contributions',
300 'fields' =>
301 array(
302 'Contribution Dates' =>
303 array(
304 'type' => 'select',
305 'locator' => 'contribution_date_relative',
306 'values' => array('This Day'),
307 ),
308 ),
309 ),
310 'pledge' =>
311 array(
312 'headerLocator' => 'div#CiviPledge',
313 'bodyLocator' => 'select#pledge_payment_date_relative',
314 'title' => 'Pledges',
315 'fields' =>
316 array(
317 'Contribution Dates' =>
318 array(
319 'type' => 'select',
320 'locator' => 'pledge_payment_date_relative',
321 'values' => array('Prior to Previous Month'),
322 ),
323 ),
324 ),
325 'membership' =>
326 array(
327 'headerLocator' => 'div#CiviMember',
328 'bodyLocator' => 'input#member_source',
329 'title' => 'Memberships',
330 'fields' =>
331 array(
332 'Member Since' =>
333 array(
334 'type' => 'select',
335 'locator' => 'member_join_date_relative',
336 'values' => array('Previous Year'),
337 ),
338
339 ),
340 ),
341 'event' =>
342 array(
343 'headerLocator' => 'div#CiviEvent',
344 'bodyLocator' => 'input#event_id',
345 'title' => 'Events',
346 'fields' =>
347 array(
348 'Event Dates' =>
349 array(
350 'type' => 'select',
351 'locator' => 'event_relative',
352 'values' => array('Previous Week'),
353 ),
354 ),
355 ),
356
357 );
358 }
359
360 if ($paneRef) {
361 return $_advance_search_panes[$paneRef];
362 }
363
364 return $_advance_search_panes;
365 }
366 }
367