Merge pull request #10496 from jitendrapurohit/CRM-20719
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / UpdateBatchPendingContributionTest.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_UpdateBatchPendingContributionTest
31 */
32 class WebTest_Contribute_UpdateBatchPendingContributionTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testBatchUpdatePendingContribution() {
39 $this->webtestLogin();
40 $this->_testOfflineContribution();
41 $this->_testOfflineContribution();
42 $this->_testOfflineContribution();
43
44 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
45
46 $this->type("sort_name", "Individual");
47 $this->waitForElementPresent("contribution_status_id");
48 $this->multiselect2('contribution_status_id', array("Pending"));
49 $this->clickLink("_qf_Search_refresh");
50
51 $this->click('radio_ts', 'ts_all');
52 $this->waitForAjaxContent();
53 $this->select('task', "label=Update pending contribution status");
54 $this->waitForAjaxContent();
55 $this->waitForElementPresent("contribution_status_id");
56 $this->select('contribution_status_id', 'label=Completed');
57 $this->waitForAjaxContent();
58 $this->click('_qf_Status_next');
59 $this->waitForElementPresent("_qf_Result_done");
60 $this->click("_qf_Result_done");
61
62 $this->waitForElementPresent("contribution_date_low");
63
64 $this->type("sort_name", "Individual");
65 $this->waitForElementPresent("contribution_status_id");
66 $this->multiselect2('contribution_status_id', array("Completed"));
67 $this->click("_qf_Search_refresh");
68
69 $this->waitForPageToLoad($this->getTimeoutMsec());
70 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']");
71 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
72 $expected = array(
73 'Received Into' => "Deposit Bank Account",
74 'Contribution Status' => "Completed",
75 );
76
77 $this->webtestVerifyTabularData($expected);
78 }
79
80 public function testParticipationAdd() {
81 // Log in using webtestLogin() method
82 $this->webtestLogin();
83
84 // Adding contact with randomized first name (so we can then select that contact when creating event registration)
85 // We're using Quick Add block on the main page for this.
86 $firstName1 = substr(sha1(rand()), 0, 7);
87 $this->webtestAddContact($firstName1, 'Anderson', TRUE);
88 $sortName1 = "Anderson, $firstName1";
89 $this->_addParticipant($firstName1);
90
91 $firstName2 = substr(sha1(rand()), 0, 7);
92 $this->webtestAddContact($firstName2, 'Anderson', TRUE);
93 $sortName2 = "Anderson, $firstName2";
94 $this->_addParticipant($firstName2);
95
96 // Search the participants
97 $this->openCiviPage("event/search", "reset=1", '_qf_Search_refresh');
98
99 $eventName = 'Rain-forest Cup Youth Soccer Tournament';
100 $this->select2("event_id", $eventName, TRUE);
101 $this->click('_qf_Search_refresh');
102
103 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
104
105 $this->type("sort_name", "Anderson");
106 $this->multiselect2('contribution_status_id', array("Pending"));
107 $this->click("_qf_Search_refresh");
108
109 $this->waitForPageToLoad($this->getTimeoutMsec());
110 $this->click('radio_ts', 'ts_all');
111
112 $this->select('task', "label=Update pending contribution status");
113 $this->waitForElementPresent("_qf_Search_next_action");
114 $this->click("_qf_Search_next_action");
115 $this->waitForPageToLoad($this->getTimeoutMsec());
116 $this->select('contribution_status_id', 'label=Completed');
117 $this->click('_qf_Status_next');
118 $this->waitForElementPresent("_qf_Result_done");
119 $this->click("_qf_Result_done");
120
121 $this->waitForElementPresent("contribution_date_low");
122
123 $this->type("sort_name", "Anderson");
124 $this->multiselect2('contribution_status_id', array("Completed"));
125 $this->click("_qf_Search_refresh");
126
127 $this->waitForPageToLoad($this->getTimeoutMsec());
128 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']");
129 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
130 $expected = array(
131 'Received Into' => "Deposit Bank Account",
132 'Contribution Status' => "Completed",
133 );
134
135 $this->webtestVerifyTabularData($expected);
136 }
137
138 /**
139 * @param string $firstName
140 */
141 public function _addParticipant($firstName) {
142
143 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", '_qf_Participant_upload-bottom');
144
145 // Type contact last name in contact auto-complete, wait for dropdown and click first result
146 $this->webtestFillAutocomplete($firstName);
147
148 // Select event. Based on label for now.
149 $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament");
150
151 // Select role
152 $this->multiselect2('role_id', array('Volunteer'));
153
154 // Select participant status
155 $this->select('status_id', 'value=1');
156
157 // Setting registration source
158 $this->type('source', 'Event StandaloneAddTest Webtest');
159
160 // Since we're here, let's check of screen help is being displayed properly
161 $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).'));
162
163 // Select an event fee
164 $this->waitForElementPresent('priceset');
165
166 $this->click("xpath=//input[@class='crm-form-radio']");
167
168 // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle)
169 $this->type('total_amount', '800');
170
171 $this->select('contribution_status_id', "label=Pending");
172
173 // Clicking save.
174 $this->click('_qf_Participant_upload-bottom');
175 $this->waitForPageToLoad($this->getTimeoutMsec());
176
177 // Is status message correct?
178 $this->waitForText("crm-notification-container", "Event registration for $firstName Anderson has been added");
179
180 $this->waitForElementPresent("xpath=//form[@class='CRM_Event_Form_Search crm-search-form']/table//tbody/tr[1]/td[8]/span/a[text()='View']");
181 //click through to the participant view screen
182 $this->click("xpath=//form[@class='CRM_Event_Form_Search crm-search-form']/table//tbody/tr[1]/td[8]/span/a[text()='View']");
183 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
184
185 $this->webtestVerifyTabularData(
186 array(
187 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
188 'Participant Role' => 'Attendee',
189 'Status' => 'Registered',
190 'Event Source' => 'Event StandaloneAddTest Webtest',
191 'Fees' => '$ 800.00',
192 )
193 );
194 }
195
196 public function _testOfflineContribution() {
197 $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
198
199 // create new contact using dialog
200 $this->createDialogContact();
201
202 // select financial type
203 $this->select("financial_type_id", "value=1");
204
205 //Contribution status
206 $this->waitForElementPresent("contribution_status_id");
207 $this->select("contribution_status_id", "label=Pending");
208
209 // total amount
210 $this->type("total_amount", "100");
211
212 // Clicking save.
213 $this->click("_qf_Contribution_upload");
214 $this->waitForPageToLoad($this->getTimeoutMsec());
215
216 // Is status message correct?
217 $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!");
218
219 // verify if Membership is created
220 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[2]//tbody/tr[1]/td[8]/span/a[text()='View']");
221
222 //click through to the Membership view screen
223 $this->click("xpath=//div[@class='view-content']//table[2]/tbody/tr[1]/td[8]/span/a[text()='View']");
224 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
225
226 $expected = array(
227 'Financial Type' => 'Donation',
228 'Total Amount' => '100.00',
229 'Contribution Status' => 'Pending',
230 );
231 foreach ($expected as $label => $value) {
232 $this->assertElementContainsText("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='$label']/../td[2]", $value);
233 }
234 }
235
236 }