Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | class 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"); | |
54 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
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"); | |
67 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
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 | |
038dc0e3 | 171 | $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_1'); |
6a488035 TO |
172 | |
173 | //Additional Detail section | |
174 | $this->click("AdditionalDetail"); | |
175 | $this->waitForElementPresent("thankyou_date"); | |
176 | ||
177 | $this->type("note", "Test note for {$firstName}."); | |
178 | $this->type("non_deductible_amount", "10"); | |
179 | $this->type("fee_amount", "0"); | |
180 | $this->type("net_amount", "0"); | |
181 | $this->type("invoice_id", time()); | |
182 | $this->webtestFillDate('thankyou_date'); | |
183 | ||
184 | //Honoree section | |
185 | $this->click("Honoree"); | |
186 | $this->waitForElementPresent("honor_email"); | |
187 | ||
188 | $this->click("CIVICRM_QFID_1_2"); | |
189 | $this->select("honor_prefix_id", "label=Ms."); | |
190 | $this->type("honor_first_name", "Foo"); | |
191 | $this->type("honor_last_name", "Bar"); | |
192 | $this->type("honor_email", "foo@bar.com"); | |
193 | ||
194 | //Premium section | |
195 | $this->click("Premium"); | |
196 | $this->waitForElementPresent("fulfilled_date"); | |
197 | $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )"); | |
198 | $this->select("product_name[1]", "label=Black"); | |
199 | $this->webtestFillDate('fulfilled_date'); | |
200 | ||
201 | // Clicking save. | |
202 | $this->click("_qf_Contribution_upload-bottom"); | |
203 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
204 | ||
205 | // Is status message correct? | |
6c5f7368 | 206 | $this->waitForText('crm-notification-container', "The contribution record has been saved"); |
6a488035 TO |
207 | |
208 | $this->waitForElementPresent("xpath=//div[@id='Contributions']//table/tbody/tr/td[8]/span/a[text()='View']"); | |
209 | ||
210 | // click through to the Contribution view screen | |
211 | $this->click("xpath=//div[@id='Contributions']//table/tbody/tr/td[8]/span/a[text()='View']"); | |
212 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); | |
213 | ||
214 | // verify Contribution created | |
215 | $this->webtestVerifyTabularData(array('Campaign' => $campaignTitle)); | |
216 | ||
217 | if ($past) { | |
218 | // when campaign component is disabled | |
8f737a72 | 219 | $this->openCiviPage('admin/setting/component', 'reset=1', '_qf_Component_next-bottom'); |
6a488035 TO |
220 | $this->addSelection("enableComponents-t", "label=CiviCampaign"); |
221 | $this->click("//option[@value='CiviCampaign']"); | |
222 | $this->click("remove"); | |
223 | $this->click("_qf_Component_next-bottom"); | |
224 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
225 | $this->assertTrue($this->isTextPresent("Changes Saved.")); | |
226 | ||
76e86fd8 | 227 | $this->openCiviPage('contribute/search', 'reset=1', '_qf_Search_refresh'); |
6a488035 TO |
228 | |
229 | $this->type('sort_name', $firstName); | |
230 | $this->click("_qf_Search_refresh"); | |
231 | $this->waitForElementPresent("_qf_Search_next_print"); | |
232 | $this->click("xpath=//div[@id='contributionSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']"); | |
233 | $this->waitForElementPresent("_qf_Contribution_cancel-bottom"); | |
234 | $this->assertTrue($this->isTextPresent("$campaignTitle")); | |
235 | } | |
236 | } | |
237 | ||
238 | function pastCampaignsTest($groupName) { | |
8f737a72 | 239 | $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom'); |
6a488035 | 240 | |
6a488035 TO |
241 | $pastTitle = substr(sha1(rand()), 0, 7); |
242 | $pastCampaignTitle = "Past Campaign $pastTitle"; | |
243 | $this->type("title", $pastCampaignTitle); | |
244 | ||
245 | // select the campaign type | |
246 | $this->select("campaign_type_id", "value=2"); | |
247 | ||
248 | // fill in the description | |
249 | $this->type("description", "This is a test for past campaign"); | |
250 | ||
251 | // include groups for the campaign | |
252 | $this->addSelection("includeGroups-f", "label=$groupName"); | |
253 | $this->click("//option[@value=4]"); | |
254 | $this->click("add"); | |
255 | ||
256 | // fill the start date for campaign | |
257 | $this->webtestFillDate("start_date", "1 January 2011"); | |
258 | ||
259 | // fill the end date for campaign | |
260 | $this->webtestFillDate("end_date", "31 January 2011"); | |
261 | ||
262 | // select campaign status | |
263 | $this->select("status_id", "value=3"); | |
264 | ||
265 | // click save | |
266 | $this->click("_qf_Campaign_upload-bottom"); | |
267 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
268 | ||
269 | $this->assertTrue($this->isTextPresent("Campaign $pastCampaignTitle has been saved."), | |
270 | "Status message didn't show up after saving campaign!" | |
271 | ); | |
272 | ||
273 | $this->waitForElementPresent("link=Add Campaign"); | |
274 | ||
275 | $this->waitForElementPresent("Campaigns"); | |
276 | $this->click("search_form_campaign"); | |
277 | $this->type("campaign_title", $pastCampaignTitle); | |
278 | $this->click("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[4]/td/a[text()='Search']"); | |
279 | ||
280 | $this->waitForElementPresent("xpath=//div[@id='campaignList']/div[@id='campaigns_wrapper']/table[@id='campaigns']/tbody//tr/td[text()='$pastCampaignTitle']"); | |
281 | $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")); | |
282 | $campaignId = $url[1]; | |
283 | ||
284 | $this->offlineContributionTest($pastCampaignTitle, $campaignId, TRUE); | |
285 | } | |
286 | } | |
287 |