3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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_OnlineContributionTest
32 class WebTest_Campaign_OnlineContributionTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public 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
78 'edit-2-administer-civicampaign',
79 'edit-1-make-online-contributions',
80 'edit-1-profile-listings-and-forms',
82 $this->changePermissions($permissions);
84 // Log in as normal user
85 $this->webtestLogin();
86 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
88 $campaignTitle = "Campaign $title";
89 $this->type("title", $campaignTitle);
91 // select the campaign type
92 $this->select("campaign_type_id", "value=2");
94 // fill in the description
95 $this->type("description", "This is a test campaign");
97 // include groups for the campaign
98 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
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("//div[@id='campaignList']/div/table/tbody//tr/td[3]/div[text()='{$campaignTitle}']/../../td[1]");
113 $id = (int) $this->getText("//div[@id='campaignList']/div/table/tbody//tr/td[3]/div[text()='{$campaignTitle}']/../../td[1]");
115 $this->onlineContributionAddTest($campaignTitle, $id);
119 * @param $campaignTitle
122 public function onlineContributionAddTest($campaignTitle, $id) {
123 // Use default payment processor
124 $processorName = 'Test Processor';
125 $paymentProcessorId = $this->webtestAddPaymentProcessor($processorName);
127 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
129 $contributionTitle = substr(sha1(rand()), 0, 7);
130 $rand = 2 * rand(2, 50);
132 // fill in step 1 (Title and Settings)
133 $contributionPageTitle = "Title $contributionTitle";
134 $this->type('title', $contributionPageTitle);
135 $this->select('financial_type_id', 'value=1');
138 $this->click("campaign_id");
139 $this->select("campaign_id", "value=$id");
141 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
142 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
145 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
147 // Get contribution page id
148 $pageId = $this->urlArg('id');
150 //this contribution page for online contribution
151 $this->check("payment_processor[{$paymentProcessorId}]");
152 $this->assertElementContainsText('crm-container', "Contribution Amounts section enabled");
153 $this->type("label_1", "amount 1");
154 $this->type("value_1", "100");
155 $this->type("label_2", "amount 2");
156 $this->type("value_2", "200");
157 $this->click("xpath=//*[@id='map-field-table']//tr[2]//input[1][@name='default']");
159 $this->click("_qf_Amount_next-bottom");
160 $this->waitForPageToLoad($this->getTimeoutMsec());
163 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Receipt']");
164 $this->waitForElementPresent('_qf_ThankYou_next-bottom');
166 // fill in step 4 (Thanks and Receipt)
167 $this->type('thankyou_title', "Thank-you Page Title $contributionTitle");
168 $this->type('receipt_from_name', "Receipt From Name $contributionTitle");
169 $this->type('receipt_from_email', "$contributionTitle@example.org");
170 $this->type('receipt_text', "Receipt Message $contributionTitle");
171 $this->type('cc_receipt', "$contributionTitle@example.net");
172 $this->type('bcc_receipt', "$contributionTitle@example.com");
174 $this->click('_qf_ThankYou_next-bottom');
175 $this->waitForPageToLoad($this->getTimeoutMsec());
178 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Tell a Friend']");
179 $this->waitForElementPresent("_qf_Contribute_next-bottom");
181 // fill in step 5 (Tell a Friend)
182 $this->click('tf_is_active');
183 $this->type('tf_title', "TaF Title $contributionTitle");
184 $this->type('intro', "TaF Introduction $contributionTitle");
185 $this->type('suggested_message', "TaF Suggested Message $contributionTitle");
186 $this->type('general_link', "TaF Info Page Link $contributionTitle");
187 $this->type('tf_thankyou_title', "TaF Thank-you Title $contributionTitle");
188 $this->type('tf_thankyou_text', "TaF Thank-you Message $contributionTitle");
190 $this->click('_qf_Contribute_next-bottom');
191 $this->waitForPageToLoad($this->getTimeoutMsec());
194 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Profiles']");
195 $this->waitForElementPresent("_qf_Custom_next-bottom");
197 // fill in step 6 (Include Profiles)
198 $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_pre_id span.crm-profile-selector-select select', 'value=1');
200 $this->click('_qf_Custom_next-bottom');
201 $this->waitForPageToLoad($this->getTimeoutMsec());
204 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Premiums']");
205 $this->waitForElementPresent("_qf_Premium_next-bottom");
207 // fill in step 7 (Premiums)
208 $this->click('premiums_active');
209 $this->type('premiums_intro_title', "Prem Title $contributionTitle");
210 $this->type('premiums_intro_text', "Prem Introductory Message $contributionTitle");
211 $this->type('premiums_contact_email', "$contributionTitle@example.info");
212 $this->type('premiums_contact_phone', rand(100000000, 999999999));
213 $this->click('premiums_display_min_contribution');
214 $this->type('premiums_nothankyou_label', "No Thank you ");
216 $this->click('_qf_Premium_next-bottom');
217 $this->waitForPageToLoad($this->getTimeoutMsec());
220 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Widgets']");
221 $this->waitForElementPresent("_qf_Widget_next-bottom");
223 // fill in step 8 (Widget Settings)
224 $this->click('is_active');
225 $this->type('url_logo', "URL to Logo Image $contributionTitle");
226 $this->type('button_title', "Button Title $contributionTitle");
227 $this->type('about', "About $contributionTitle");
229 $this->click('_qf_Widget_next-bottom');
230 $this->waitForPageToLoad($this->getTimeoutMsec());
233 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Personal Campaigns']");
234 $this->waitForElementPresent("_qf_Contribute_next-bottom");
236 // fill in step 9 (Enable Personal Campaign Pages)
237 $this->click('pcp_active');
238 $this->click('is_approval_needed');
239 $this->type('notify_email', "$contributionTitle@example.name");
240 $this->select('supporter_profile_id', 'value=2');
241 $this->type('tellfriend_limit', 7);
242 $this->type('link_text', "'Create Personal Campaign Page' link text $contributionTitle");
244 // submit new contribution page
245 $this->click('_qf_Contribute_next-bottom');
246 $this->waitForPageToLoad($this->getTimeoutMsec());
248 // Make sure our page shows up in search results
249 $this->openCiviPage("admin/contribute", "reset=1", "_qf_SearchContribution_refresh");
250 $this->type('title', $contributionPageTitle);
251 $this->click("_qf_SearchContribution_refresh");
252 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
253 $url = $this->assertElementContainsText("//div[@id='configure_contribution_page']//table/tbody", $contributionPageTitle);
256 $this->webtestLogout();
258 //Open Live Contribution Page
259 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId&action=preview", '_qf_Main_upload-bottom');
261 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
262 $lastName = 'An' . substr(sha1(rand()), 0, 7);
263 $this->type("first_name", $firstName);
264 $this->type("last_name", $lastName);
266 $this->type("email-5", $firstName . "@example.com");
268 $streetAddress = "100 Main Street";
269 $this->type("street_address-1", $streetAddress);
270 $this->type("city-1", "San Francisco");
271 $this->type("postal_code-1", "94117");
272 $this->select("country-1", "value=1228");
273 $this->select("state_province-1", "value=1001");
276 $this->select("credit_card_type", "value=Visa");
277 $this->type("credit_card_number", "4111111111111111");
278 $this->type("cvv2", "000");
279 $this->select("credit_card_exp_date[M]", "value=1");
280 $this->select("credit_card_exp_date[Y]", "value=2020");
283 $this->type("billing_first_name", $firstName . "billing");
284 $this->type("billing_last_name", $lastName . "billing");
285 $this->type("billing_street_address-5", "15 Main St.");
286 $this->type(" billing_city-5", "San Jose");
287 $this->select("billing_country_id-5", "value=1228");
288 $this->select("billing_state_province_id-5", "value=1004");
289 $this->type("billing_postal_code-5", "94129");
290 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
292 $this->clickLink("_qf_Confirm_next-bottom", NULL);
294 //login to check contribution
295 $this->webtestLogin();
298 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
299 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
300 $this->type("sort_name", "$lastName $firstName");
301 $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE);
302 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
303 //View Contribution Record
304 $this->assertElementContainsText("xpath=//form[@class='CRM_Contribute_Form_ContributionView']/div[2]//table[1]/tbody/tr[10]/td[2]", $campaignTitle);