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