Merge pull request #2370 from kurund/CRM-14087
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / PCPAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contribute_PCPAddTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testPCPAdd() {
35 // open browser, login
36 $this->webtestLogin();
37
38 // set pcp supporter name and email
39 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
40 $lastName = 'An' . substr(sha1(rand()), 0, 7);
41 $middleName = 'Mid' . substr(sha1(rand()), 0, 7);
42 $email = substr(sha1(rand()), 0, 7) . '@example.org';
43
44 $this->openCiviPage("admin/domain", "action=update&reset=1", '_qf_Domain_cancel-bottom');
45 $this->type('name', 'DefaultDomain');
46 $this->type('email_name', $firstName);
47 $this->type('email_address', $email);
48
49 $this->click('_qf_Domain_next_view-bottom');
50 $this->waitForPageToLoad($this->getTimeoutMsec());
51 $this->assertTrue($this->isTextPresent("Domain information for 'DefaultDomain' has been saved."),
52 "Status message didn't show up after saving!"
53 );
54
55 require_once 'ContributionPageAddTest.php';
56
57 // a random 7-char string and an even number to make this pass unique
58 $hash = substr(sha1(rand()), 0, 7);
59 $rand = $contributionAmount = 2 * rand(2, 50);
60 $pageTitle = 'PCP Contribution' . $hash;
61 $processorType = 'Dummy';
62 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
63 $amountSection = TRUE;
64 $payLater = TRUE;
65 $onBehalf = FALSE;
66 $pledges = FALSE;
67 $recurring = FALSE;
68 $memberships = FALSE;
69 $memPriceSetId = NULL;
70 $friend = FALSE;
71 $profilePreId = NULL;
72 $profilePostId = NULL;
73 $premiums = FALSE;
74 $widget = FALSE;
75 $pcp = TRUE;
76 $isAprovalNeeded = TRUE;
77
78 // create a new online contribution page with pcp enabled
79 // create contribution page with randomized title and default params
80 $pageId = $this->webtestAddContributionPage($hash,
81 $rand,
82 $pageTitle,
83 array($processorName => $processorType),
84 $amountSection,
85 $payLater,
86 $onBehalf,
87 $pledges,
88 $recurring,
89 $memberships,
90 $memPriceSetId,
91 $friend,
92 $profilePreId,
93 $profilePostId,
94 $premiums,
95 $widget,
96 $pcp,
97 TRUE,
98 $isAprovalNeeded
99 );
100
101 // logout
102 $this->webtestLogout();
103
104 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", "_qf_Main_upload-bottom");
105
106 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
107 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", $contributionAmount);
108 $this->type("email-5", $email);
109
110 $this->webtestAddCreditCardDetails();
111 $this->webtestAddBillingDetails($firstName, $middleName, $lastName);
112
113 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
114 $this->click("_qf_Confirm_next-bottom");
115
116 $this->waitForElementPresent("thankyou_footer");
117 $this->openCiviPage("contribute/campaign", "action=add&reset=1&pageId={$pageId}&component=contribute", "_qf_PCPAccount_next-bottom");
118
119 $cmsUserName = 'CmsUser' . substr(sha1(rand()), 0, 7);
120 $this->type("cms_name", $cmsUserName);
121 $this->click("checkavailability");
122 $this->type("first_name", $firstName);
123 $this->type("last_name", $lastName);
124 $this->type("email-Primary", $email);
125 if ($this->isElementPresent("cms_pass")) {
126 $pass = 'myBigPassword';
127 $this->type("cms_pass", $pass);
128
129 $this->type("cms_confirm_pass", $pass);
130
131 }
132 $this->click("_qf_PCPAccount_next-bottom");
133
134 $this->waitForElementPresent("_qf_Campaign_upload-bottom");
135
136 $pcpTitle = 'PCPTitle' . substr(sha1(rand()), 0, 7);
137 $this->type("pcp_title", $pcpTitle);
138 $this->type("pcp_intro_text", "Welcome Text $hash");
139 $this->type("goal_amount", $contributionAmount);
140 $this->clickLink("_qf_Campaign_upload-bottom", '_qf_Main_upload-bottom');
141
142 $this->webtestLogin();
143 $this->openCiviPage("admin/pcp", "reset=1", "_qf_PCP_refresh");
144 $this->select('status_id', 'value=1');
145 $this->click("_qf_PCP_refresh");
146 $this->waitForElementPresent("_qf_PCP_refresh");
147 $id = explode('id=', $this->getAttribute("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody/tr/td/a[text()='$pcpTitle']@href"));
148 $pcpId = trim($id[1]);
149 $pcpUrl = "civicrm/contribute/pcp/info?reset=1&id=$pcpId";
150 $this->click("xpath=//td[@id=$pcpId]/span[1]/a[2]");
151 $this->waitForPageToLoad($this->getTimeoutMsec());
152 // logout
153 $this->webtestLogout();
154
155 // Set pcp contributor name
156 $donorFirstName = 'Donor' . substr(sha1(rand()), 0, 4);
157 $donorLastName = 'Person' . substr(sha1(rand()), 0, 7);
158 $middleName = 'Mid' . substr(sha1(rand()), 0, 7);
159
160 $this->open($this->sboxPath . $pcpUrl);
161
162 $this->waitForPageToLoad($this->getTimeoutMsec());
163 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&pcpId=$id[1]", "_qf_Main_upload-bottom");
164 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
165 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", $contributionAmount);
166 $this->type("email-5", $donorFirstName . "@example.com");
167
168 $this->webtestAddCreditCardDetails();
169 $this->webtestAddBillingDetails($donorFirstName, $middleName, $donorLastName);
170 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
171 $this->click("_qf_Confirm_next-bottom");
172
173 $this->waitForElementPresent("thankyou_footer");
174
175 //login to check contribution
176 $this->webtestLogin();
177
178 //Find Contribution
179 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
180
181 $this->select('contribution_pcp_made_through_id', "label={$pcpTitle}");
182
183 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
184 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
185
186 // View Contribution Record and test for expected values
187 $expected = array(
188 'From' => "{$donorFirstName} {$donorLastName}",
189 'Financial Type' => 'Donation',
190 'Total Amount' => $contributionAmount,
191 'Contribution Status' => 'Completed',
192 );
193 $this->webtestVerifyTabularData($expected);
194
195 //Check for SoftCredit
196 $softCreditor = "{$firstName} {$lastName}";
197 $this->verifyText("xpath=//table[@class='crm-info-panel crm-soft-credit-listing']/tbody/tr/td[1]", preg_quote($softCreditor), 'In line ' . __LINE__);
198
199 // Check PCP Summary Report
200 $this->openCiviPage('report/instance/16', 'reset=1');
201 $this->verifyText("PCP", preg_quote($pcpTitle));
202 $this->verifyText("PCP", preg_quote("{$lastName}, {$firstName}"));
203 }
204 }
205