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