Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Campaign_OnlineContributionTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Campaign_OnlineContributionTest 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"); | |
701f18c0 | 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"); | |
701f18c0 | 71 | $this->waitForElementPresent('link=Remove'); |
6a488035 TO |
72 | |
73 | // Enable CiviCampaign module if necessary | |
9042f10e | 74 | $this->enableComponents(array('CiviCampaign')); |
6a488035 | 75 | |
42daf119 | 76 | // add the required permission |
6a488035 TO |
77 | $permissions = array( |
78 | 'edit-2-administer-civicampaign', | |
79 | 'edit-1-make-online-contributions', | |
80 | 'edit-1-profile-listings-and-forms', | |
81 | ); | |
82 | $this->changePermissions($permissions); | |
83 | ||
42daf119 CW |
84 | // Log in as normal user |
85 | $this->webtestLogin(); | |
9042f10e | 86 | $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom"); |
6a488035 | 87 | |
6a488035 TO |
88 | $campaignTitle = "Campaign $title"; |
89 | $this->type("title", $campaignTitle); | |
90 | ||
91 | // select the campaign type | |
92 | $this->select("campaign_type_id", "value=2"); | |
93 | ||
94 | // fill in the description | |
95 | $this->type("description", "This is a test campaign"); | |
96 | ||
97 | // include groups for the campaign | |
aeaa5f5d | 98 | $this->multiselect2("includeGroups", array("$groupName", "Advisory Board")); |
6a488035 TO |
99 | |
100 | // fill the end date for campaign | |
101 | $this->webtestFillDate("end_date", "+1 year"); | |
102 | ||
103 | // select campaign status | |
104 | $this->select("status_id", "value=2"); | |
105 | ||
106 | // click save | |
107 | $this->click("_qf_Campaign_upload-bottom"); | |
108 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
109 | ||
6c5f7368 | 110 | $this->waitForText('crm-notification-container', "Campaign $title"); |
6a488035 | 111 | |
131d5a64 WA |
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]"); | |
6a488035 TO |
114 | |
115 | $this->onlineContributionAddTest($campaignTitle, $id); | |
116 | } | |
117 | ||
4cbe18b8 EM |
118 | /** |
119 | * @param $campaignTitle | |
100fef9d | 120 | * @param int $id |
4cbe18b8 | 121 | */ |
00be9182 | 122 | public function onlineContributionAddTest($campaignTitle, $id) { |
c3ad8633 CW |
123 | // Use default payment processor |
124 | $processorName = 'Test Processor'; | |
6a488035 TO |
125 | $paymentProcessorId = $this->webtestAddPaymentProcessor($processorName); |
126 | ||
9042f10e | 127 | $this->openCiviPage("admin/contribute/add", "reset=1&action=add"); |
6a488035 TO |
128 | |
129 | $contributionTitle = substr(sha1(rand()), 0, 7); | |
130 | $rand = 2 * rand(2, 50); | |
131 | ||
132 | // fill in step 1 (Title and Settings) | |
133 | $contributionPageTitle = "Title $contributionTitle"; | |
134 | $this->type('title', $contributionPageTitle); | |
481a74f4 | 135 | $this->select('financial_type_id', 'value=1'); |
6a488035 TO |
136 | |
137 | // select campaign | |
138 | $this->click("campaign_id"); | |
139 | $this->select("campaign_id", "value=$id"); | |
140 | ||
141 | $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor'); | |
142 | $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor'); | |
143 | ||
b45c587e CW |
144 | // Submit form |
145 | $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom"); | |
146 | ||
147 | // Get contribution page id | |
148 | $pageId = $this->urlArg('id'); | |
6a488035 TO |
149 | |
150 | //this contribution page for online contribution | |
151 | $this->check("payment_processor[{$paymentProcessorId}]"); | |
9042f10e | 152 | $this->assertElementContainsText('crm-container', "Contribution Amounts section enabled"); |
6a488035 TO |
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"); | |
701f18c0 | 157 | $this->click("xpath=//*[@id='map-field-table']//tr[2]//input[1][@name='default']"); |
6a488035 TO |
158 | |
159 | $this->click("_qf_Amount_next-bottom"); | |
160 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
161 | ||
162 | // go to step 4 | |
163 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Receipt']"); | |
164 | $this->waitForElementPresent('_qf_ThankYou_next-bottom'); | |
165 | ||
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"); | |
173 | ||
174 | $this->click('_qf_ThankYou_next-bottom'); | |
175 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
176 | ||
177 | // go to step 5 | |
178 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Tell a Friend']"); | |
179 | $this->waitForElementPresent("_qf_Contribute_next-bottom"); | |
180 | ||
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"); | |
189 | ||
190 | $this->click('_qf_Contribute_next-bottom'); | |
191 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
192 | ||
193 | // go to step 6 | |
194 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Profiles']"); | |
195 | $this->waitForElementPresent("_qf_Custom_next-bottom"); | |
196 | ||
197 | // fill in step 6 (Include Profiles) | |
701f18c0 | 198 | $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_pre_id span.crm-profile-selector-select select', 'value=1'); |
6a488035 TO |
199 | |
200 | $this->click('_qf_Custom_next-bottom'); | |
201 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
202 | ||
203 | // go to step 7 | |
204 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Premiums']"); | |
205 | $this->waitForElementPresent("_qf_Premium_next-bottom"); | |
206 | ||
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 "); | |
215 | ||
216 | $this->click('_qf_Premium_next-bottom'); | |
217 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
218 | ||
219 | // go to step 8 | |
220 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Widgets']"); | |
221 | $this->waitForElementPresent("_qf_Widget_next-bottom"); | |
222 | ||
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"); | |
228 | ||
229 | $this->click('_qf_Widget_next-bottom'); | |
230 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
231 | ||
232 | // go to step 9 | |
233 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Personal Campaigns']"); | |
234 | $this->waitForElementPresent("_qf_Contribute_next-bottom"); | |
235 | ||
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"); | |
243 | ||
244 | // submit new contribution page | |
245 | $this->click('_qf_Contribute_next-bottom'); | |
246 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
247 | ||
b45c587e CW |
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); | |
6a488035 TO |
254 | |
255 | //logout | |
42daf119 | 256 | $this->webtestLogout(); |
6a488035 TO |
257 | |
258 | //Open Live Contribution Page | |
f1224701 | 259 | $this->openCiviPage('contribute/transact', "reset=1&id=$pageId&action=preview", '_qf_Main_upload-bottom'); |
b45c587e | 260 | |
6a488035 TO |
261 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); |
262 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
6a488035 TO |
263 | $this->type("first_name", $firstName); |
264 | $this->type("last_name", $lastName); | |
265 | ||
b45c587e CW |
266 | $this->type("email-5", $firstName . "@example.com"); |
267 | ||
6a488035 TO |
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"); | |
274 | ||
275 | //Credit Card Info | |
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"); | |
281 | ||
282 | //Billing Info | |
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"); | |
225a8648 | 290 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
6a488035 | 291 | |
b45c587e | 292 | $this->clickLink("_qf_Confirm_next-bottom", NULL); |
6a488035 TO |
293 | |
294 | //login to check contribution | |
6a488035 TO |
295 | $this->webtestLogin(); |
296 | ||
297 | //Find Contribution | |
9042f10e | 298 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
f1224701 | 299 | $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]"); |
b18eb8e1 | 300 | $this->type("sort_name", "$lastName $firstName"); |
deeea38d WA |
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); | |
6a488035 | 303 | //View Contribution Record |
b18eb8e1 | 304 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[11]/td[2]", preg_quote($campaignTitle)); |
6a488035 TO |
305 | } |
306 | ||
b9715b8a | 307 | } |