| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 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_OfflineContributionTest |
| 31 | */ |
| 32 | class WebTest_Campaign_OfflineContributionTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testCreateCampaign() { |
| 39 | $this->webtestLogin('admin'); |
| 40 | |
| 41 | // Create new group |
| 42 | $title = substr(sha1(rand()), 0, 7); |
| 43 | $groupName = $this->WebtestAddGroup(); |
| 44 | |
| 45 | // Adding contact |
| 46 | // We're using Quick Add block on the main page for this. |
| 47 | $firstName1 = substr(sha1(rand()), 0, 7); |
| 48 | $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org"); |
| 49 | |
| 50 | // add contact to group |
| 51 | // visit group tab |
| 52 | $this->click("css=li#tab_group a"); |
| 53 | $this->waitForElementPresent("group_id"); |
| 54 | |
| 55 | // add to group |
| 56 | $this->select("group_id", "label=$groupName"); |
| 57 | $this->click("_qf_GroupContact_next"); |
| 58 | $this->waitForElementPresent('link=Remove'); |
| 59 | |
| 60 | $firstName2 = substr(sha1(rand()), 0, 7); |
| 61 | $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org"); |
| 62 | |
| 63 | // add contact to group |
| 64 | // visit group tab |
| 65 | $this->click("css=li#tab_group a"); |
| 66 | $this->waitForElementPresent("group_id"); |
| 67 | |
| 68 | // add to group |
| 69 | $this->select("group_id", "label=$groupName"); |
| 70 | $this->click("_qf_GroupContact_next"); |
| 71 | $this->waitForElementPresent('link=Remove'); |
| 72 | |
| 73 | // Enable CiviCampaign module if necessary |
| 74 | $this->enableComponents(array('CiviCampaign')); |
| 75 | |
| 76 | // add the required permission |
| 77 | $this->changePermissions('edit-2-administer-civicampaign'); |
| 78 | |
| 79 | // Log in as normal user |
| 80 | $this->webtestLogin(); |
| 81 | |
| 82 | $this->openCiviPage('campaign', 'reset=1', "link=Add Campaign"); |
| 83 | if ($this->isTextPresent('None found.')) { |
| 84 | $this->openCiviPage('contribute/add', 'reset=1&action=add&context=standalone', '_qf_Contribution_cancel-bottom'); |
| 85 | $this->assertElementContainsText('crm-container', 'There are currently no active Campaigns.'); |
| 86 | } |
| 87 | $this->openCiviPage('campaign/add', 'reset=1'); |
| 88 | |
| 89 | $campaignTitle = "Campaign $title"; |
| 90 | $this->type("title", $campaignTitle); |
| 91 | |
| 92 | // select the campaign type |
| 93 | $this->select("campaign_type_id", "value=2"); |
| 94 | |
| 95 | // fill in the description |
| 96 | $this->type("description", "This is a test campaign"); |
| 97 | |
| 98 | // include groups for the campaign |
| 99 | $this->multiselect2("includeGroups", array("$groupName", "Advisory Board")); |
| 100 | |
| 101 | // fill the end date for campaign |
| 102 | $this->webtestFillDate("end_date", "+1 year"); |
| 103 | |
| 104 | // select campaign status |
| 105 | $this->select("status_id", "value=2"); |
| 106 | |
| 107 | // click save |
| 108 | $this->clickLink("_qf_Campaign_upload-bottom"); |
| 109 | |
| 110 | $this->checkCRMAlert("Campaign $title"); |
| 111 | |
| 112 | $this->waitForElementPresent("//td[3]/div[text()='$campaignTitle']"); |
| 113 | $campaignId = $this->urlArg('id', $this->getAttribute("//td[3]/div[text()='$campaignTitle']/../../td[13]/span/a[text()='Edit']@href")); |
| 114 | |
| 115 | $this->offlineContributionTest($campaignTitle, $campaignId); |
| 116 | |
| 117 | $this->pastCampaignsTest($groupName); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @param $campaignTitle |
| 122 | * @param int $id |
| 123 | * @param bool $past |
| 124 | */ |
| 125 | public function offlineContributionTest($campaignTitle, $id, $past = FALSE) { |
| 126 | // Create a contact to be used as soft creditor |
| 127 | $softCreditFname = substr(sha1(rand()), 0, 7); |
| 128 | $softCreditLname = substr(sha1(rand()), 0, 7); |
| 129 | $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE); |
| 130 | |
| 131 | // Adding contact with randomized first name (so we can then select that contact when creating contribution.) |
| 132 | // We're using Quick Add block on the main page for this. |
| 133 | $firstName = substr(sha1(rand()), 0, 7); |
| 134 | $this->webtestAddContact($firstName, "Summerson", $firstName . "@summerson.name"); |
| 135 | |
| 136 | // go to contribution tab and add contribution. |
| 137 | $this->click("css=li#tab_contribute a"); |
| 138 | |
| 139 | // wait for Record Contribution elenment. |
| 140 | $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)"); |
| 141 | $this->click("link=Record Contribution (Check, Cash, EFT ...)"); |
| 142 | |
| 143 | $this->waitForElementPresent("_qf_Contribution_cancel-bottom"); |
| 144 | |
| 145 | // fill financial type. |
| 146 | $this->select("financial_type_id", "Donation"); |
| 147 | |
| 148 | // fill in Received Date |
| 149 | $this->webtestFillDate('receive_date'); |
| 150 | |
| 151 | // source |
| 152 | $this->type("source", "Mailer 1"); |
| 153 | |
| 154 | if ($past) { |
| 155 | $this->click("include-past-campaigns"); |
| 156 | $this->waitForElementPresent("css=#campaign_id option[value=$id]"); |
| 157 | } |
| 158 | |
| 159 | $this->select("campaign_id", "value=$id"); |
| 160 | |
| 161 | // total amount |
| 162 | $this->type("total_amount", "100"); |
| 163 | |
| 164 | // select payment instrument type = Check and enter chk number |
| 165 | $this->select("payment_instrument_id", "value=4"); |
| 166 | $this->waitForElementPresent("check_number"); |
| 167 | $this->type("check_number", "check #1041"); |
| 168 | |
| 169 | $this->type("trxn_id", "P20901X1" . rand(100, 10000)); |
| 170 | |
| 171 | // soft credit |
| 172 | $this->click("xpath=id('Contribution')/div[2]/div[@id='softCredit']/div[1]"); |
| 173 | $this->type("soft_credit_amount_1", "50"); |
| 174 | $this->waitForElementPresent("soft_credit_contact_id_1"); |
| 175 | $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_id_1'); |
| 176 | |
| 177 | //Additional Detail section |
| 178 | $this->click("AdditionalDetail"); |
| 179 | $this->waitForElementPresent("thankyou_date"); |
| 180 | |
| 181 | $this->type("note", "Test note for {$firstName}."); |
| 182 | $this->type("non_deductible_amount", "10"); |
| 183 | $this->type("fee_amount", "0"); |
| 184 | $this->type("net_amount", "0"); |
| 185 | $this->type("invoice_id", time()); |
| 186 | $this->webtestFillDate('thankyou_date'); |
| 187 | |
| 188 | //Premium section |
| 189 | $this->click("Premium"); |
| 190 | $this->waitForElementPresent("fulfilled_date"); |
| 191 | $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )"); |
| 192 | $this->select("product_name[1]", "label=Black"); |
| 193 | $this->webtestFillDate('fulfilled_date'); |
| 194 | |
| 195 | // Clicking save. |
| 196 | $this->click("_qf_Contribution_upload-bottom"); |
| 197 | |
| 198 | // Is status message correct? |
| 199 | $this->checkCRMAlert("The contribution record has been saved."); |
| 200 | |
| 201 | $this->waitForElementPresent("xpath=//*[@id='Search']//div[2]//table[2]/tbody/tr/td[8]/span/a[text()='View']"); |
| 202 | |
| 203 | // click through to the Contribution view screen |
| 204 | $this->click("xpath=//*[@id='Search']//div[2]//table[2]/tbody/tr/td[8]/span/a[text()='View']"); |
| 205 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); |
| 206 | |
| 207 | // verify Contribution created |
| 208 | $this->webtestVerifyTabularData(array('Campaign' => $campaignTitle)); |
| 209 | |
| 210 | if ($past) { |
| 211 | // when campaign component is disabled |
| 212 | $this->openCiviPage('admin/setting/component', 'reset=1', '_qf_Component_next-bottom'); |
| 213 | $this->addSelection("enableComponents-t", "label=CiviCampaign"); |
| 214 | $this->click("//option[@value='CiviCampaign']"); |
| 215 | $this->click("remove"); |
| 216 | $this->clickLink("_qf_Component_next-bottom"); |
| 217 | |
| 218 | $this->checkCRMAlert("Changes Saved"); |
| 219 | |
| 220 | $this->openCiviPage('contribute/search', 'reset=1', '_qf_Search_refresh'); |
| 221 | |
| 222 | $this->type('sort_name', $firstName); |
| 223 | $this->click("_qf_Search_refresh"); |
| 224 | $this->waitForElementPresent("xpath=//div[@id='contributionSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']"); |
| 225 | $this->click("xpath=//div[@id='contributionSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']"); |
| 226 | $this->waitForElementPresent("_qf_Contribution_cancel-bottom"); |
| 227 | $this->assertTrue($this->isTextPresent("$campaignTitle")); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * @param string $groupName |
| 233 | */ |
| 234 | public function pastCampaignsTest($groupName) { |
| 235 | $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom'); |
| 236 | |
| 237 | $pastTitle = substr(sha1(rand()), 0, 7); |
| 238 | $pastCampaignTitle = "Past Campaign $pastTitle"; |
| 239 | $this->type("title", $pastCampaignTitle); |
| 240 | |
| 241 | // select the campaign type |
| 242 | $this->select("campaign_type_id", "value=2"); |
| 243 | |
| 244 | // fill in the description |
| 245 | $this->type("description", "This is a test for past campaign"); |
| 246 | |
| 247 | // include groups for the campaign |
| 248 | $this->multiselect2("includeGroups", array("$groupName", "Advisory Board")); |
| 249 | |
| 250 | // fill the start date for campaign |
| 251 | $this->webtestFillDate("start_date", "1 January " . (date('Y') - 1)); |
| 252 | |
| 253 | // fill the end date for campaign |
| 254 | $this->webtestFillDate("end_date", "31 January " . (date('Y') - 1)); |
| 255 | |
| 256 | // select campaign status |
| 257 | $this->select("status_id", "value=3"); |
| 258 | |
| 259 | // click save |
| 260 | $this->clickLink("_qf_Campaign_upload-bottom"); |
| 261 | $this->checkCRMAlert("Campaign $pastCampaignTitle has been saved."); |
| 262 | |
| 263 | $this->waitForElementPresent("link=Add Campaign"); |
| 264 | $this->waitForElementPresent("link=Campaigns"); |
| 265 | $this->click("search_form_campaign"); |
| 266 | $this->type("campaign_title", $pastCampaignTitle); |
| 267 | $this->clickAjaxLink("//a[text()='Search']", "//td[3]/div[text()='$pastCampaignTitle']"); |
| 268 | $campaignId = $this->urlArg('id', $this->getAttribute("//td[3]/div[text()='$pastCampaignTitle']/../../td[13]/span/a[text()='Edit']@href")); |
| 269 | |
| 270 | $this->offlineContributionTest($pastCampaignTitle, $campaignId, TRUE); |
| 271 | } |
| 272 | |
| 273 | } |