Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 26 | |
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contact_AdvanceSearchPrivacyOptionsTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contact_AdvanceSearchPrivacyOptionsTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testSearchForPrivacyOptions() { |
6a488035 TO |
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 | |
d8bd5fb9 | 60 | $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); |
6a488035 TO |
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 | ||
6a488035 TO |
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()); | |
76e86fd8 | 118 | |
6a488035 TO |
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 | ||
4cbe18b8 EM |
128 | /** |
129 | * @param $inEx | |
130 | * @param $privacyOptions | |
131 | * @param $privacyOperator | |
132 | * @param $allPrivacyOptions | |
133 | */ | |
00be9182 | 134 | public function _addPrivacyCriteria($inEx, $privacyOptions, $privacyOperator, $allPrivacyOptions) { |
6a488035 TO |
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); | |
76e86fd8 | 140 | |
b5e4fcd9 | 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}']"); | |
6a488035 TO |
144 | } |
145 | } | |
76e86fd8 | 146 | |
6a488035 TO |
147 | foreach ($allPrivacyOptions as $allPrivacyOption) { |
148 | if (!in_array($allPrivacyOption, $privacyOptions)) { | |
149 | $privacyOptionVal = $this->getOptionVal($allPrivacyOption); | |
b5e4fcd9 | 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']"); | |
6a488035 TO |
152 | } |
153 | } | |
154 | } | |
155 | } | |
76e86fd8 | 156 | |
4cbe18b8 | 157 | /** |
100fef9d CW |
158 | * @param string $firstName |
159 | * @param string $lastName | |
4cbe18b8 EM |
160 | * |
161 | * @return bool | |
162 | */ | |
00be9182 | 163 | public function _searchSortNameCriteria($firstName, $lastName) { |
6a488035 | 164 | //type in the criteria |
76e86fd8 CW |
165 | $this->type("sort_name", "{$lastName}, {$firstName}"); |
166 | ||
167 | $this->click("_qf_Advanced_refresh"); | |
168 | ||
6a488035 | 169 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
76e86fd8 | 170 | |
6a488035 TO |
171 | //return its presence |
172 | return $this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr/td[3]/a[text()='{$lastName}, {$firstName}']"); | |
173 | } | |
76e86fd8 | 174 | |
4cbe18b8 EM |
175 | /** |
176 | * @param $privacyOption | |
177 | * | |
178 | * @return string | |
179 | */ | |
00be9182 | 180 | public function getOptionVal($privacyOption) { |
6a488035 TO |
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 | ||
4cbe18b8 | 199 | /** |
100fef9d CW |
200 | * @param string $firstName |
201 | * @param string $lastName | |
4cbe18b8 EM |
202 | * @param $options |
203 | */ | |
00be9182 | 204 | public function _addIndividual($firstName, $lastName, $options) { |
6a488035 | 205 | |
d8bd5fb9 | 206 | $this->openCiviPage('contact/add', 'reset=1&ct=Individual'); |
76e86fd8 | 207 | |
6a488035 TO |
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 | } | |
76e86fd8 | 224 | |
6a488035 TO |
225 | // Clicking save. |
226 | $this->click("_qf_Contact_upload_view"); | |
227 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
6c5f7368 | 228 | $this->waitForText('crm-notification-container', "{$firstName} {$lastName} has been created."); |
6a488035 TO |
229 | |
230 | } | |
96025800 | 231 | |
6a488035 | 232 | } |