Merge pull request #11735 from mukeshcompucorp/CRM-21814-add-proper-container-to...
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / PCPAddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 +--------------------------------------------------------------------+
25 */
26
27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contribute_PCPAddTest
31 */
6a488035
TO
32class WebTest_Contribute_PCPAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testPCPAdd() {
6a488035 39 // open browser, login
6a488035
TO
40 $this->webtestLogin();
41
42 // set pcp supporter name and email
42daf119
CW
43 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
44 $lastName = 'An' . substr(sha1(rand()), 0, 7);
6a488035 45 $middleName = 'Mid' . substr(sha1(rand()), 0, 7);
42daf119 46 $email = substr(sha1(rand()), 0, 7) . '@example.org';
6a488035 47
42daf119 48 $this->openCiviPage("admin/domain", "action=update&reset=1", '_qf_Domain_cancel-bottom');
6a488035
TO
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
42daf119
CW
62 $hash = substr(sha1(rand()), 0, 7);
63 $rand = $contributionAmount = 2 * rand(2, 50);
64 $pageTitle = 'PCP Contribution' . $hash;
42daf119
CW
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;
6a488035
TO
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,
c3ad8633 85 array('Test Processor' => 'Dummy'),
6a488035
TO
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
42daf119 104 $this->webtestLogout();
6a488035 105
42daf119 106 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", "_qf_Main_upload-bottom");
6a488035
TO
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);
cd223eef 110 $this->typeKeys("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", $contributionAmount);
6a488035 111 $this->type("email-5", $email);
cd223eef 112 $this->click("xpath=//label[text()='Test Processor']");
113 $this->waitForAjaxContent();
6a488035
TO
114
115 $this->webtestAddCreditCardDetails();
116 $this->webtestAddBillingDetails($firstName, $middleName, $lastName);
117
225a8648 118 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
119 $this->click("_qf_Confirm_next-bottom");
120
121 $this->waitForElementPresent("thankyou_footer");
42daf119 122 $this->openCiviPage("contribute/campaign", "action=add&reset=1&pageId={$pageId}&component=contribute", "_qf_PCPAccount_next-bottom");
6a488035
TO
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';
76e86fd8
CW
132 $this->type("cms_pass", $pass);
133
134 $this->type("cms_confirm_pass", $pass);
135
6a488035 136 }
c3ad8633 137 $this->clickLink("_qf_PCPAccount_next-bottom", "_qf_Campaign_upload-bottom");
6a488035
TO
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);
27c7ef42 143 $this->clickLink("_qf_Campaign_upload-bottom", '_qf_Main_upload-bottom');
6a488035 144
6a488035 145 $this->webtestLogin();
42daf119 146 $this->openCiviPage("admin/pcp", "reset=1", "_qf_PCP_refresh");
6a488035 147 $this->select('status_id', 'value=1');
c3ad8633 148 $this->clickLink("_qf_PCP_refresh", "_qf_PCP_refresh");
6a488035
TO
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";
c3ad8633 152 $this->clickLink("xpath=//td[@id=$pcpId]/span[1]/a[2]");
6a488035 153 // logout
42daf119 154 $this->webtestLogout();
6a488035
TO
155
156 // Set pcp contributor name
42daf119
CW
157 $donorFirstName = 'Donor' . substr(sha1(rand()), 0, 4);
158 $donorLastName = 'Person' . substr(sha1(rand()), 0, 7);
6a488035
TO
159 $middleName = 'Mid' . substr(sha1(rand()), 0, 7);
160
161 $this->open($this->sboxPath . $pcpUrl);
162
163 $this->waitForPageToLoad($this->getTimeoutMsec());
42daf119 164 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&pcpId=$id[1]", "_qf_Main_upload-bottom");
6a488035
TO
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);
cd223eef 167 $this->typeKeys("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", $contributionAmount);
6a488035 168 $this->type("email-5", $donorFirstName . "@example.com");
cd223eef 169 $this->click("xpath=//label[text()='Test Processor']");
170 $this->waitForAjaxContent();
6a488035
TO
171
172 $this->webtestAddCreditCardDetails();
173 $this->webtestAddBillingDetails($donorFirstName, $middleName, $donorLastName);
225a8648 174 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
175 $this->click("_qf_Confirm_next-bottom");
176
177 $this->waitForElementPresent("thankyou_footer");
6a488035 178
071a6d2e 179 //login to check contribution
6a488035
TO
180 $this->webtestLogin();
181
182 //Find Contribution
42daf119 183 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
84ff2662 184 $this->waitForElementPresent('contribution_pcp_made_through_id');
80a9d035 185 $this->multiselect2('contribution_pcp_made_through_id', array($pcpTitle));
6a488035 186
cd223eef 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']");
84ff2662 189 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
6a488035
TO
190
191 // View Contribution Record and test for expected values
192 $expected = array(
42daf119
CW
193 'From' => "{$donorFirstName} {$donorLastName}",
194 'Financial Type' => 'Donation',
195 'Total Amount' => $contributionAmount,
6a488035
TO
196 'Contribution Status' => 'Completed',
197 );
198 $this->webtestVerifyTabularData($expected);
199
200 //Check for SoftCredit
6b14c845 201 $softCreditor = "{$firstName} {$lastName}";
ba4a1892 202 $this->verifyText("xpath=//div['PCPView']/div[2]/table[@class='crm-info-panel']/tbody/tr[2]/td[2]/a", preg_quote($softCreditor));
e9479dcf 203
6a488035 204 // Check PCP Summary Report
895231b4 205 $this->openCiviPage('report/instance/17', 'reset=1');
24f591b0 206 $this->assertElementContainsText("PCP", $pcpTitle);
207 $this->assertElementContainsText("PCP", "{$lastName}, {$firstName}");
6a488035 208 }
96025800 209
6a488035 210}