3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Contact_AdvanceSearchPrivacyOptionsTest
32 class WebTest_Contact_AdvanceSearchPrivacyOptionsTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testSearchForPrivacyOptions() {
39 $this->webtestLogin();
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'),
46 $randString = substr(sha1(rand()), 0, 7);
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'),
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']);
59 //advance search for created contacts
60 $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh');
61 $allPrivacyOptions = array(
69 $this->_addPrivacyCriteria('include', $privacyOptions['dn_phone_mail'], 'OR', $allPrivacyOptions);
70 $this->click('_qf_Advanced_refresh');
71 $this->waitForPageToLoad($this->getTimeoutMsec());
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'])) {
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());
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'])) {
90 $this->assertTrue($assertCheck, 'Do not phone / mail assertion failed using criteria(exclude , OR )');
92 $this->_addPrivacyCriteria('include', $privacyOptions['dn_phone_mail'], 'AND', $allPrivacyOptions);
93 $this->click('_qf_Advanced_refresh');
94 $this->waitForPageToLoad($this->getTimeoutMsec());
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'])) {
100 $assertCheck = FALSE;
102 $this->assertTrue($assertCheck, 'Do not phone / mail assertion failed using criteria(include , AND )');
104 $this->_addPrivacyCriteria('exclude', $privacyOptions['dn_phone_mail'], 'AND', $allPrivacyOptions);
105 $this->click('_qf_Advanced_refresh');
106 $this->waitForPageToLoad($this->getTimeoutMsec());
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'])) {
112 $assertCheck = FALSE;
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());
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'])) {
123 $assertCheck = FALSE;
125 $this->assertTrue($assertCheck, 'Do not trade / sms assertion failed using criteria(include , AND )');
130 * @param $privacyOptions
131 * @param $privacyOperator
132 * @param $allPrivacyOptions
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);
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}']");
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']");
158 * @param string $firstName
159 * @param string $lastName
163 public function _searchSortNameCriteria($firstName, $lastName) {
164 //type in the criteria
165 $this->type("sort_name", "{$lastName}, {$firstName}");
167 $this->click("_qf_Advanced_refresh");
169 $this->waitForPageToLoad($this->getTimeoutMsec());
171 //return its presence
172 return $this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr/td[3]/a[text()='{$lastName}, {$firstName}']");
176 * @param $privacyOption
180 public function getOptionVal($privacyOption) {
181 if ($privacyOption == 'do_not_phone') {
182 $privacyOptionVal = 'Do not phone';
184 elseif ($privacyOption == 'do_not_mail') {
185 $privacyOptionVal = 'Do not mail';
187 elseif ($privacyOption == 'do_not_email') {
188 $privacyOptionVal = 'Do not email';
190 elseif ($privacyOption == 'do_not_trade') {
191 $privacyOptionVal = 'Do not trade';
193 elseif ($privacyOption == 'do_not_sms') {
194 $privacyOptionVal = 'Do not sms';
196 return $privacyOptionVal;
200 * @param string $firstName
201 * @param string $lastName
204 public function _addIndividual($firstName, $lastName, $options) {
206 $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
209 $this->type("first_name", $firstName);
212 $this->type("last_name", $lastName);
215 $this->type("email_1_email", "{$firstName}@{$lastName}.com");
218 $this->type("phone_1_phone", "2222-4444");
220 foreach ($options as $option) {
221 //Select preferred method for Privacy
222 $this->click("privacy_{$option}");
226 $this->click("_qf_Contact_upload_view");
227 $this->waitForPageToLoad($this->getTimeoutMsec());
228 $this->waitForText('crm-notification-container', "{$firstName} {$lastName} has been created.");