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