3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Campaign_PetitionUsageScenarioTest
extends CiviSeleniumTestCase
{
31 protected $captureScreenshotOnFailure = TRUE;
32 protected $screenshotPath = '/tmp/';
33 protected $screenshotUrl = 'http://api.dev.civicrm.org/sc/';
35 protected function setUp() {
39 function testPetitionUsageScenario() {
40 $this->webtestLogin();
42 // Enable CiviCampaign module if necessary
43 $this->enableComponents("CiviCampaign");
45 // handle permissions early
47 // let's give permission 'sign CiviCRM Petition' to anonymous user.
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",
64 $this->changePermissions($permissions);
66 /////////////// Create Campaign ///////////////////////////////
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");
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");
75 // Let's start filling the form with values.
76 $title = substr(sha1(rand()), 0, 7);
77 $this->type("title", "$title Campaign");
79 // select the campaign type
80 $this->select("campaign_type_id", "value=2");
82 // fill in the description
83 $this->type("description", "This is a test campaign");
85 // include groups for the campaign
86 $this->addSelection("includeGroups-f", "label=Advisory Board");
87 $this->click("//option[@value=4]");
90 // fill the end date for campaign
91 $this->webtestFillDate("end_date", "+1 year");
93 // select campaign status
94 $this->select("status_id", "value=2");
97 $this->click("_qf_Campaign_upload-bottom");
98 $this->waitForPageToLoad($this->getTimeoutMsec());
100 $this->assertTrue($this->isTextPresent("Campaign $title Campaign has been saved."), "Status message didn't show up after saving!");
102 ////////////// Create petition using New Individual profile //////////////////////
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");
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");
110 // fill petition tile.
111 $title = substr(sha1(rand()), 0, 7);
112 $this->type("title", "$title Petition");
115 //$this->type("cke_instructions", "This is introduction of $title Petition");
118 $this->select("campaign_id", "value=1");
121 $this->select("contact_profile_id", "value=4");
124 $this->click("_qf_Petition_next-bottom");
125 $this->waitForPageToLoad($this->getTimeoutMsec());
127 $this->assertTrue($this->isTextPresent("Petition has been saved."));
129 $this->waitForElementPresent("link=Add Petition");
131 $this->waitForElementPresent("petitions");
132 $this->click("search_form_petition");
133 $this->type("petition_title", $title);
135 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
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");
140 ////////////// Retrieve Sign Petition Url /////////////////////////
142 // logout and sign as anonymous.
143 $this->open($this->sboxPath
. "civicrm/logout?reset=1");
144 $this->waitForElementPresent("edit-submit");
146 // go to the link that you will be sign as anonymous
148 $this->waitForElementPresent("_qf_Signature_next-bottom");
151 $firstName = substr(sha1(rand()), 0, 7);
152 $this->type("first_name", $firstName);
155 $lastName = substr(sha1(rand()), 0, 7);
156 $this->type("last_name", $lastName);
159 $email = $firstName . "@" . $lastName . ".com";
160 $this->type("email-Primary", $email);
162 // click Sign the petition.
163 $this->click("_qf_Signature_next-bottom");
164 $this->waitForPageToLoad($this->getTimeoutMsec());
165 $this->assertTrue($this->isTextPresent("Thank You"));
168 $this->open($this->sboxPath
);
169 $this->webtestLogin();
171 $this->open($this->sboxPath
. "civicrm/campaign?reset=1&subPage=petition");
172 $this->waitForPageToLoad($this->getTimeoutMsec());
173 $this->waitForElementPresent("link=Add Petition");
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']");
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());
185 // verify tabular data
188 3 => "$title Petition",
189 4 => "$firstName $lastName",
190 5 => "$lastName, $firstName",
194 foreach ($expected as $column => $value) {
195 $this->verifyText("xpath=//table[@class='selector']/tbody/tr[2]/td[$column]", preg_quote($value));
198 // ONCE MORE, NO EMAIL VERIFICATION AND CUSTOM THANK-YOU
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");
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");
206 // fill petition tile.
207 $title = substr(sha1(rand()), 0, 7);
208 $this->type("title", "$title Petition");
211 //$this->type("cke_instructions", "This is introduction of $title Petition");
214 $this->select("campaign_id", "value=1");
217 $this->select("contact_profile_id", "value=4");
219 // bypass email confirmation
220 $this->click("bypass_confirm");
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');
227 $this->click("_qf_Petition_next-bottom");
228 $this->waitForPageToLoad($this->getTimeoutMsec());
230 $this->assertTrue($this->isTextPresent("Petition has been saved."));
232 $this->waitForElementPresent("link=Add Petition");
234 $this->waitForElementPresent("petitions");
235 $this->click("search_form_petition");
236 $this->type("petition_title", $title);
238 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
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");
243 // logout and sign as anonymous.
244 $this->open($this->sboxPath
. "civicrm/logout?reset=1");
245 $this->waitForElementPresent("edit-submit");
247 // go to the link that you will be sign as anonymous
249 $this->waitForElementPresent("_qf_Signature_next-bottom");
252 $firstName = substr(sha1(rand()), 0, 7);
253 $this->type("first_name", $firstName);
256 $lastName = substr(sha1(rand()), 0, 7);
257 $this->type("last_name", $lastName);
260 $email = $firstName . "@" . $lastName . ".com";
261 $this->type("email-Primary", $email);
263 // click Sign the petition.
264 $this->click("_qf_Signature_next-bottom");
265 $this->waitForElementPresent("thankyou_text");
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"));
272 $this->open($this->sboxPath
);
273 $this->webtestLogin();
275 $this->open($this->sboxPath
. "civicrm/campaign?reset=1&subPage=petition");
276 $this->waitForPageToLoad($this->getTimeoutMsec());
277 $this->waitForElementPresent("link=Add Petition");
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']");
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());
289 // verify tabular data
292 3 => "$title Petition",
293 4 => "$firstName $lastName",
294 5 => "$lastName, $firstName",
298 foreach ($expected as $column => $value) {
299 $this->verifyText("xpath=//table[@class='selector']/tbody/tr[2]/td[$column]", preg_quote($value));