| 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->webtestLogin('admin'); |
| 40 | |
| 41 | // Enable CiviCampaign module if necessary |
| 42 | $this->enableComponents("CiviCampaign"); |
| 43 | |
| 44 | // handle permissions early |
| 45 | |
| 46 | // let's give permission 'sign CiviCRM Petition' to anonymous user. |
| 47 | $permissions = array( |
| 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", |
| 62 | ); |
| 63 | $this->changePermissions($permissions); |
| 64 | |
| 65 | // Log in as normal user |
| 66 | $this->webtestLogin(); |
| 67 | |
| 68 | /////////////// Create Campaign /////////////////////////////// |
| 69 | |
| 70 | $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom"); |
| 71 | |
| 72 | $title = substr(sha1(rand()), 0, 7); |
| 73 | $this->type("title", "$title Campaign"); |
| 74 | |
| 75 | // select the campaign type |
| 76 | $this->select("campaign_type_id", "value=2"); |
| 77 | |
| 78 | // fill in the description |
| 79 | $this->type("description", "This is a test campaign"); |
| 80 | |
| 81 | // include groups for the campaign |
| 82 | $this->addSelection("includeGroups", "label=Advisory Board"); |
| 83 | $this->click("//option[@value=4]"); |
| 84 | |
| 85 | // fill the end date for campaign |
| 86 | $this->webtestFillDate("end_date", "+1 year"); |
| 87 | |
| 88 | // select campaign status |
| 89 | $this->select("status_id", "value=2"); |
| 90 | |
| 91 | // click save |
| 92 | $this->clickLink('_qf_Campaign_upload-bottom'); |
| 93 | |
| 94 | $this->waitForText('crm-notification-container', "Campaign $title Campaign has been saved."); |
| 95 | |
| 96 | ////////////// Create petition using New Individual profile ////////////////////// |
| 97 | |
| 98 | $this->openCiviPage("petition/add", "reset=1", "_qf_Petition_next-bottom"); |
| 99 | |
| 100 | // fill petition tile. |
| 101 | $title = substr(sha1(rand()), 0, 7); |
| 102 | $this->type("title", "$title Petition"); |
| 103 | |
| 104 | // fill introduction |
| 105 | //$this->type("cke_instructions", "This is introduction of $title Petition"); |
| 106 | |
| 107 | // select campaign |
| 108 | $this->select("campaign_id", "value=1"); |
| 109 | |
| 110 | // select profile |
| 111 | $this->select("contact_profile_id", "value=4"); |
| 112 | |
| 113 | // click save |
| 114 | $this->clickLink('_qf_Petition_next-bottom'); |
| 115 | |
| 116 | $this->waitForText('crm-notification-container', "Petition has been saved."); |
| 117 | |
| 118 | $this->waitForElementPresent("link=Add Petition"); |
| 119 | $this->waitForElementPresent("search_form_petition"); |
| 120 | $this->click("search_form_petition"); |
| 121 | $this->type("petition_title", $title); |
| 122 | |
| 123 | $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']"); |
| 124 | $this->waitForElementPresent("xpath=//div[@id='petitionList']/div/table/tbody//tr//td[@class=' crm-petition-action']//span[text()='more']/ul//li/a[text()='Sign']"); |
| 125 | $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"); |
| 126 | |
| 127 | ////////////// Retrieve Sign Petition Url ///////////////////////// |
| 128 | |
| 129 | // logout and sign as anonymous. |
| 130 | $this->webtestLogout(); |
| 131 | |
| 132 | // go to the link that you will be sign as anonymous |
| 133 | $this->open($url); |
| 134 | $this->waitForElementPresent("_qf_Signature_next-bottom"); |
| 135 | |
| 136 | // fill first name |
| 137 | $firstName = substr(sha1(rand()), 0, 7); |
| 138 | $this->type("first_name", $firstName); |
| 139 | |
| 140 | // fill last name |
| 141 | $lastName = substr(sha1(rand()), 0, 7); |
| 142 | $this->type("last_name", $lastName); |
| 143 | |
| 144 | // fill email |
| 145 | $email = $firstName . "@" . $lastName . ".com"; |
| 146 | $this->type("email-Primary", $email); |
| 147 | |
| 148 | // click Sign the petition. |
| 149 | $this->clickLink('_qf_Signature_next-bottom', NULL); |
| 150 | $this->waitForText('page-title', "Thank You"); |
| 151 | |
| 152 | // login |
| 153 | $this->webtestLogin(); |
| 154 | |
| 155 | $this->openCiviPage("campaign", "reset=1&subPage=petition", "link=Add Petition"); |
| 156 | |
| 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']"); |
| 162 | |
| 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()); |
| 166 | |
| 167 | // verify tabular data |
| 168 | $expected = array( |
| 169 | 2 => 'Petition', |
| 170 | 3 => "$title Petition", |
| 171 | 4 => "$lastName, $firstName", |
| 172 | 5 => "$lastName, $firstName", |
| 173 | 8 => 'Scheduled', |
| 174 | ); |
| 175 | |
| 176 | foreach ($expected as $column => $value) { |
| 177 | $this->verifyText("xpath=//div[@class='crm-search-results']/table/tbody/tr[2]/td[$column]/", preg_quote($value)); |
| 178 | } |
| 179 | |
| 180 | // ONCE MORE, NO EMAIL VERIFICATION AND CUSTOM THANK-YOU |
| 181 | $this->openCiviPage("petition/add", "reset=1", "_qf_Petition_next-bottom"); |
| 182 | |
| 183 | // fill petition tile. |
| 184 | $title = substr(sha1(rand()), 0, 7); |
| 185 | $this->type("title", "$title Petition"); |
| 186 | |
| 187 | // fill introduction |
| 188 | //$this->type("cke_instructions", "This is introduction of $title Petition"); |
| 189 | |
| 190 | // select campaign |
| 191 | $this->select("campaign_id", "value=1"); |
| 192 | |
| 193 | // select profile |
| 194 | $this->select("contact_profile_id", "value=4"); |
| 195 | |
| 196 | // bypass email confirmation |
| 197 | $this->click("bypass_confirm"); |
| 198 | |
| 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'); |
| 202 | |
| 203 | // click save |
| 204 | $this->clickLink('_qf_Petition_next-bottom'); |
| 205 | |
| 206 | $this->waitForText('crm-notification-container', "Petition has been saved."); |
| 207 | |
| 208 | $this->waitForElementPresent("link=Add Petition"); |
| 209 | |
| 210 | $this->waitForElementPresent("search_form_petition"); |
| 211 | $this->click("search_form_petition"); |
| 212 | $this->type("petition_title", $title); |
| 213 | |
| 214 | $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[2]/td/a[text()='Search']"); |
| 215 | |
| 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"); |
| 218 | |
| 219 | // logout and sign as anonymous. |
| 220 | $this->webtestLogout(); |
| 221 | |
| 222 | // go to the link that you will be sign as anonymous |
| 223 | $this->open($url); |
| 224 | $this->waitForElementPresent("_qf_Signature_next-bottom"); |
| 225 | |
| 226 | // fill first name |
| 227 | $firstName = substr(sha1(rand()), 0, 7); |
| 228 | $this->type("first_name", $firstName); |
| 229 | |
| 230 | // fill last name |
| 231 | $lastName = substr(sha1(rand()), 0, 7); |
| 232 | $this->type("last_name", $lastName); |
| 233 | |
| 234 | // fill email |
| 235 | $email = $firstName . "@" . $lastName . ".com"; |
| 236 | $this->type("email-Primary", $email); |
| 237 | |
| 238 | // click Sign the petition. |
| 239 | $this->clickLink('_qf_Signature_next-bottom', 'thankyou_text'); |
| 240 | |
| 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"); |
| 244 | |
| 245 | // login |
| 246 | $this->webtestLogin(); |
| 247 | |
| 248 | $this->openCiviPage("campaign", "reset=1&subPage=petition", "link=Add Petition"); |
| 249 | |
| 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']"); |
| 255 | |
| 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()); |
| 259 | |
| 260 | // verify tabular data |
| 261 | $expected = array( |
| 262 | 2 => 'Petition', |
| 263 | 3 => "$title Petition", |
| 264 | 4 => "$lastName, $firstName", |
| 265 | 5 => "$lastName, $firstName", |
| 266 | 8 => 'Completed', |
| 267 | ); |
| 268 | |
| 269 | foreach ($expected as $column => $value) { |
| 270 | $this->verifyText("xpath=//div[@class='crm-search-results']/table/tbody/tr[2]/td[$column]/", preg_quote($value)); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | } |