3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Campaign_PetitionUsageScenarioTest
32 class WebTest_Campaign_PetitionUsageScenarioTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testPetitionUsageScenario() {
39 $this->webtestLogin('admin');
41 // Enable CiviCampaign module if necessary
42 $this->enableComponents("CiviCampaign");
44 // handle permissions early
46 // let's give permission 'sign CiviCRM Petition' to anonymous user.
48 // give profile related permision
49 "edit-1-sign-civicrm-petition",
50 "edit-1-profile-create",
51 "edit-1-profile-edit",
52 "edit-1-profile-listings",
53 "edit-1-profile-view",
54 // now give full permissions to CiviPetition to registered user
55 "edit-2-administer-civicampaign",
56 "edit-2-manage-campaign",
57 "edit-2-gotv-campaign-contacts",
58 "edit-2-interview-campaign-contacts",
59 "edit-2-release-campaign-contacts",
60 "edit-2-reserve-campaign-contacts",
61 "edit-2-sign-civicrm-petition",
63 $this->changePermissions($permissions);
65 // Log in as normal user
66 $this->webtestLogin();
68 /////////////// Create Campaign ///////////////////////////////
70 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
72 $title = substr(sha1(rand()), 0, 7);
73 $this->type("title", "$title Campaign");
75 // select the campaign type
76 $this->select("campaign_type_id", "value=2");
78 // fill in the description
79 $this->type("description", "This is a test campaign");
81 // include groups for the campaign
82 $this->addSelection("includeGroups", "label=Advisory Board");
83 $this->click("//option[@value=4]");
85 // fill the end date for campaign
86 $this->webtestFillDate("end_date", "+1 year");
88 // select campaign status
89 $this->select("status_id", "value=2");
92 $this->clickLink('_qf_Campaign_upload-bottom');
94 $this->waitForText('crm-notification-container', "Campaign $title Campaign has been saved.");
96 ////////////// Create petition using New Individual profile //////////////////////
98 $this->openCiviPage("petition/add", "reset=1", "_qf_Petition_next-bottom");
100 // fill petition tile.
101 $title = substr(sha1(rand()), 0, 7);
102 $this->type("title", "$title Petition");
105 //$this->type("cke_instructions", "This is introduction of $title Petition");
108 $this->select("campaign_id", "value=1");
111 $this->select("contact_profile_id", "value=4");
114 $this->clickLink('_qf_Petition_next-bottom');
116 $this->waitForText('crm-notification-container', "Petition has been saved.");
118 $this->waitForElementPresent("link=Add Petition");
119 $this->waitForElementPresent("search_form_petition");
120 $this->click("search_form_petition");
121 $this->type("petition_title", $title);
123 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
124 $this->waitForElementPresent("xpath=//table[@class='petitions dataTable no-footer']/tbody//tr/td[10]/span[2][text()='more']/ul/li[2]/a[text()='Sign']");
125 $url = $this->getAttribute("xpath=//table[@class='petitions dataTable no-footer']/tbody//tr/td[10]/span[2][text()='more']/ul/li[2]/a[text()='Sign']@href");
127 ////////////// Retrieve Sign Petition Url /////////////////////////
129 // logout and sign as anonymous.
130 $this->webtestLogout();
132 // go to the link that you will be sign as anonymous
134 $this->waitForElementPresent("_qf_Signature_next-bottom");
137 $firstName = substr(sha1(rand()), 0, 7);
138 $this->type("first_name", $firstName);
141 $lastName = substr(sha1(rand()), 0, 7);
142 $this->type("last_name", $lastName);
145 $email = $firstName . "@" . $lastName . ".com";
146 $this->type("email-Primary", $email);
148 // click Sign the petition.
149 $this->clickLink('_qf_Signature_next-bottom', NULL);
150 $this->waitForText('page-title', "Thank You");
153 $this->webtestLogin();
155 $this->openCiviPage("campaign", "reset=1&subPage=petition", "link=Add Petition");
157 // check for unconfirmed petition signature
158 $this->waitForElementPresent("search_form_petition");
159 $this->click("search_form_petition");
160 $this->type("petition_title", $title);
161 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
163 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']");
164 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']/ul/li[3]/a[text()='Signatures']");
165 $this->waitForPageToLoad($this->getTimeoutMsec());
167 // verify tabular data
170 3 => "$title Petition",
171 4 => "$lastName, $firstName",
172 5 => "$lastName, $firstName",
176 foreach ($expected as $column => $value) {
177 $this->verifyText("xpath=//div[@class='crm-search-results']/table/tbody/tr[2]/td[$column]/", preg_quote($value));
180 // ONCE MORE, NO EMAIL VERIFICATION AND CUSTOM THANK-YOU
181 $this->openCiviPage("petition/add", "reset=1", "_qf_Petition_next-bottom");
183 // fill petition tile.
184 $title = substr(sha1(rand()), 0, 7);
185 $this->type("title", "$title Petition");
188 //$this->type("cke_instructions", "This is introduction of $title Petition");
191 $this->select("campaign_id", "value=1");
194 $this->select("contact_profile_id", "value=4");
196 // bypass email confirmation
197 $this->click("bypass_confirm");
199 // set custom thank-you title and text
200 $this->type('thankyou_title', "Awesome $title donation");
201 $this->fillRichTextField('thankyou_text', "Thank you for your kind contribution to support $title", 'CKEditor');
204 $this->clickLink('_qf_Petition_next-bottom');
206 $this->waitForText('crm-notification-container', "Petition has been saved.");
208 $this->waitForElementPresent("link=Add Petition");
210 $this->waitForElementPresent("search_form_petition");
211 $this->click("search_form_petition");
212 $this->type("petition_title", $title);
214 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
216 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']/ul/li[2]/a[text()='Sign']");
217 $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 // logout and sign as anonymous.
220 $this->webtestLogout();
222 // go to the link that you will be sign as anonymous
224 $this->waitForElementPresent("_qf_Signature_next-bottom");
227 $firstName = substr(sha1(rand()), 0, 7);
228 $this->type("first_name", $firstName);
231 $lastName = substr(sha1(rand()), 0, 7);
232 $this->type("last_name", $lastName);
235 $email = $firstName . "@" . $lastName . ".com";
236 $this->type("email-Primary", $email);
238 // click Sign the petition.
239 $this->clickLink('_qf_Signature_next-bottom', 'thankyou_text');
241 // check that thank-you page has appropriate title and message
242 $this->waitForText('page-title', "Awesome $title donation");
243 $this->waitForText('thankyou_text', "Thank you for your kind contribution to support $title");
246 $this->webtestLogin();
248 $this->openCiviPage("campaign", "reset=1&subPage=petition", "link=Add Petition");
250 // check for confirmed petition signature
251 $this->waitForElementPresent("search_form_petition");
252 $this->click("search_form_petition");
253 $this->type("petition_title", $title);
254 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']");
256 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[10]/span[2][text()='more']");
257 $this->click("xpath=//table[@class='petitions dataTable no-footer']/tbody/tr/td[10]/span[2][text()='more']/ul/li[3]/a[text()='Signatures']");
258 $this->waitForPageToLoad($this->getTimeoutMsec());
260 // verify tabular data
263 3 => "$title Petition",
264 4 => "$lastName, $firstName",
265 5 => "$lastName, $firstName",
269 foreach ($expected as $column => $value) {
270 $this->verifyText("xpath=//div[@class='crm-search-results']/table/tbody/tr[2]/td[$column]/", preg_quote($value));