version fixes
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / OfflineContributionTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Campaign_OfflineContributionTest
31 */
6a488035
TO
32class WebTest_Campaign_OfflineContributionTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testCreateCampaign() {
42daf119 39 $this->webtestLogin('admin');
6a488035
TO
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");
2af8120a 58 $this->waitForElementPresent('link=Remove');
6a488035
TO
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");
2af8120a 71 $this->waitForElementPresent('link=Remove');
6a488035
TO
72
73 // Enable CiviCampaign module if necessary
8f737a72 74 $this->enableComponents(array('CiviCampaign'));
6a488035 75
42daf119
CW
76 // add the required permission
77 $this->changePermissions('edit-2-administer-civicampaign');
78
79 // Log in as normal user
80 $this->webtestLogin();
6a488035 81
8f737a72 82 $this->openCiviPage('campaign', 'reset=1', "link=Add Campaign");
1eba7e53 83 if ($this->isTextPresent('None found.')) {
8f737a72
RN
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.');
6a488035 86 }
8f737a72 87 $this->openCiviPage('campaign/add', 'reset=1');
6a488035 88
6a488035
TO
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
aeaa5f5d 99 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
6a488035
TO
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
e42c089b 108 $this->clickLink("_qf_Campaign_upload-bottom");
6a488035 109
e42c089b 110 $this->checkCRMAlert("Campaign $title");
6a488035 111
131d5a64
WA
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"));
6a488035
TO
114
115 $this->offlineContributionTest($campaignTitle, $campaignId);
116
117 $this->pastCampaignsTest($groupName);
118 }
119
4cbe18b8
EM
120 /**
121 * @param $campaignTitle
100fef9d 122 * @param int $id
4cbe18b8
EM
123 * @param bool $past
124 */
00be9182 125 public function offlineContributionTest($campaignTitle, $id, $past = FALSE) {
6a488035
TO
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");
59445490 144
145 // fill financial type.
146 $this->select("financial_type_id", "Donation");
6a488035
TO
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");
e42c089b 156 $this->waitForElementPresent("css=#campaign_id option[value=$id]");
6a488035
TO
157 }
158
6a488035
TO
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
2af8120a
AS
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');
6a488035
TO
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
6a488035
TO
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");
6a488035
TO
197
198 // Is status message correct?
e42c089b 199 $this->checkCRMAlert("The contribution record has been saved.");
6a488035 200
2af8120a 201 $this->waitForElementPresent("xpath=//*[@id='Search']//div[2]//table[2]/tbody/tr/td[8]/span/a[text()='View']");
6a488035
TO
202
203 // click through to the Contribution view screen
2af8120a 204 $this->click("xpath=//*[@id='Search']//div[2]//table[2]/tbody/tr/td[8]/span/a[text()='View']");
6a488035
TO
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
8f737a72 212 $this->openCiviPage('admin/setting/component', 'reset=1', '_qf_Component_next-bottom');
6a488035
TO
213 $this->addSelection("enableComponents-t", "label=CiviCampaign");
214 $this->click("//option[@value='CiviCampaign']");
215 $this->click("remove");
e42c089b
CW
216 $this->clickLink("_qf_Component_next-bottom");
217
4481526f 218 $this->checkCRMAlert("Changes Saved");
6a488035 219
76e86fd8 220 $this->openCiviPage('contribute/search', 'reset=1', '_qf_Search_refresh');
6a488035
TO
221
222 $this->type('sort_name', $firstName);
223 $this->click("_qf_Search_refresh");
2af8120a 224 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']");
6a488035
TO
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
4cbe18b8 231 /**
100fef9d 232 * @param string $groupName
4cbe18b8 233 */
00be9182 234 public function pastCampaignsTest($groupName) {
8f737a72 235 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
6a488035 236
6a488035
TO
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
aeaa5f5d 248 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
6a488035
TO
249
250 // fill the start date for campaign
e42c089b 251 $this->webtestFillDate("start_date", "1 January " . (date('Y') - 1));
6a488035
TO
252
253 // fill the end date for campaign
e42c089b 254 $this->webtestFillDate("end_date", "31 January " . (date('Y') - 1));
6a488035
TO
255
256 // select campaign status
257 $this->select("status_id", "value=3");
258
259 // click save
e42c089b
CW
260 $this->clickLink("_qf_Campaign_upload-bottom");
261 $this->checkCRMAlert("Campaign $pastCampaignTitle has been saved.");
6a488035
TO
262
263 $this->waitForElementPresent("link=Add Campaign");
2af8120a 264 $this->waitForElementPresent("link=Campaigns");
6a488035
TO
265 $this->click("search_form_campaign");
266 $this->type("campaign_title", $pastCampaignTitle);
131d5a64
WA
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"));
6a488035
TO
269
270 $this->offlineContributionTest($pastCampaignTitle, $campaignId, TRUE);
271 }
96025800 272
6a488035 273}