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