Merge pull request #4875 from civicrm/minor-fix
[civicrm-core.git] / tests / phpunit / WebTest / Contact / PrivacyOptionSearchTest.php
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_PrivacyOptionSearchTest
31 */
32 class WebTest_Contact_PrivacyOptionSearchTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testPrivacyOptionSearch() {
39 $this->webtestLogin();
40 $this->waitForPageToLoad($this->getTimeoutMsec());
41
42 // Add new group.
43 $this->openCiviPage('group/add', 'reset=1', "_qf_Edit_upload");
44
45 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
46 $this->type("title", $groupName);
47
48 // Fill description.
49 $this->type("description", "Adding new group.");
50
51 // Check Access Control.
52 $this->click("group_type[1]");
53
54 // Clicking save.
55 $this->click("_qf_Edit_upload");
56 $this->waitForPageToLoad($this->getTimeoutMsec());
57
58 // Add Contact1.
59 $fname1 = substr(sha1(rand()), 0, 7);
60 $lname1 = substr(sha1(rand()), 0, 7);
61 $this->openCiviPage("contact/add", "reset=1&ct=Individual", '_qf_Contact_upload_view-bottom');
62 $this->type('first_name', $fname1);
63 $this->type('last_name', $lname1);
64 $email1 = $fname1 . '@example.org';
65 $this->type('email_1_email', $email1);
66
67 //click 'Communication Preferences' Panel
68 $this->click("commPrefs");
69 $this->waitForElementPresent("preferred_mail_format");
70 $this->click("privacy_do_not_phone");
71 $this->click("privacy_do_not_email");
72 $this->click("privacy_do_not_mail");
73 $this->click("privacy_do_not_sms");
74
75 $this->click('_qf_Contact_upload_view-bottom');
76 $this->waitForPageToLoad($this->getTimeoutMsec());
77
78 // Add contact to the group.
79 $this->click("css=li#tab_group a");
80 $this->waitForElementPresent("group_id");
81 $this->select("group_id", "label=$groupName");
82 $this->click("_qf_GroupContact_next");
83
84 // Add Contact2.
85 $fname2 = substr(sha1(rand()), 0, 7);
86 $lname2 = substr(sha1(rand()), 0, 7);
87 $this->openCiviPage("contact/add", "reset=1&ct=Individual", '_qf_Contact_upload_view-bottom');
88 $this->type('first_name', $fname2);
89 $this->type('last_name', $lname2);
90 $email2 = $fname2 . '@example.org';
91 $this->type('email_1_email', $email2);
92
93 //click 'Communication Preferences' Panel
94 $this->click("commPrefs");
95 $this->waitForElementPresent("preferred_mail_format");
96 $this->click("privacy_do_not_phone");
97 $this->click("privacy_do_not_email");
98 $this->click("privacy_do_not_trade");
99
100 $this->click('_qf_Contact_upload_view-bottom');
101 $this->waitForPageToLoad($this->getTimeoutMsec());
102
103 // Add contact to the group.
104 $this->click("css=li#tab_group a");
105 $this->waitForElementPresent("group_id");
106 $this->select("group_id", "label=$groupName");
107 $this->click("_qf_GroupContact_next");
108
109 // Go to advance search, check for 'Exclude' option.
110 $this->openCiviPage("contact/search/advanced", "reset=1");
111
112 $this->select("xpath=//form[@id='Advanced']//table[1]/tbody/tr[2]/td[2]//select[1]", "label={$groupName}");
113 $this->waitForTextPresent($groupName);
114
115 $this->select("xpath=//form[@id='Advanced']//table[1]/tbody/tr[5]/td[1]/table[1]/tbody/tr[2]/td[1]//select[1]", 'value=do_not_phone');
116 $this->waitForTextPresent('Do not phone');
117
118 $this->select("xpath=//form[@id='Advanced']//table[1]/tbody/tr[5]/td[1]/table[1]/tbody/tr[2]/td[1]//select[1]", 'value=do_not_email');
119 $this->waitForTextPresent('Do not email');
120
121 $this->click("_qf_Advanced_refresh");
122 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
123
124 $this->assertTrue($this->isTextPresent("None found."));
125
126 // Go to advance search, check for 'Include' + 'OR' options.
127 $this->openCiviPage("contact/search/advanced", "reset=1");
128
129 $this->select("xpath=//form[@id='Advanced']//table[1]/tbody/tr[2]/td[2]//select[1]", "label={$groupName}");
130 $this->waitForTextPresent($groupName);
131
132 $this->click("xpath=//form[@id='Advanced']//table[1]/tbody/tr[5]/td[1]/table[1]/tbody/tr[1]/td[1]//input[2]");
133
134 $this->select("xpath=//form[@id='Advanced']//table[1]/tbody/tr[5]/td[1]/table[1]/tbody/tr[2]/td[1]//select[1]", 'value=do_not_phone');
135 $this->waitForTextPresent('Do not phone');
136
137 $this->select("xpath=//form[@id='Advanced']//table[1]/tbody/tr[5]/td[1]/table[1]/tbody/tr[2]/td[1]//select[1]", 'value=do_not_email');
138 $this->waitForTextPresent('Do not email');
139
140 $this->click("_qf_Advanced_refresh");
141 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
142 $this->assertTrue($this->isTextPresent("2 Contacts"));
143 $this->assertTrue($this->isTextPresent("$lname1, $fname1"));
144 $this->assertTrue($this->isTextPresent("$lname2, $fname2"));
145
146 // Go to advance search, check for 'Include' + 'AND' options.
147 $this->openCiviPage("contact/search/advanced", "reset=1");
148
149 $this->select("xpath=//form[@id='Advanced']//table[1]/tbody/tr[2]/td[2]//select[1]", "label={$groupName}");
150 $this->waitForTextPresent($groupName);
151
152 $this->click("xpath=//form[@id='Advanced']//table[1]/tbody/tr[5]/td[1]/table[1]/tbody/tr[1]/td[1]//input[2]");
153
154 $this->select("xpath=//form[@id='Advanced']//table[1]/tbody/tr[5]/td[1]/table[1]/tbody/tr[2]/td[1]//select[1]", 'value=do_not_phone');
155 $this->waitForTextPresent('Do not phone');
156
157 $this->select("xpath=//form[@id='Advanced']//table[1]/tbody/tr[5]/td[1]/table[1]/tbody/tr[2]/td[1]//select[1]", 'value=do_not_trade');
158 $this->waitForTextPresent('Do not trade');
159
160 $this->select('privacy_operator', 'value=AND');
161
162 $this->click("_qf_Advanced_refresh");
163 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
164 $this->assertTrue($this->isTextPresent("1 Contact"));
165 $this->assertTrue($this->isTextPresent("$lname2, $fname2"));
166 }
167 }