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