Merge pull request #11702 from jmcclelland/pdf-receipt-filename
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / PCPAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 public 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 $amountSection = TRUE;
66 $payLater = TRUE;
67 $onBehalf = FALSE;
68 $pledges = FALSE;
69 $recurring = FALSE;
70 $memberships = FALSE;
71 $memPriceSetId = NULL;
72 $friend = FALSE;
73 $profilePreId = NULL;
74 $profilePostId = NULL;
75 $premiums = FALSE;
76 $widget = FALSE;
77 $pcp = TRUE;
78 $isAprovalNeeded = TRUE;
79
80 // create a new online contribution page with pcp enabled
81 // create contribution page with randomized title and default params
82 $pageId = $this->webtestAddContributionPage($hash,
83 $rand,
84 $pageTitle,
85 array('Test Processor' => 'Dummy'),
86 $amountSection,
87 $payLater,
88 $onBehalf,
89 $pledges,
90 $recurring,
91 $memberships,
92 $memPriceSetId,
93 $friend,
94 $profilePreId,
95 $profilePostId,
96 $premiums,
97 $widget,
98 $pcp,
99 TRUE,
100 $isAprovalNeeded
101 );
102
103 // logout
104 $this->webtestLogout();
105
106 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", "_qf_Main_upload-bottom");
107
108 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
109 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", $contributionAmount);
110 $this->typeKeys("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", $contributionAmount);
111 $this->type("email-5", $email);
112 $this->click("xpath=//label[text()='Test Processor']");
113 $this->waitForAjaxContent();
114
115 $this->webtestAddCreditCardDetails();
116 $this->webtestAddBillingDetails($firstName, $middleName, $lastName);
117
118 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
119 $this->click("_qf_Confirm_next-bottom");
120
121 $this->waitForElementPresent("thankyou_footer");
122 $this->openCiviPage("contribute/campaign", "action=add&reset=1&pageId={$pageId}&component=contribute", "_qf_PCPAccount_next-bottom");
123
124 $cmsUserName = 'CmsUser' . substr(sha1(rand()), 0, 7);
125 $this->type("cms_name", $cmsUserName);
126 $this->click("checkavailability");
127 $this->type("first_name", $firstName);
128 $this->type("last_name", $lastName);
129 $this->type("email-Primary", $email);
130 if ($this->isElementPresent("cms_pass")) {
131 $pass = 'myBigPassword';
132 $this->type("cms_pass", $pass);
133
134 $this->type("cms_confirm_pass", $pass);
135
136 }
137 $this->clickLink("_qf_PCPAccount_next-bottom", "_qf_Campaign_upload-bottom");
138
139 $pcpTitle = 'PCPTitle' . substr(sha1(rand()), 0, 7);
140 $this->type("pcp_title", $pcpTitle);
141 $this->type("pcp_intro_text", "Welcome Text $hash");
142 $this->type("goal_amount", $contributionAmount);
143 $this->clickLink("_qf_Campaign_upload-bottom", '_qf_Main_upload-bottom');
144
145 $this->webtestLogin();
146 $this->openCiviPage("admin/pcp", "reset=1", "_qf_PCP_refresh");
147 $this->select('status_id', 'value=1');
148 $this->clickLink("_qf_PCP_refresh", "_qf_PCP_refresh");
149 $id = explode('id=', $this->getAttribute("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody/tr/td/a[text()='$pcpTitle']@href"));
150 $pcpId = trim($id[1]);
151 $pcpUrl = "civicrm/contribute/pcp/info?reset=1&id=$pcpId";
152 $this->clickLink("xpath=//td[@id=$pcpId]/span[1]/a[2]");
153 // logout
154 $this->webtestLogout();
155
156 // Set pcp contributor name
157 $donorFirstName = 'Donor' . substr(sha1(rand()), 0, 4);
158 $donorLastName = 'Person' . substr(sha1(rand()), 0, 7);
159 $middleName = 'Mid' . substr(sha1(rand()), 0, 7);
160
161 $this->open($this->sboxPath . $pcpUrl);
162
163 $this->waitForPageToLoad($this->getTimeoutMsec());
164 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&pcpId=$id[1]", "_qf_Main_upload-bottom");
165 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
166 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", $contributionAmount);
167 $this->typeKeys("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", $contributionAmount);
168 $this->type("email-5", $donorFirstName . "@example.com");
169 $this->click("xpath=//label[text()='Test Processor']");
170 $this->waitForAjaxContent();
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 $this->waitForElementPresent('contribution_pcp_made_through_id');
185 $this->multiselect2('contribution_pcp_made_through_id', array($pcpTitle));
186
187 $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]//td/span/a[1][text()='View']");
188 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]//td/span/a[1][text()='View']");
189 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
190
191 // View Contribution Record and test for expected values
192 $expected = array(
193 'From' => "{$donorFirstName} {$donorLastName}",
194 'Financial Type' => 'Donation',
195 'Total Amount' => $contributionAmount,
196 'Contribution Status' => 'Completed',
197 );
198 $this->webtestVerifyTabularData($expected);
199
200 //Check for SoftCredit
201 $softCreditor = "{$firstName} {$lastName}";
202 $this->verifyText("xpath=//div['PCPView']/div[2]/table[@class='crm-info-panel']/tbody/tr[2]/td[2]/a", preg_quote($softCreditor));
203
204 // Check PCP Summary Report
205 $this->openCiviPage('report/instance/17', 'reset=1');
206 $this->assertElementContainsText("PCP", $pcpTitle);
207 $this->assertElementContainsText("PCP", "{$lastName}, {$firstName}");
208 }
209
210 }