| 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_AdvanceSearchPrivacyOptionsTest |
| 31 | */ |
| 32 | class WebTest_Contact_AdvanceSearchPrivacyOptionsTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testSearchForPrivacyOptions() { |
| 39 | $this->webtestLogin(); |
| 40 | |
| 41 | $privacyOptions = array( |
| 42 | 'dn_phone_mail' => array('do_not_phone', 'do_not_mail'), |
| 43 | 'dn_phone_email' => array('do_not_phone', 'do_not_email'), |
| 44 | 'dn_trade_sms' => array('do_not_trade', 'do_not_sms'), |
| 45 | ); |
| 46 | $randString = substr(sha1(rand()), 0, 7); |
| 47 | |
| 48 | $contactsReffOptions = array( |
| 49 | 'dn_phone_mail' => array('first_name' => $randString . 'John', 'last_name' => $randString . 'Smith'), |
| 50 | 'dn_phone_email' => array('first_name' => $randString . 'Jeff', 'last_name' => $randString . 'Adams'), |
| 51 | 'dn_trade_sms' => array('first_name' => $randString . 'Rocky', 'last_name' => $randString . 'Stanley'), |
| 52 | ); |
| 53 | |
| 54 | //creating individuals |
| 55 | $this->_addIndividual($contactsReffOptions['dn_phone_mail']['first_name'], $contactsReffOptions['dn_phone_mail']['last_name'], $privacyOptions['dn_phone_mail']); |
| 56 | $this->_addIndividual($contactsReffOptions['dn_phone_email']['first_name'], $contactsReffOptions['dn_phone_email']['last_name'], $privacyOptions['dn_phone_email']); |
| 57 | $this->_addIndividual($contactsReffOptions['dn_trade_sms']['first_name'], $contactsReffOptions['dn_trade_sms']['last_name'], $privacyOptions['dn_trade_sms']); |
| 58 | |
| 59 | //advance search for created contacts |
| 60 | $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); |
| 61 | $allPrivacyOptions = array( |
| 62 | 'do_not_phone', |
| 63 | 'do_not_mail', |
| 64 | 'do_not_email', |
| 65 | 'do_not_sms', |
| 66 | 'do_not_trade', |
| 67 | ); |
| 68 | |
| 69 | $this->_addPrivacyCriteria('include', $privacyOptions['dn_phone_mail'], 'OR', $allPrivacyOptions); |
| 70 | $this->click('_qf_Advanced_refresh'); |
| 71 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 72 | |
| 73 | if ($this->_searchSortNameCriteria($contactsReffOptions['dn_phone_mail']['first_name'], $contactsReffOptions['dn_phone_mail']['last_name']) && $this->_searchSortNameCriteria($contactsReffOptions['dn_phone_mail']['first_name'], $contactsReffOptions['dn_phone_mail']['last_name']) && !$this->_searchSortNameCriteria($contactsReffOptions['dn_trade_sms']['first_name'], $contactsReffOptions['dn_trade_sms']['last_name'])) { |
| 74 | $assertCheck = TRUE; |
| 75 | } |
| 76 | else { |
| 77 | $assertCheck = FALSE; |
| 78 | } |
| 79 | $this->assertTrue($assertCheck, 'Do not phone / mail assertion failed using criteria(include , OR )'); |
| 80 | $this->_addPrivacyCriteria('exclude', $privacyOptions['dn_phone_mail'], 'OR', $allPrivacyOptions); |
| 81 | $this->click('_qf_Advanced_refresh'); |
| 82 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 83 | |
| 84 | if (!$this->_searchSortNameCriteria($contactsReffOptions['dn_phone_mail']['first_name'], $contactsReffOptions['dn_phone_mail']['last_name']) && $this->_searchSortNameCriteria($contactsReffOptions['dn_trade_sms']['first_name'], $contactsReffOptions['dn_trade_sms']['last_name'])) { |
| 85 | $assertCheck = TRUE; |
| 86 | } |
| 87 | else { |
| 88 | $assertCheck = FALSE; |
| 89 | } |
| 90 | $this->assertTrue($assertCheck, 'Do not phone / mail assertion failed using criteria(exclude , OR )'); |
| 91 | |
| 92 | $this->_addPrivacyCriteria('include', $privacyOptions['dn_phone_mail'], 'AND', $allPrivacyOptions); |
| 93 | $this->click('_qf_Advanced_refresh'); |
| 94 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 95 | |
| 96 | if ($this->_searchSortNameCriteria($contactsReffOptions['dn_phone_mail']['first_name'], $contactsReffOptions['dn_phone_mail']['last_name']) && !$this->_searchSortNameCriteria($contactsReffOptions['dn_phone_email']['first_name'], $contactsReffOptions['dn_phone_email']['last_name']) && !$this->_searchSortNameCriteria($contactsReffOptions['dn_trade_sms']['first_name'], $contactsReffOptions['dn_trade_sms']['last_name'])) { |
| 97 | $assertCheck = TRUE; |
| 98 | } |
| 99 | else { |
| 100 | $assertCheck = FALSE; |
| 101 | } |
| 102 | $this->assertTrue($assertCheck, 'Do not phone / mail assertion failed using criteria(include , AND )'); |
| 103 | |
| 104 | $this->_addPrivacyCriteria('exclude', $privacyOptions['dn_phone_mail'], 'AND', $allPrivacyOptions); |
| 105 | $this->click('_qf_Advanced_refresh'); |
| 106 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 107 | |
| 108 | if (!$this->_searchSortNameCriteria($contactsReffOptions['dn_phone_mail']['first_name'], $contactsReffOptions['dn_phone_mail']['last_name']) && $this->_searchSortNameCriteria($contactsReffOptions['dn_trade_sms']['first_name'], $contactsReffOptions['dn_trade_sms']['last_name'])) { |
| 109 | $assertCheck = TRUE; |
| 110 | } |
| 111 | else { |
| 112 | $assertCheck = FALSE; |
| 113 | } |
| 114 | $this->assertTrue($assertCheck, 'Do not phone / mail assertion failed using criteria(exclude , AND )'); |
| 115 | $this->_addPrivacyCriteria('include', $privacyOptions['dn_trade_sms'], 'AND', $allPrivacyOptions); |
| 116 | $this->click('_qf_Advanced_refresh'); |
| 117 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 118 | |
| 119 | if (!$this->_searchSortNameCriteria($contactsReffOptions['dn_phone_mail']['first_name'], $contactsReffOptions['dn_phone_mail']['last_name']) && !$this->_searchSortNameCriteria($contactsReffOptions['dn_phone_email']['first_name'], $contactsReffOptions['dn_phone_email']['last_name']) && $this->_searchSortNameCriteria($contactsReffOptions['dn_trade_sms']['first_name'], $contactsReffOptions['dn_trade_sms']['last_name'])) { |
| 120 | $assertCheck = TRUE; |
| 121 | } |
| 122 | else { |
| 123 | $assertCheck = FALSE; |
| 124 | } |
| 125 | $this->assertTrue($assertCheck, 'Do not trade / sms assertion failed using criteria(include , AND )'); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @param $inEx |
| 130 | * @param $privacyOptions |
| 131 | * @param $privacyOperator |
| 132 | * @param $allPrivacyOptions |
| 133 | */ |
| 134 | public function _addPrivacyCriteria($inEx, $privacyOptions, $privacyOperator, $allPrivacyOptions) { |
| 135 | $inExId = ($inEx == 'include') ? 'CIVICRM_QFID_2_privacy_toggle' : 'CIVICRM_QFID_1_privacy_toggle'; |
| 136 | $this->click($inExId); |
| 137 | $this->select('privacy_operator', "{$privacyOperator}"); |
| 138 | foreach ($privacyOptions as $privacyOption) { |
| 139 | $privacyOptionVal = $this->getOptionVal($privacyOption); |
| 140 | |
| 141 | if (!$this->isElementPresent("xpath=//div[@id='s2id_privacy_options']//ul//li//div[text()='{$privacyOptionVal}']")) { |
| 142 | $this->select('privacy_options', "value={$privacyOption}"); |
| 143 | $this->waitForElementPresent("xpath=//div[@id='s2id_privacy_options']//ul//li//div[text()='{$privacyOptionVal}']"); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | foreach ($allPrivacyOptions as $allPrivacyOption) { |
| 148 | if (!in_array($allPrivacyOption, $privacyOptions)) { |
| 149 | $privacyOptionVal = $this->getOptionVal($allPrivacyOption); |
| 150 | if ($this->isElementPresent("xpath=//div[@id='s2id_privacy_options']//ul//li//div[text()='{$privacyOptionVal}']")) { |
| 151 | $this->click("xpath=//div[@id='s2id_privacy_options']//ul//li//div[text()='{$privacyOptionVal}']/../a[@class='select2-search-choice-close']"); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * @param string $firstName |
| 159 | * @param string $lastName |
| 160 | * |
| 161 | * @return bool |
| 162 | */ |
| 163 | public function _searchSortNameCriteria($firstName, $lastName) { |
| 164 | //type in the criteria |
| 165 | $this->type("sort_name", "{$lastName}, {$firstName}"); |
| 166 | |
| 167 | $this->click("_qf_Advanced_refresh"); |
| 168 | |
| 169 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 170 | |
| 171 | //return its presence |
| 172 | return $this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr/td[3]/a[text()='{$lastName}, {$firstName}']"); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * @param $privacyOption |
| 177 | * |
| 178 | * @return string |
| 179 | */ |
| 180 | public function getOptionVal($privacyOption) { |
| 181 | if ($privacyOption == 'do_not_phone') { |
| 182 | $privacyOptionVal = 'Do not phone'; |
| 183 | } |
| 184 | elseif ($privacyOption == 'do_not_mail') { |
| 185 | $privacyOptionVal = 'Do not mail'; |
| 186 | } |
| 187 | elseif ($privacyOption == 'do_not_email') { |
| 188 | $privacyOptionVal = 'Do not email'; |
| 189 | } |
| 190 | elseif ($privacyOption == 'do_not_trade') { |
| 191 | $privacyOptionVal = 'Do not trade'; |
| 192 | } |
| 193 | elseif ($privacyOption == 'do_not_sms') { |
| 194 | $privacyOptionVal = 'Do not sms'; |
| 195 | } |
| 196 | return $privacyOptionVal; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * @param string $firstName |
| 201 | * @param string $lastName |
| 202 | * @param $options |
| 203 | */ |
| 204 | public function _addIndividual($firstName, $lastName, $options) { |
| 205 | |
| 206 | $this->openCiviPage('contact/add', 'reset=1&ct=Individual'); |
| 207 | |
| 208 | //fill in first name |
| 209 | $this->type("first_name", $firstName); |
| 210 | |
| 211 | //fill in last name |
| 212 | $this->type("last_name", $lastName); |
| 213 | |
| 214 | //fill in email |
| 215 | $this->type("email_1_email", "{$firstName}@{$lastName}.com"); |
| 216 | |
| 217 | //fill in phone |
| 218 | $this->type("phone_1_phone", "2222-4444"); |
| 219 | |
| 220 | foreach ($options as $option) { |
| 221 | //Select preferred method for Privacy |
| 222 | $this->click("privacy_{$option}"); |
| 223 | } |
| 224 | |
| 225 | // Clicking save. |
| 226 | $this->click("_qf_Contact_upload_view"); |
| 227 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 228 | $this->waitForText('crm-notification-container', "{$firstName} {$lastName} has been created."); |
| 229 | |
| 230 | } |
| 231 | } |