Webtest Fix
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / PCPAddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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);
110 $this->type("email-5", $email);
111
112 $this->webtestAddCreditCardDetails();
113 $this->webtestAddBillingDetails($firstName, $middleName, $lastName);
114
225a8648 115 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
116 $this->click("_qf_Confirm_next-bottom");
117
118 $this->waitForElementPresent("thankyou_footer");
42daf119 119 $this->openCiviPage("contribute/campaign", "action=add&reset=1&pageId={$pageId}&component=contribute", "_qf_PCPAccount_next-bottom");
6a488035
TO
120
121 $cmsUserName = 'CmsUser' . substr(sha1(rand()), 0, 7);
122 $this->type("cms_name", $cmsUserName);
123 $this->click("checkavailability");
124 $this->type("first_name", $firstName);
125 $this->type("last_name", $lastName);
126 $this->type("email-Primary", $email);
127 if ($this->isElementPresent("cms_pass")) {
128 $pass = 'myBigPassword';
76e86fd8
CW
129 $this->type("cms_pass", $pass);
130
131 $this->type("cms_confirm_pass", $pass);
132
6a488035 133 }
c3ad8633 134 $this->clickLink("_qf_PCPAccount_next-bottom", "_qf_Campaign_upload-bottom");
6a488035
TO
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);
27c7ef42 140 $this->clickLink("_qf_Campaign_upload-bottom", '_qf_Main_upload-bottom');
6a488035 141
6a488035 142 $this->webtestLogin();
42daf119 143 $this->openCiviPage("admin/pcp", "reset=1", "_qf_PCP_refresh");
6a488035 144 $this->select('status_id', 'value=1');
c3ad8633 145 $this->clickLink("_qf_PCP_refresh", "_qf_PCP_refresh");
6a488035
TO
146 $id = explode('id=', $this->getAttribute("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody/tr/td/a[text()='$pcpTitle']@href"));
147 $pcpId = trim($id[1]);
148 $pcpUrl = "civicrm/contribute/pcp/info?reset=1&id=$pcpId";
c3ad8633 149 $this->clickLink("xpath=//td[@id=$pcpId]/span[1]/a[2]");
6a488035 150 // logout
42daf119 151 $this->webtestLogout();
6a488035
TO
152
153 // Set pcp contributor name
42daf119
CW
154 $donorFirstName = 'Donor' . substr(sha1(rand()), 0, 4);
155 $donorLastName = 'Person' . substr(sha1(rand()), 0, 7);
6a488035
TO
156 $middleName = 'Mid' . substr(sha1(rand()), 0, 7);
157
158 $this->open($this->sboxPath . $pcpUrl);
159
160 $this->waitForPageToLoad($this->getTimeoutMsec());
42daf119 161 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&pcpId=$id[1]", "_qf_Main_upload-bottom");
6a488035
TO
162 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
163 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", $contributionAmount);
164 $this->type("email-5", $donorFirstName . "@example.com");
165
166 $this->webtestAddCreditCardDetails();
167 $this->webtestAddBillingDetails($donorFirstName, $middleName, $donorLastName);
225a8648 168 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
169 $this->click("_qf_Confirm_next-bottom");
170
171 $this->waitForElementPresent("thankyou_footer");
6a488035 172
071a6d2e 173 //login to check contribution
6a488035
TO
174 $this->webtestLogin();
175
176 //Find Contribution
42daf119 177 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
84ff2662 178 $this->waitForElementPresent('contribution_pcp_made_through_id');
80a9d035 179 $this->multiselect2('contribution_pcp_made_through_id', array($pcpTitle));
6a488035 180
84ff2662
RK
181 $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[11]/span/a[1][text()='View']");
182 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[11]/span/a[1][text()='View']");
183 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
6a488035
TO
184
185 // View Contribution Record and test for expected values
186 $expected = array(
42daf119
CW
187 'From' => "{$donorFirstName} {$donorLastName}",
188 'Financial Type' => 'Donation',
189 'Total Amount' => $contributionAmount,
6a488035
TO
190 'Contribution Status' => 'Completed',
191 );
192 $this->webtestVerifyTabularData($expected);
193
194 //Check for SoftCredit
6b14c845 195 $softCreditor = "{$firstName} {$lastName}";
0ecb5006 196 $this->verifyText("xpath=//div['PCPView']/div[2]/table[@class='crm-info-panel']/tbody/tr[2]/td[2]/a", preg_quote($softCreditor), 'In line ' . __LINE__);
e9479dcf 197
6a488035 198 // Check PCP Summary Report
6b14c845 199 $this->openCiviPage('report/instance/16', 'reset=1');
6a488035
TO
200 $this->verifyText("PCP", preg_quote($pcpTitle));
201 $this->verifyText("PCP", preg_quote("{$lastName}, {$firstName}"));
202 }
96025800 203
6a488035 204}