Import from SVN (r45945, r596)
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / PetitionUsageScenarioTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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
27
28require_once 'CiviTest/CiviSeleniumTestCase.php';
29class WebTest_Campaign_PetitionUsageScenarioTest extends CiviSeleniumTestCase {
30
31 protected $captureScreenshotOnFailure = TRUE;
32 protected $screenshotPath = '/tmp/';
33 protected $screenshotUrl = 'http://api.dev.civicrm.org/sc/';
34
35 protected function setUp() {
36 parent::setUp();
37 }
38
39 function testPetitionUsageScenario() {
40 // This is the path where our testing install resides.
41 // The rest of URL is defined in CiviSeleniumTestCase base class, in
42 // class attributes.
43 $this->open($this->sboxPath);
44
45 // Logging in. Remember to wait for page to load. In most cases,
46 // you can rely on 30000 as the value that allows your test to pass, however,
47 // sometimes your test might fail because of this. In such cases, it's better to pick one element
48 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
49 // page contents loaded and you can continue your test execution.
50 $this->webtestLogin();
51
52
53 // Enable CiviCampaign module if necessary
54 $this->open($this->sboxPath . "civicrm/admin/setting/component?reset=1");
55 $this->waitForPageToLoad($this->getTimeoutMsec());
56 $this->waitForElementPresent("_qf_Component_next-bottom");
57 $enabledComponents = $this->getSelectOptions("enableComponents-t");
58 if (!in_array("CiviCampaign", $enabledComponents)) {
59 $this->addSelection("enableComponents-f", "label=CiviCampaign");
60 $this->click("//option[@value='CiviCampaign']");
61 $this->click("add");
62 $this->click("_qf_Component_next-bottom");
63 $this->waitForPageToLoad($this->getTimeoutMsec());
64 $this->assertTrue($this->isTextPresent("Your changes have been saved."));
65 }
66
67 // handle permissions early
68
69 // let's give permission 'sign CiviCRM Petition' to anonymous user.
70 $permissions = array(
71 // give profile related permision
72 "edit-1-sign-civicrm-petition",
73 "edit-1-profile-create",
74 "edit-1-profile-edit",
75 "edit-1-profile-listings",
76 "edit-1-profile-view",
77 // now give full permissions to CiviPetition to registered user
78 "edit-2-administer-civicampaign",
79 "edit-2-manage-campaign",
80 "edit-2-gotv-campaign-contacts",
81 "edit-2-interview-campaign-contacts",
82 "edit-2-release-campaign-contacts",
83 "edit-2-reserve-campaign-contacts",
84 "edit-2-sign-civicrm-petition",
85 );
86 $this->changePermissions($permissions);
87
88 /////////////// Create Campaign ///////////////////////////////
89
90 // Go directly to the URL of the screen that you will be add campaign
91 $this->open($this->sboxPath . "civicrm/campaign/add?reset=1");
92
93 // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit
94 // button at the end of this page to show up, to make sure it's fully loaded.
95 $this->waitForElementPresent("_qf_Campaign_upload-bottom");
96
97 // Let's start filling the form with values.
98 $title = substr(sha1(rand()), 0, 7);
99 $this->type("title", "$title Campaign");
100
101 // select the campaign type
102 $this->select("campaign_type_id", "value=2");
103
104 // fill in the description
105 $this->type("description", "This is a test campaign");
106
107 // include groups for the campaign
108 $this->addSelection("includeGroups-f", "label=Advisory Board");
109 $this->click("//option[@value=4]");
110 $this->click("add");
111
112 // fill the end date for campaign
113 $this->webtestFillDate("end_date", "+1 year");
114
115 // select campaign status
116 $this->select("status_id", "value=2");
117
118 // click save
119 $this->click("_qf_Campaign_upload-bottom");
120 $this->waitForPageToLoad($this->getTimeoutMsec());
121
122 $this->assertTrue($this->isTextPresent("Campaign $title Campaign has been saved."), "Status message didn't show up after saving!");
123
124 ////////////// Create petition using New Individual profile //////////////////////
125
126 // Go directly to the URL of the screen that you will be add petition
127 $this->open($this->sboxPath . "civicrm/petition/add?reset=1");
128
129 // button at the end of this page to show up, to make sure it's fully loaded.
130 $this->waitForElementPresent("_qf_Petition_next-bottom");
131
132 // fill petition tile.
133 $title = substr(sha1(rand()), 0, 7);
134 $this->type("title", "$title Petition");
135
136 // fill introduction
137 //$this->type("cke_instructions", "This is introduction of $title Petition");
138
139 // select campaign
140 $this->select("campaign_id", "value=1");
141
142 // select profile
143 $this->select("contact_profile_id", "value=4");
144
145 // click save
146 $this->click("_qf_Petition_next-bottom");
147 $this->waitForPageToLoad($this->getTimeoutMsec());
148
149 $this->assertTrue($this->isTextPresent("Petition has been saved."));
150
151 $this->waitForElementPresent("link=Add Petition");
152
153 $this->waitForElementPresent("petitions");
154 $this->click("search_form_petition");
155 $this->type("petition_title", $title);
156
157 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
158
159 $this->waitForElementPresent("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']/ul/li/a[text()='Sign']");
160 $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");
161
162 ////////////// Retrieve Sign Petition Url /////////////////////////
163
164 // logout and sign as anonymous.
165 $this->open($this->sboxPath . "civicrm/logout?reset=1");
166 $this->waitForElementPresent("edit-submit");
167
168 // go to the link that you will be sign as anonymous
169 $this->open($url);
170 $this->waitForElementPresent("_qf_Signature_next-bottom");
171
172 // fill first name
173 $firstName = substr(sha1(rand()), 0, 7);
174 $this->type("first_name", $firstName);
175
176 // fill last name
177 $lastName = substr(sha1(rand()), 0, 7);
178 $this->type("last_name", $lastName);
179
180 // fill email
181 $email = $firstName . "@" . $lastName . ".com";
182 $this->type("email-Primary", $email);
183
184 // click Sign the petition.
185 $this->click("_qf_Signature_next-bottom");
186 $this->waitForPageToLoad($this->getTimeoutMsec());
187 $this->assertTrue($this->isTextPresent("Thank You"));
188
189 // login
190 $this->open($this->sboxPath);
191 $this->webtestLogin();
192
193 $this->open($this->sboxPath . "civicrm/campaign?reset=1&subPage=petition");
194 $this->waitForPageToLoad($this->getTimeoutMsec());
195 $this->waitForElementPresent("link=Add Petition");
196
197 // check for unconfirmed petition signature
198 $this->waitForElementPresent("petitions");
199 $this->click("search_form_petition");
200 $this->type("petition_title", $title);
201 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
202
203 $this->waitForElementPresent("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']");
204 $this->click("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']/ul/li/a[text()='Signatures']");
205 $this->waitForPageToLoad($this->getTimeoutMsec());
206
207 // verify tabular data
208 $expected = array(
209 2 => 'Petition',
210 3 => "$title Petition",
211 4 => "$firstName $lastName",
212 5 => "$lastName, $firstName",
213 8 => 'Scheduled',
214 );
215
216 foreach ($expected as $column => $value) {
217 $this->verifyText("xpath=//table[@class='selector']/tbody/tr[2]/td[$column]", preg_quote($value));
218 }
219
220 // ONCE MORE, NO EMAIL VERIFICATION AND CUSTOM THANK-YOU
221
222 // Go directly to the URL of the screen that you will be add petition
223 $this->open($this->sboxPath . "civicrm/petition/add?reset=1");
224
225 // button at the end of this page to show up, to make sure it's fully loaded.
226 $this->waitForElementPresent("_qf_Petition_next-bottom");
227
228 // fill petition tile.
229 $title = substr(sha1(rand()), 0, 7);
230 $this->type("title", "$title Petition");
231
232 // fill introduction
233 //$this->type("cke_instructions", "This is introduction of $title Petition");
234
235 // select campaign
236 $this->select("campaign_id", "value=1");
237
238 // select profile
239 $this->select("contact_profile_id", "value=4");
240
241 // bypass email confirmation
242 $this->click("bypass_confirm");
243
244 // set custom thank-you title and text
245 $this->type('thankyou_title', "Awesome $title donation");
246 $this->fillRichTextField('thankyou_text', "Thank you for your kind contribution to support $title", 'CKEditor');
247
248 // click save
249 $this->click("_qf_Petition_next-bottom");
250 $this->waitForPageToLoad($this->getTimeoutMsec());
251
252 $this->assertTrue($this->isTextPresent("Petition has been saved."));
253
254 $this->waitForElementPresent("link=Add Petition");
255
256 $this->waitForElementPresent("petitions");
257 $this->click("search_form_petition");
258 $this->type("petition_title", $title);
259
260 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
261
262 $this->waitForElementPresent("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']/ul/li/a[text()='Sign']");
263 $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");
264
265 // logout and sign as anonymous.
266 $this->open($this->sboxPath . "civicrm/logout?reset=1");
267 $this->waitForElementPresent("edit-submit");
268
269 // go to the link that you will be sign as anonymous
270 $this->open($url);
271 $this->waitForElementPresent("_qf_Signature_next-bottom");
272
273 // fill first name
274 $firstName = substr(sha1(rand()), 0, 7);
275 $this->type("first_name", $firstName);
276
277 // fill last name
278 $lastName = substr(sha1(rand()), 0, 7);
279 $this->type("last_name", $lastName);
280
281 // fill email
282 $email = $firstName . "@" . $lastName . ".com";
283 $this->type("email-Primary", $email);
284
285 // click Sign the petition.
286 $this->click("_qf_Signature_next-bottom");
287 $this->waitForElementPresent("thankyou_text");
288
289 // check that thank-you page has appropriate title and message
290 $this->assertTrue($this->isTextPresent("Awesome $title donation"));
291 $this->assertTrue($this->isTextPresent("Thank you for your kind contribution to support $title"));
292
293 // login
294 $this->open($this->sboxPath);
295 $this->webtestLogin();
296
297 $this->open($this->sboxPath . "civicrm/campaign?reset=1&subPage=petition");
298 $this->waitForPageToLoad($this->getTimeoutMsec());
299 $this->waitForElementPresent("link=Add Petition");
300
301 // check for confirmed petition signature
302 $this->waitForElementPresent("petitions");
303 $this->click("search_form_petition");
304 $this->type("petition_title", $title);
305 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
306
307 $this->waitForElementPresent("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']");
308 $this->click("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']/ul/li/a[text()='Signatures']");
309 $this->waitForPageToLoad($this->getTimeoutMsec());
310
311 // verify tabular data
312 $expected = array(
313 2 => 'Petition',
314 3 => "$title Petition",
315 4 => "$firstName $lastName",
316 5 => "$lastName, $firstName",
317 8 => 'Completed',
318 );
319
320 foreach ($expected as $column => $value) {
321 $this->verifyText("xpath=//table[@class='selector']/tbody/tr[2]/td[$column]", preg_quote($value));
322 }
323}
324}
325