| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
| 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 | $this->waitForElementPresent("xpath=//*[@id='Search']//div[2]//table[2]/tbody/tr/td[8]/span//a[text()='View']"); |
| 201 | |
| 202 | // click through to the Contribution view screen |
| 203 | $this->click("xpath=//*[@id='Search']//div[2]//table[2]/tbody/tr/td[8]/span/a[text()='View']"); |
| 204 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); |
| 205 | |
| 206 | // verify Contribution created |
| 207 | $this->webtestVerifyTabularData(array('Campaign' => $campaignTitle)); |
| 208 | |
| 209 | if ($past) { |
| 210 | // when campaign component is disabled |
| 211 | $this->openCiviPage('admin/setting/component', 'reset=1', '_qf_Component_next-bottom'); |
| 212 | $this->addSelection("enableComponents-t", "label=CiviCampaign"); |
| 213 | $this->click("//option[@value='CiviCampaign']"); |
| 214 | $this->click("remove"); |
| 215 | $this->clickLink("_qf_Component_next-bottom"); |
| 216 | |
| 217 | $this->checkCRMAlert("Changes Saved"); |
| 218 | |
| 219 | $this->openCiviPage('contribute/search', 'reset=1', '_qf_Search_refresh'); |
| 220 | |
| 221 | $this->type('sort_name', $firstName); |
| 222 | $this->click("_qf_Search_refresh"); |
| 223 | $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody/tr/td[10]/span//a[text()='Edit']"); |
| 224 | $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr/td[10]/span//a[text()='Edit']"); |
| 225 | $this->waitForElementPresent("_qf_Contribution_cancel-bottom"); |
| 226 | $this->assertTrue($this->isTextPresent("$campaignTitle")); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * @param string $groupName |
| 232 | */ |
| 233 | public function pastCampaignsTest($groupName) { |
| 234 | $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom'); |
| 235 | |
| 236 | $pastTitle = substr(sha1(rand()), 0, 7); |
| 237 | $pastCampaignTitle = "Past Campaign $pastTitle"; |
| 238 | $this->type("title", $pastCampaignTitle); |
| 239 | |
| 240 | // select the campaign type |
| 241 | $this->select("campaign_type_id", "value=2"); |
| 242 | |
| 243 | // fill in the description |
| 244 | $this->type("description", "This is a test for past campaign"); |
| 245 | |
| 246 | // include groups for the campaign |
| 247 | $this->multiselect2("includeGroups", array("$groupName", "Advisory Board")); |
| 248 | |
| 249 | // fill the start date for campaign |
| 250 | $this->webtestFillDate("start_date", "1 January " . (date('Y') - 1)); |
| 251 | |
| 252 | // fill the end date for campaign |
| 253 | $this->webtestFillDate("end_date", "31 January " . (date('Y') - 1)); |
| 254 | |
| 255 | // select campaign status |
| 256 | $this->select("status_id", "value=3"); |
| 257 | |
| 258 | // click save |
| 259 | $this->clickLink("_qf_Campaign_upload-bottom"); |
| 260 | $this->checkCRMAlert("Campaign $pastCampaignTitle has been saved."); |
| 261 | |
| 262 | $this->waitForElementPresent("link=Add Campaign"); |
| 263 | $this->waitForElementPresent("link=Campaigns"); |
| 264 | $this->click("search_form_campaign"); |
| 265 | $this->type("campaign_title", $pastCampaignTitle); |
| 266 | $this->clickAjaxLink("//a[text()='Search']", "//td[3]/div[text()='$pastCampaignTitle']"); |
| 267 | $campaignId = $this->urlArg('id', $this->getAttribute("//td[3]/div[text()='$pastCampaignTitle']/../../td[13]/span/a[text()='Edit']@href")); |
| 268 | |
| 269 | $this->offlineContributionTest($pastCampaignTitle, $campaignId, TRUE); |
| 270 | } |
| 271 | |
| 272 | } |