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