Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-01-12-16-09-32
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / PetitionUsageScenarioTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
25*/
26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Campaign_PetitionUsageScenarioTest
31 */
6a488035
TO
32class WebTest_Campaign_PetitionUsageScenarioTest extends CiviSeleniumTestCase {
33
6a488035
TO
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testPetitionUsageScenario() {
42daf119 39 $this->webtestLogin('admin');
6a488035 40
6a488035 41 // Enable CiviCampaign module if necessary
b9715b8a 42 $this->enableComponents("CiviCampaign");
6a488035
TO
43
44 // handle permissions early
45
46 // let's give permission 'sign CiviCRM Petition' to anonymous user.
47 $permissions = array(
48 // give profile related permision
49 "edit-1-sign-civicrm-petition",
50 "edit-1-profile-create",
51 "edit-1-profile-edit",
52 "edit-1-profile-listings",
53 "edit-1-profile-view",
54 // now give full permissions to CiviPetition to registered user
55 "edit-2-administer-civicampaign",
56 "edit-2-manage-campaign",
57 "edit-2-gotv-campaign-contacts",
58 "edit-2-interview-campaign-contacts",
59 "edit-2-release-campaign-contacts",
60 "edit-2-reserve-campaign-contacts",
61 "edit-2-sign-civicrm-petition",
62 );
63 $this->changePermissions($permissions);
64
42daf119
CW
65 // Log in as normal user
66 $this->webtestLogin();
6a488035 67
42daf119 68 /////////////// Create Campaign ///////////////////////////////
6a488035 69
42daf119 70 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
6a488035 71
6a488035
TO
72 $title = substr(sha1(rand()), 0, 7);
73 $this->type("title", "$title Campaign");
74
75 // select the campaign type
76 $this->select("campaign_type_id", "value=2");
77
78 // fill in the description
79 $this->type("description", "This is a test campaign");
80
81 // include groups for the campaign
fe725ccb 82 $this->addSelection("includeGroups", "label=Advisory Board");
6a488035 83 $this->click("//option[@value=4]");
6a488035
TO
84
85 // fill the end date for campaign
86 $this->webtestFillDate("end_date", "+1 year");
87
88 // select campaign status
89 $this->select("status_id", "value=2");
90
91 // click save
d226f7d8 92 $this->clickLink('_qf_Campaign_upload-bottom');
6a488035 93
d226f7d8 94 $this->waitForText('crm-notification-container', "Campaign $title Campaign has been saved.");
6a488035
TO
95
96 ////////////// Create petition using New Individual profile //////////////////////
97
071a6d2e 98 $this->openCiviPage("petition/add", "reset=1", "_qf_Petition_next-bottom");
6a488035
TO
99
100 // fill petition tile.
101 $title = substr(sha1(rand()), 0, 7);
102 $this->type("title", "$title Petition");
103
104 // fill introduction
105 //$this->type("cke_instructions", "This is introduction of $title Petition");
106
107 // select campaign
108 $this->select("campaign_id", "value=1");
109
110 // select profile
111 $this->select("contact_profile_id", "value=4");
112
113 // click save
d226f7d8 114 $this->clickLink('_qf_Petition_next-bottom');
6a488035 115
d226f7d8 116 $this->waitForText('crm-notification-container', "Petition has been saved.");
6a488035
TO
117
118 $this->waitForElementPresent("link=Add Petition");
fe725ccb 119 $this->waitForElementPresent("search_form_petition");
6a488035
TO
120 $this->click("search_form_petition");
121 $this->type("petition_title", $title);
122
123 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
fe725ccb
RK
124 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']/ul/li[2]/a[text()='Sign']");
125 $url = $this->getAttribute("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']/ul/li[2]/a[text()='Sign']@href");
6a488035
TO
126
127 ////////////// Retrieve Sign Petition Url /////////////////////////
128
129 // logout and sign as anonymous.
42daf119 130 $this->webtestLogout();
6a488035
TO
131
132 // go to the link that you will be sign as anonymous
133 $this->open($url);
134 $this->waitForElementPresent("_qf_Signature_next-bottom");
135
136 // fill first name
137 $firstName = substr(sha1(rand()), 0, 7);
138 $this->type("first_name", $firstName);
139
140 // fill last name
141 $lastName = substr(sha1(rand()), 0, 7);
142 $this->type("last_name", $lastName);
143
144 // fill email
145 $email = $firstName . "@" . $lastName . ".com";
146 $this->type("email-Primary", $email);
147
148 // click Sign the petition.
d226f7d8
RN
149 $this->clickLink('_qf_Signature_next-bottom', NULL);
150 $this->waitForText('page-title', "Thank You");
6a488035
TO
151
152 // login
6a488035
TO
153 $this->webtestLogin();
154
42daf119 155 $this->openCiviPage("campaign", "reset=1&subPage=petition", "link=Add Petition");
6a488035
TO
156
157 // check for unconfirmed petition signature
fe725ccb 158 $this->waitForElementPresent("search_form_petition");
6a488035
TO
159 $this->click("search_form_petition");
160 $this->type("petition_title", $title);
161 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
162
f78f9745
RK
163 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']");
164 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']/ul/li[3]/a[text()='Signatures']");
6a488035
TO
165 $this->waitForPageToLoad($this->getTimeoutMsec());
166
167 // verify tabular data
168 $expected = array(
169 2 => 'Petition',
170 3 => "$title Petition",
814588fc 171 4 => "$lastName, $firstName",
6a488035
TO
172 5 => "$lastName, $firstName",
173 8 => 'Scheduled',
174 );
175
176 foreach ($expected as $column => $value) {
642aa483 177 $this->verifyText("xpath=//div[@class='crm-search-results']/table/tbody/tr[2]/td[$column]/", preg_quote($value));
6a488035 178 }
76e86fd8 179
6a488035 180 // ONCE MORE, NO EMAIL VERIFICATION AND CUSTOM THANK-YOU
071a6d2e 181 $this->openCiviPage("petition/add", "reset=1", "_qf_Petition_next-bottom");
6a488035
TO
182
183 // fill petition tile.
184 $title = substr(sha1(rand()), 0, 7);
185 $this->type("title", "$title Petition");
186
187 // fill introduction
188 //$this->type("cke_instructions", "This is introduction of $title Petition");
189
190 // select campaign
191 $this->select("campaign_id", "value=1");
192
193 // select profile
194 $this->select("contact_profile_id", "value=4");
195
196 // bypass email confirmation
197 $this->click("bypass_confirm");
198
199 // set custom thank-you title and text
200 $this->type('thankyou_title', "Awesome $title donation");
201 $this->fillRichTextField('thankyou_text', "Thank you for your kind contribution to support $title", 'CKEditor');
202
203 // click save
d226f7d8 204 $this->clickLink('_qf_Petition_next-bottom');
6a488035 205
d226f7d8 206 $this->waitForText('crm-notification-container', "Petition has been saved.");
6a488035
TO
207
208 $this->waitForElementPresent("link=Add Petition");
209
fe725ccb 210 $this->waitForElementPresent("search_form_petition");
6a488035
TO
211 $this->click("search_form_petition");
212 $this->type("petition_title", $title);
213
214 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
215
fe725ccb
RK
216 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']/ul/li[2]/a[text()='Sign']");
217 $url = $this->getAttribute("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']/ul/li[2]/a[text()='Sign']@href");
6a488035
TO
218
219 // logout and sign as anonymous.
42daf119 220 $this->webtestLogout();
6a488035
TO
221
222 // go to the link that you will be sign as anonymous
223 $this->open($url);
224 $this->waitForElementPresent("_qf_Signature_next-bottom");
225
226 // fill first name
227 $firstName = substr(sha1(rand()), 0, 7);
228 $this->type("first_name", $firstName);
229
230 // fill last name
231 $lastName = substr(sha1(rand()), 0, 7);
232 $this->type("last_name", $lastName);
233
234 // fill email
235 $email = $firstName . "@" . $lastName . ".com";
236 $this->type("email-Primary", $email);
237
238 // click Sign the petition.
d226f7d8 239 $this->clickLink('_qf_Signature_next-bottom', 'thankyou_text');
76e86fd8 240
6a488035 241 // check that thank-you page has appropriate title and message
d226f7d8
RN
242 $this->waitForText('page-title', "Awesome $title donation");
243 $this->waitForText('thankyou_text', "Thank you for your kind contribution to support $title");
6a488035
TO
244
245 // login
6a488035
TO
246 $this->webtestLogin();
247
42daf119 248 $this->openCiviPage("campaign", "reset=1&subPage=petition", "link=Add Petition");
6a488035
TO
249
250 // check for confirmed petition signature
fe725ccb 251 $this->waitForElementPresent("search_form_petition");
6a488035
TO
252 $this->click("search_form_petition");
253 $this->type("petition_title", $title);
254 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
255
ff6ef696 256 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']");
d25d8bbf 257 $this->click("xpath=//table[@class='petitions dataTable no-footer']/tbody/tr/td[10]/span[2][text()='more']/ul/li[3]/a[text()='Signatures']");
6a488035
TO
258 $this->waitForPageToLoad($this->getTimeoutMsec());
259
260 // verify tabular data
261 $expected = array(
262 2 => 'Petition',
263 3 => "$title Petition",
814588fc 264 4 => "$lastName, $firstName",
6a488035
TO
265 5 => "$lastName, $firstName",
266 8 => 'Completed',
267 );
268
269 foreach ($expected as $column => $value) {
642aa483 270 $this->verifyText("xpath=//div[@class='crm-search-results']/table/tbody/tr[2]/td[$column]/", preg_quote($value));
3fb27458 271 }
6a488035
TO
272 }
273}