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