3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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';
28 class WebTest_Campaign_OfflineContributionTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testCreateCampaign() {
35 $this->webtestLogin('admin');
38 $title = substr(sha1(rand()), 0, 7);
39 $groupName = $this->WebtestAddGroup();
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");
46 // add contact to group
48 $this->click("css=li#tab_group a");
49 $this->waitForElementPresent("group_id");
52 $this->select("group_id", "label=$groupName");
53 $this->click("_qf_GroupContact_next");
54 $this->waitForPageToLoad($this->getTimeoutMsec());
56 $firstName2 = substr(sha1(rand()), 0, 7);
57 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
59 // add contact to group
61 $this->click("css=li#tab_group a");
62 $this->waitForElementPresent("group_id");
65 $this->select("group_id", "label=$groupName");
66 $this->click("_qf_GroupContact_next");
67 $this->waitForPageToLoad($this->getTimeoutMsec());
69 // Enable CiviCampaign module if necessary
70 $this->enableComponents(array('CiviCampaign'));
72 // add the required permission
73 $this->changePermissions('edit-2-administer-civicampaign');
75 // Log in as normal user
76 $this->webtestLogin();
78 $this->openCiviPage('campaign', 'reset=1', "link=Add Campaign");
79 if ($this->isTextPresent('No campaigns found.')) {
81 $this->openCiviPage('contribute/add', 'reset=1&action=add&context=standalone', '_qf_Contribution_cancel-bottom');
82 $this->assertElementContainsText('crm-container', 'There are currently no active Campaigns.');
84 $this->openCiviPage('campaign/add', 'reset=1');
86 $campaignTitle = "Campaign $title";
87 $this->type("title", $campaignTitle);
89 // select the campaign type
90 $this->select("campaign_type_id", "value=2");
92 // fill in the description
93 $this->type("description", "This is a test campaign");
95 // include groups for the campaign
96 $this->addSelection("includeGroups-f", "label=$groupName");
97 $this->click("//option[@value=4]");
100 // fill the end date for campaign
101 $this->webtestFillDate("end_date", "+1 year");
103 // select campaign status
104 $this->select("status_id", "value=2");
107 $this->click("_qf_Campaign_upload-bottom");
108 $this->waitForPageToLoad($this->getTimeoutMsec());
110 $this->waitForText('crm-notification-container', "Campaign $title");
112 $this->waitForElementPresent("xpath=//div[@id='campaignList']/div[@id='campaigns_wrapper']/table[@id='campaigns']/tbody//tr/td[text()='$campaignTitle']");
113 $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"));
114 $campaignId = $url[1];
116 $this->offlineContributionTest($campaignTitle, $campaignId);
118 $this->pastCampaignsTest($groupName);
121 function offlineContributionTest($campaignTitle, $id, $past = FALSE) {
122 // Create a contact to be used as soft creditor
123 $softCreditFname = substr(sha1(rand()), 0, 7);
124 $softCreditLname = substr(sha1(rand()), 0, 7);
125 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
127 // Adding contact with randomized first name (so we can then select that contact when creating contribution.)
128 // We're using Quick Add block on the main page for this.
129 $firstName = substr(sha1(rand()), 0, 7);
130 $this->webtestAddContact($firstName, "Summerson", $firstName . "@summerson.name");
132 // go to contribution tab and add contribution.
133 $this->click("css=li#tab_contribute a");
135 // wait for Record Contribution elenment.
136 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
137 $this->click("link=Record Contribution (Check, Cash, EFT ...)");
139 $this->waitForElementPresent("_qf_Contribution_cancel-bottom");
140 // fill financial type.
141 $this->select("financial_type_id", "Donation");
143 // fill in Received Date
144 $this->webtestFillDate('receive_date');
147 $this->type("source", "Mailer 1");
150 $this->click("include-past-campaigns");
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!
157 $this->click("campaign_id");
158 $this->select("campaign_id", "value=$id");
161 $this->type("total_amount", "100");
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");
168 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
171 $this->click("soft_credit_to");
172 $this->type("soft_credit_to", $softCreditFname);
173 $this->typeKeys("soft_credit_to", $softCreditFname);
174 $this->waitForElementPresent("css=div.ac_results-inner li");
175 $this->click("css=div.ac_results-inner li");
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');
189 $this->click("Honoree");
190 $this->waitForElementPresent("honor_email");
192 $this->click("CIVICRM_QFID_1_2");
193 $this->select("honor_prefix_id", "label=Ms.");
194 $this->type("honor_first_name", "Foo");
195 $this->type("honor_last_name", "Bar");
196 $this->type("honor_email", "foo@bar.com");
199 $this->click("Premium");
200 $this->waitForElementPresent("fulfilled_date");
201 $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )");
202 $this->select("product_name[1]", "label=Black");
203 $this->webtestFillDate('fulfilled_date');
206 $this->click("_qf_Contribution_upload-bottom");
207 $this->waitForPageToLoad($this->getTimeoutMsec());
209 // Is status message correct?
210 $this->waitForText('crm-notification-container', "The contribution record has been saved");
212 $this->waitForElementPresent("xpath=//div[@id='Contributions']//table/tbody/tr/td[8]/span/a[text()='View']");
214 // click through to the Contribution view screen
215 $this->click("xpath=//div[@id='Contributions']//table/tbody/tr/td[8]/span/a[text()='View']");
216 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
218 // verify Contribution created
219 $this->webtestVerifyTabularData(array('Campaign' => $campaignTitle));
222 // when campaign component is disabled
223 $this->openCiviPage('admin/setting/component', 'reset=1', '_qf_Component_next-bottom');
224 $this->addSelection("enableComponents-t", "label=CiviCampaign");
225 $this->click("//option[@value='CiviCampaign']");
226 $this->click("remove");
227 $this->click("_qf_Component_next-bottom");
228 $this->waitForPageToLoad($this->getTimeoutMsec());
229 $this->assertTrue($this->isTextPresent("Changes Saved."));
231 $this->openCiviPage('contribute/search', 'reset=1', '_qf_Search_refresh');
233 $this->type('sort_name', $firstName);
234 $this->click("_qf_Search_refresh");
235 $this->waitForElementPresent("_qf_Search_next_print");
236 $this->click("xpath=//div[@id='contributionSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']");
237 $this->waitForElementPresent("_qf_Contribution_cancel-bottom");
238 $this->assertTrue($this->isTextPresent("$campaignTitle"));
242 function pastCampaignsTest($groupName) {
243 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
245 $pastTitle = substr(sha1(rand()), 0, 7);
246 $pastCampaignTitle = "Past Campaign $pastTitle";
247 $this->type("title", $pastCampaignTitle);
249 // select the campaign type
250 $this->select("campaign_type_id", "value=2");
252 // fill in the description
253 $this->type("description", "This is a test for past campaign");
255 // include groups for the campaign
256 $this->addSelection("includeGroups-f", "label=$groupName");
257 $this->click("//option[@value=4]");
260 // fill the start date for campaign
261 $this->webtestFillDate("start_date", "1 January 2011");
263 // fill the end date for campaign
264 $this->webtestFillDate("end_date", "31 January 2011");
266 // select campaign status
267 $this->select("status_id", "value=3");
270 $this->click("_qf_Campaign_upload-bottom");
271 $this->waitForPageToLoad($this->getTimeoutMsec());
273 $this->assertTrue($this->isTextPresent("Campaign $pastCampaignTitle has been saved."),
274 "Status message didn't show up after saving campaign!"
277 $this->waitForElementPresent("link=Add Campaign");
279 $this->waitForElementPresent("Campaigns");
280 $this->click("search_form_campaign");
281 $this->type("campaign_title", $pastCampaignTitle);
282 $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[4]/td/a[text()='Search']");
284 $this->waitForElementPresent("xpath=//div[@id='campaignList']/div[@id='campaigns_wrapper']/table[@id='campaigns']/tbody//tr/td[text()='$pastCampaignTitle']");
285 $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"));
286 $campaignId = $url[1];
288 $this->offlineContributionTest($pastCampaignTitle, $campaignId, TRUE);