Commit | Line | Data |
---|---|---|
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 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | class 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() { | |
6a488035 TO |
40 | $this->webtestLogin(); |
41 | ||
6a488035 | 42 | // Enable CiviCampaign module if necessary |
b9715b8a | 43 | $this->enableComponents("CiviCampaign"); |
6a488035 TO |
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 | /////////////// Create Campaign /////////////////////////////// | |
67 | ||
68 | // Go directly to the URL of the screen that you will be add campaign | |
69 | $this->open($this->sboxPath . "civicrm/campaign/add?reset=1"); | |
70 | ||
71 | // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit | |
72 | // button at the end of this page to show up, to make sure it's fully loaded. | |
73 | $this->waitForElementPresent("_qf_Campaign_upload-bottom"); | |
74 | ||
75 | // Let's start filling the form with values. | |
76 | $title = substr(sha1(rand()), 0, 7); | |
77 | $this->type("title", "$title Campaign"); | |
78 | ||
79 | // select the campaign type | |
80 | $this->select("campaign_type_id", "value=2"); | |
81 | ||
82 | // fill in the description | |
83 | $this->type("description", "This is a test campaign"); | |
84 | ||
85 | // include groups for the campaign | |
86 | $this->addSelection("includeGroups-f", "label=Advisory Board"); | |
87 | $this->click("//option[@value=4]"); | |
88 | $this->click("add"); | |
89 | ||
90 | // fill the end date for campaign | |
91 | $this->webtestFillDate("end_date", "+1 year"); | |
92 | ||
93 | // select campaign status | |
94 | $this->select("status_id", "value=2"); | |
95 | ||
96 | // click save | |
97 | $this->click("_qf_Campaign_upload-bottom"); | |
98 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
99 | ||
100 | $this->assertTrue($this->isTextPresent("Campaign $title Campaign has been saved."), "Status message didn't show up after saving!"); | |
101 | ||
102 | ////////////// Create petition using New Individual profile ////////////////////// | |
103 | ||
104 | // Go directly to the URL of the screen that you will be add petition | |
105 | $this->open($this->sboxPath . "civicrm/petition/add?reset=1"); | |
106 | ||
107 | // button at the end of this page to show up, to make sure it's fully loaded. | |
108 | $this->waitForElementPresent("_qf_Petition_next-bottom"); | |
109 | ||
110 | // fill petition tile. | |
111 | $title = substr(sha1(rand()), 0, 7); | |
112 | $this->type("title", "$title Petition"); | |
113 | ||
114 | // fill introduction | |
115 | //$this->type("cke_instructions", "This is introduction of $title Petition"); | |
116 | ||
117 | // select campaign | |
118 | $this->select("campaign_id", "value=1"); | |
119 | ||
120 | // select profile | |
121 | $this->select("contact_profile_id", "value=4"); | |
122 | ||
123 | // click save | |
124 | $this->click("_qf_Petition_next-bottom"); | |
125 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
126 | ||
127 | $this->assertTrue($this->isTextPresent("Petition has been saved.")); | |
128 | ||
129 | $this->waitForElementPresent("link=Add Petition"); | |
130 | ||
131 | $this->waitForElementPresent("petitions"); | |
132 | $this->click("search_form_petition"); | |
133 | $this->type("petition_title", $title); | |
134 | ||
135 | $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']"); | |
136 | ||
137 | $this->waitForElementPresent("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']/ul/li/a[text()='Sign']"); | |
138 | $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"); | |
139 | ||
140 | ////////////// Retrieve Sign Petition Url ///////////////////////// | |
141 | ||
142 | // logout and sign as anonymous. | |
143 | $this->open($this->sboxPath . "civicrm/logout?reset=1"); | |
144 | $this->waitForElementPresent("edit-submit"); | |
145 | ||
146 | // go to the link that you will be sign as anonymous | |
147 | $this->open($url); | |
148 | $this->waitForElementPresent("_qf_Signature_next-bottom"); | |
149 | ||
150 | // fill first name | |
151 | $firstName = substr(sha1(rand()), 0, 7); | |
152 | $this->type("first_name", $firstName); | |
153 | ||
154 | // fill last name | |
155 | $lastName = substr(sha1(rand()), 0, 7); | |
156 | $this->type("last_name", $lastName); | |
157 | ||
158 | // fill email | |
159 | $email = $firstName . "@" . $lastName . ".com"; | |
160 | $this->type("email-Primary", $email); | |
161 | ||
162 | // click Sign the petition. | |
163 | $this->click("_qf_Signature_next-bottom"); | |
164 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
165 | $this->assertTrue($this->isTextPresent("Thank You")); | |
166 | ||
167 | // login | |
168 | $this->open($this->sboxPath); | |
169 | $this->webtestLogin(); | |
170 | ||
171 | $this->open($this->sboxPath . "civicrm/campaign?reset=1&subPage=petition"); | |
172 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
173 | $this->waitForElementPresent("link=Add Petition"); | |
174 | ||
175 | // check for unconfirmed petition signature | |
176 | $this->waitForElementPresent("petitions"); | |
177 | $this->click("search_form_petition"); | |
178 | $this->type("petition_title", $title); | |
179 | $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']"); | |
180 | ||
181 | $this->waitForElementPresent("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']"); | |
182 | $this->click("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']/ul/li/a[text()='Signatures']"); | |
183 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
184 | ||
185 | // verify tabular data | |
186 | $expected = array( | |
187 | 2 => 'Petition', | |
188 | 3 => "$title Petition", | |
189 | 4 => "$firstName $lastName", | |
190 | 5 => "$lastName, $firstName", | |
191 | 8 => 'Scheduled', | |
192 | ); | |
193 | ||
194 | foreach ($expected as $column => $value) { | |
195 | $this->verifyText("xpath=//table[@class='selector']/tbody/tr[2]/td[$column]", preg_quote($value)); | |
196 | } | |
197 | ||
198 | // ONCE MORE, NO EMAIL VERIFICATION AND CUSTOM THANK-YOU | |
199 | ||
200 | // Go directly to the URL of the screen that you will be add petition | |
201 | $this->open($this->sboxPath . "civicrm/petition/add?reset=1"); | |
202 | ||
203 | // button at the end of this page to show up, to make sure it's fully loaded. | |
204 | $this->waitForElementPresent("_qf_Petition_next-bottom"); | |
205 | ||
206 | // fill petition tile. | |
207 | $title = substr(sha1(rand()), 0, 7); | |
208 | $this->type("title", "$title Petition"); | |
209 | ||
210 | // fill introduction | |
211 | //$this->type("cke_instructions", "This is introduction of $title Petition"); | |
212 | ||
213 | // select campaign | |
214 | $this->select("campaign_id", "value=1"); | |
215 | ||
216 | // select profile | |
217 | $this->select("contact_profile_id", "value=4"); | |
218 | ||
219 | // bypass email confirmation | |
220 | $this->click("bypass_confirm"); | |
221 | ||
222 | // set custom thank-you title and text | |
223 | $this->type('thankyou_title', "Awesome $title donation"); | |
224 | $this->fillRichTextField('thankyou_text', "Thank you for your kind contribution to support $title", 'CKEditor'); | |
225 | ||
226 | // click save | |
227 | $this->click("_qf_Petition_next-bottom"); | |
228 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
229 | ||
230 | $this->assertTrue($this->isTextPresent("Petition has been saved.")); | |
231 | ||
232 | $this->waitForElementPresent("link=Add Petition"); | |
233 | ||
234 | $this->waitForElementPresent("petitions"); | |
235 | $this->click("search_form_petition"); | |
236 | $this->type("petition_title", $title); | |
237 | ||
238 | $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']"); | |
239 | ||
240 | $this->waitForElementPresent("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']/ul/li/a[text()='Sign']"); | |
241 | $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"); | |
242 | ||
243 | // logout and sign as anonymous. | |
244 | $this->open($this->sboxPath . "civicrm/logout?reset=1"); | |
245 | $this->waitForElementPresent("edit-submit"); | |
246 | ||
247 | // go to the link that you will be sign as anonymous | |
248 | $this->open($url); | |
249 | $this->waitForElementPresent("_qf_Signature_next-bottom"); | |
250 | ||
251 | // fill first name | |
252 | $firstName = substr(sha1(rand()), 0, 7); | |
253 | $this->type("first_name", $firstName); | |
254 | ||
255 | // fill last name | |
256 | $lastName = substr(sha1(rand()), 0, 7); | |
257 | $this->type("last_name", $lastName); | |
258 | ||
259 | // fill email | |
260 | $email = $firstName . "@" . $lastName . ".com"; | |
261 | $this->type("email-Primary", $email); | |
262 | ||
263 | // click Sign the petition. | |
264 | $this->click("_qf_Signature_next-bottom"); | |
265 | $this->waitForElementPresent("thankyou_text"); | |
266 | ||
267 | // check that thank-you page has appropriate title and message | |
268 | $this->assertTrue($this->isTextPresent("Awesome $title donation")); | |
269 | $this->assertTrue($this->isTextPresent("Thank you for your kind contribution to support $title")); | |
270 | ||
271 | // login | |
272 | $this->open($this->sboxPath); | |
273 | $this->webtestLogin(); | |
274 | ||
275 | $this->open($this->sboxPath . "civicrm/campaign?reset=1&subPage=petition"); | |
276 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
277 | $this->waitForElementPresent("link=Add Petition"); | |
278 | ||
279 | // check for confirmed petition signature | |
280 | $this->waitForElementPresent("petitions"); | |
281 | $this->click("search_form_petition"); | |
282 | $this->type("petition_title", $title); | |
283 | $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']"); | |
284 | ||
285 | $this->waitForElementPresent("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']"); | |
286 | $this->click("xpath=//div[@id='petitions_wrapper']/table[@id='petitions']/tbody/tr/td[10]/span[2][text()='more']/ul/li/a[text()='Signatures']"); | |
287 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
288 | ||
289 | // verify tabular data | |
290 | $expected = array( | |
291 | 2 => 'Petition', | |
292 | 3 => "$title Petition", | |
293 | 4 => "$firstName $lastName", | |
294 | 5 => "$lastName, $firstName", | |
295 | 8 => 'Completed', | |
296 | ); | |
297 | ||
298 | foreach ($expected as $column => $value) { | |
299 | $this->verifyText("xpath=//table[@class='selector']/tbody/tr[2]/td[$column]", preg_quote($value)); | |
300 | } | |
301 | } | |
302 | } | |
303 |