remove duplicate assignments
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / OfflineContributionTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
25*/
26
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Campaign_OfflineContributionTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testCreateCampaign() {
42daf119 35 $this->webtestLogin('admin');
6a488035
TO
36
37 // Create new group
38 $title = substr(sha1(rand()), 0, 7);
39 $groupName = $this->WebtestAddGroup();
40
41 // Adding contact
42 // We're using Quick Add block on the main page for this.
43 $firstName1 = substr(sha1(rand()), 0, 7);
44 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
45
46 // add contact to group
47 // visit group tab
48 $this->click("css=li#tab_group a");
49 $this->waitForElementPresent("group_id");
50
51 // add to group
52 $this->select("group_id", "label=$groupName");
53 $this->click("_qf_GroupContact_next");
2af8120a 54 $this->waitForElementPresent('link=Remove');
6a488035
TO
55
56 $firstName2 = substr(sha1(rand()), 0, 7);
57 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
58
59 // add contact to group
60 // visit group tab
61 $this->click("css=li#tab_group a");
62 $this->waitForElementPresent("group_id");
63
64 // add to group
65 $this->select("group_id", "label=$groupName");
66 $this->click("_qf_GroupContact_next");
2af8120a 67 $this->waitForElementPresent('link=Remove');
6a488035
TO
68
69 // Enable CiviCampaign module if necessary
8f737a72 70 $this->enableComponents(array('CiviCampaign'));
6a488035 71
42daf119
CW
72 // add the required permission
73 $this->changePermissions('edit-2-administer-civicampaign');
74
75 // Log in as normal user
76 $this->webtestLogin();
6a488035 77
8f737a72 78 $this->openCiviPage('campaign', 'reset=1', "link=Add Campaign");
6a488035 79 if ($this->isTextPresent('No campaigns found.')) {
8f737a72
RN
80 $this->openCiviPage('contribute/add', 'reset=1&action=add&context=standalone', '_qf_Contribution_cancel-bottom');
81 $this->assertElementContainsText('crm-container', 'There are currently no active Campaigns.');
6a488035 82 }
8f737a72 83 $this->openCiviPage('campaign/add', 'reset=1');
6a488035 84
6a488035
TO
85 $campaignTitle = "Campaign $title";
86 $this->type("title", $campaignTitle);
87
88 // select the campaign type
89 $this->select("campaign_type_id", "value=2");
90
91 // fill in the description
92 $this->type("description", "This is a test campaign");
93
94 // include groups for the campaign
95 $this->addSelection("includeGroups-f", "label=$groupName");
96 $this->click("//option[@value=4]");
97 $this->click("add");
98
99 // fill the end date for campaign
100 $this->webtestFillDate("end_date", "+1 year");
101
102 // select campaign status
103 $this->select("status_id", "value=2");
104
105 // click save
106 $this->click("_qf_Campaign_upload-bottom");
107 $this->waitForPageToLoad($this->getTimeoutMsec());
108
6c5f7368 109 $this->waitForText('crm-notification-container', "Campaign $title");
6a488035
TO
110
111 $this->waitForElementPresent("xpath=//div[@id='campaignList']/div[@id='campaigns_wrapper']/table[@id='campaigns']/tbody//tr/td[text()='$campaignTitle']");
112 $url = explode('id=', $this->getAttribute("xpath=//div[@id='campaignList']/div[@id='campaigns_wrapper']/table[@id='campaigns']/tbody//tr/td[text()='$campaignTitle']/../td[13]/span/a[text()='Edit']@href"));
113 $campaignId = $url[1];
114
115 $this->offlineContributionTest($campaignTitle, $campaignId);
116
117 $this->pastCampaignsTest($groupName);
118 }
119
120 function offlineContributionTest($campaignTitle, $id, $past = FALSE) {
121 // Create a contact to be used as soft creditor
122 $softCreditFname = substr(sha1(rand()), 0, 7);
123 $softCreditLname = substr(sha1(rand()), 0, 7);
124 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
125
126 // Adding contact with randomized first name (so we can then select that contact when creating contribution.)
127 // We're using Quick Add block on the main page for this.
128 $firstName = substr(sha1(rand()), 0, 7);
129 $this->webtestAddContact($firstName, "Summerson", $firstName . "@summerson.name");
130
131 // go to contribution tab and add contribution.
132 $this->click("css=li#tab_contribute a");
133
134 // wait for Record Contribution elenment.
135 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
136 $this->click("link=Record Contribution (Check, Cash, EFT ...)");
137
138 $this->waitForElementPresent("_qf_Contribution_cancel-bottom");
59445490 139
140 // fill financial type.
141 $this->select("financial_type_id", "Donation");
6a488035
TO
142
143 // fill in Received Date
144 $this->webtestFillDate('receive_date');
145
146 // source
147 $this->type("source", "Mailer 1");
148
149 if ($past) {
150 $this->click("include-past-campaigns");
efb29358
CW
151 // Because it tends to cause problems, all uses of sleep() must be justified in comments
152 // Sleep should never be used for wait for anything to load from the server
153 // FIXME: Use a better method for waiting for this AJAX call - sleep is not going to work!
6a488035
TO
154 sleep(2);
155 }
156
157 $this->click("campaign_id");
158 $this->select("campaign_id", "value=$id");
159
160 // total amount
161 $this->type("total_amount", "100");
162
163 // select payment instrument type = Check and enter chk number
164 $this->select("payment_instrument_id", "value=4");
165 $this->waitForElementPresent("check_number");
166 $this->type("check_number", "check #1041");
167
168 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
169
170 // soft credit
2af8120a
AS
171 $this->click("xpath=id('Contribution')/div[2]/div[@id='softCredit']/div[1]");
172 $this->type("soft_credit_amount_1", "50");
173 $this->waitForElementPresent("soft_credit_contact_id_1");
174 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_id_1');
6a488035
TO
175
176 //Additional Detail section
177 $this->click("AdditionalDetail");
178 $this->waitForElementPresent("thankyou_date");
179
180 $this->type("note", "Test note for {$firstName}.");
181 $this->type("non_deductible_amount", "10");
182 $this->type("fee_amount", "0");
183 $this->type("net_amount", "0");
184 $this->type("invoice_id", time());
185 $this->webtestFillDate('thankyou_date');
186
6a488035
TO
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");
6a488035
TO
197
198 // Is status message correct?
2af8120a 199 $this->waitForText('crm-notification-container', "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");
216 $this->click("_qf_Component_next-bottom");
217 $this->waitForPageToLoad($this->getTimeoutMsec());
218 $this->assertTrue($this->isTextPresent("Changes Saved."));
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
231 function pastCampaignsTest($groupName) {
8f737a72 232 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
6a488035 233
6a488035
TO
234 $pastTitle = substr(sha1(rand()), 0, 7);
235 $pastCampaignTitle = "Past Campaign $pastTitle";
236 $this->type("title", $pastCampaignTitle);
237
238 // select the campaign type
239 $this->select("campaign_type_id", "value=2");
240
241 // fill in the description
242 $this->type("description", "This is a test for past campaign");
243
244 // include groups for the campaign
245 $this->addSelection("includeGroups-f", "label=$groupName");
246 $this->click("//option[@value=4]");
247 $this->click("add");
248
249 // fill the start date for campaign
250 $this->webtestFillDate("start_date", "1 January 2011");
251
252 // fill the end date for campaign
253 $this->webtestFillDate("end_date", "31 January 2011");
254
255 // select campaign status
256 $this->select("status_id", "value=3");
257
258 // click save
259 $this->click("_qf_Campaign_upload-bottom");
2af8120a
AS
260 $this->waitForElementPresent("//*[@id='crm-notification-container']");
261 $this->waitForText('crm-notification-container', "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);
267 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[4]/td/a[text()='Search']");
268
269 $this->waitForElementPresent("xpath=//div[@id='campaignList']/div[@id='campaigns_wrapper']/table[@id='campaigns']/tbody//tr/td[text()='$pastCampaignTitle']");
270 $url = explode('id=', $this->getAttribute("xpath=//div[@id='campaignList']/div[@id='campaigns_wrapper']/table[@id='campaigns']/tbody//tr/td[text()='$pastCampaignTitle']/../td[13]/span/a[text()='Edit']@href"));
271 $campaignId = $url[1];
272
273 $this->offlineContributionTest($pastCampaignTitle, $campaignId, TRUE);
274 }
275}
276