3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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_OfflineContributionTest
32 class WebTest_Campaign_OfflineContributionTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testCreateCampaign() {
39 $this->webtestLogin('admin');
42 $title = substr(sha1(rand()), 0, 7);
43 $groupName = $this->WebtestAddGroup();
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");
50 // add contact to group
52 $this->click("css=li#tab_group a");
53 $this->waitForElementPresent("group_id");
56 $this->select("group_id", "label=$groupName");
57 $this->click("_qf_GroupContact_next");
58 $this->waitForElementPresent('link=Remove');
60 $firstName2 = substr(sha1(rand()), 0, 7);
61 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
63 // add contact to group
65 $this->click("css=li#tab_group a");
66 $this->waitForElementPresent("group_id");
69 $this->select("group_id", "label=$groupName");
70 $this->click("_qf_GroupContact_next");
71 $this->waitForElementPresent('link=Remove');
73 // Enable CiviCampaign module if necessary
74 $this->enableComponents(array('CiviCampaign'));
76 // add the required permission
77 $this->changePermissions('edit-2-administer-civicampaign');
79 // Log in as normal user
80 $this->webtestLogin();
82 $this->openCiviPage('campaign', 'reset=1', "link=Add Campaign");
83 if ($this->isTextPresent('No campaigns 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.');
87 $this->openCiviPage('campaign/add', 'reset=1');
89 $campaignTitle = "Campaign $title";
90 $this->type("title", $campaignTitle);
92 // select the campaign type
93 $this->select("campaign_type_id", "value=2");
95 // fill in the description
96 $this->type("description", "This is a test campaign");
98 // include groups for the campaign
99 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
101 // fill the end date for campaign
102 $this->webtestFillDate("end_date", "+1 year");
104 // select campaign status
105 $this->select("status_id", "value=2");
108 $this->clickLink("_qf_Campaign_upload-bottom");
110 $this->checkCRMAlert("Campaign $title");
112 $this->waitForElementPresent("//td[text()='$campaignTitle']");
113 $campaignId = $this->urlArg('id', $this->getAttribute("//td[text()='$campaignTitle']/../td[13]/span/a[text()='Edit']@href"));
115 $this->offlineContributionTest($campaignTitle, $campaignId);
117 $this->pastCampaignsTest($groupName);
121 * @param $campaignTitle
125 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);
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");
136 // go to contribution tab and add contribution.
137 $this->click("css=li#tab_contribute a");
139 // wait for Record Contribution elenment.
140 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
141 $this->click("link=Record Contribution (Check, Cash, EFT ...)");
143 $this->waitForElementPresent("_qf_Contribution_cancel-bottom");
145 // fill financial type.
146 $this->select("financial_type_id", "Donation");
148 // fill in Received Date
149 $this->webtestFillDate('receive_date');
152 $this->type("source", "Mailer 1");
155 $this->click("include-past-campaigns");
156 $this->waitForElementPresent("css=#campaign_id option[value=$id]");
159 $this->select("campaign_id", "value=$id");
162 $this->type("total_amount", "100");
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");
169 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
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');
177 //Additional Detail section
178 $this->click("AdditionalDetail");
179 $this->waitForElementPresent("thankyou_date");
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');
190 $this->click("Premium");
191 $this->waitForElementPresent("fulfilled_date");
192 $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )");
193 $this->select("product_name[1]", "label=Black");
194 $this->webtestFillDate('fulfilled_date');
197 $this->click("_qf_Contribution_upload-bottom");
199 // Is status message correct?
200 $this->checkCRMAlert("The contribution record has been saved.");
202 $this->waitForElementPresent("xpath=//*[@id='Search']//div[2]//table[2]/tbody/tr/td[8]/span/a[text()='View']");
204 // click through to the Contribution view screen
205 $this->click("xpath=//*[@id='Search']//div[2]//table[2]/tbody/tr/td[8]/span/a[text()='View']");
206 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
208 // verify Contribution created
209 $this->webtestVerifyTabularData(array('Campaign' => $campaignTitle));
212 // when campaign component is disabled
213 $this->openCiviPage('admin/setting/component', 'reset=1', '_qf_Component_next-bottom');
214 $this->addSelection("enableComponents-t", "label=CiviCampaign");
215 $this->click("//option[@value='CiviCampaign']");
216 $this->click("remove");
217 $this->clickLink("_qf_Component_next-bottom");
219 $this->checkCRMAlert("Changes Saved.");
221 $this->openCiviPage('contribute/search', 'reset=1', '_qf_Search_refresh');
223 $this->type('sort_name', $firstName);
224 $this->click("_qf_Search_refresh");
225 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']");
226 $this->click("xpath=//div[@id='contributionSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']");
227 $this->waitForElementPresent("_qf_Contribution_cancel-bottom");
228 $this->assertTrue($this->isTextPresent("$campaignTitle"));
235 function pastCampaignsTest($groupName) {
236 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
238 $pastTitle = substr(sha1(rand()), 0, 7);
239 $pastCampaignTitle = "Past Campaign $pastTitle";
240 $this->type("title", $pastCampaignTitle);
242 // select the campaign type
243 $this->select("campaign_type_id", "value=2");
245 // fill in the description
246 $this->type("description", "This is a test for past campaign");
248 // include groups for the campaign
249 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
251 // fill the start date for campaign
252 $this->webtestFillDate("start_date", "1 January " . (date('Y') - 1));
254 // fill the end date for campaign
255 $this->webtestFillDate("end_date", "31 January " . (date('Y') - 1));
257 // select campaign status
258 $this->select("status_id", "value=3");
261 $this->clickLink("_qf_Campaign_upload-bottom");
262 $this->checkCRMAlert("Campaign $pastCampaignTitle has been saved.");
264 $this->waitForElementPresent("link=Add Campaign");
265 $this->waitForElementPresent("link=Campaigns");
266 $this->click("search_form_campaign");
267 $this->type("campaign_title", $pastCampaignTitle);
268 $this->clickAjaxLink("//a[text()='Search']", "//td[text()='$pastCampaignTitle']");
269 $campaignId = $this->urlArg('id', $this->getAttribute("//td[text()='$pastCampaignTitle']/../td[13]/span/a[text()='Edit']@href"));
271 $this->offlineContributionTest($pastCampaignTitle, $campaignId, TRUE);