WebTestFix
[civicrm-core.git] / tests / phpunit / WebTest / Event / AdditionalPaymentTest.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 class WebTest_Event_AdditionalPaymentTest extends CiviSeleniumTestCase {
29 protected function setUp() {
30 parent::setUp();
31 }
32
33 // CRM-13964 and CRM-13965
34 function testParticipantParitalPaymentInitiation() {
35 // Log in using webtestLogin() method
36 $this->webtestLogin();
37
38 $firstName = substr(sha1(rand()), 0, 7);
39 $this->webtestAddContact($firstName, 'Anderson', TRUE);
40 $contactName = "Anderson, $firstName";
41 $displayName = "$firstName Anderson";
42
43 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
44
45 // Type contact last name in contact auto-complete, wait for dropdown and click first result
46 $this->webtestFillAutocomplete($firstName);
47
48 // Select event. Based on label for now.
49 $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament");
50
51 // Select role
52 //$this->click('role_id[2]');
53 $this->select('role_id', "value=2");
54
55 // Choose Registration Date.
56 // Using helper webtestFillDate function.
57 $this->webtestFillDate('register_date', 'now');
58 $today = date('F jS, Y', strtotime('now'));
59 // May 5th, 2010
60
61 // Select participant status
62 $this->select('status_id', 'value=1');
63
64 // Setting registration source
65 $this->type('source', 'Event Partially Paid Webtest');
66
67 // Since we're here, let's check of screen help is being displayed properly
68 $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).'));
69
70 // Select an event fee
71 $this->waitForElementPresent('priceset');
72
73 $this->click("xpath=//input[@class='crm-form-radio']");
74 sleep(1);
75 // record payment total amount
76 // amount populated after fee selection
77 $amtTotalOwed = (int) $this->getValue('id=total_amount');
78 $this->assertEquals($amtTotalOwed, 800, 'The amount owed doesn\'t match to fee amount selected');
79
80 // now change the amount to lesser amount value
81 $this->type('total_amount', '400');
82
83 // Select payment method = Check and enter chk number
84 $this->select('payment_instrument_id', 'value=4');
85 $this->waitForElementPresent('check_number');
86 $this->type('check_number', '1044');
87
88 // give some time for js to process
89 sleep(1);
90 $this->verifySelectedLabel("status_id", 'Partially paid');
91
92 // later on change the status
93 $this->select('status_id', 'value=1');
94
95 // Clicking save.
96 // check for proper info message displayed regarding status
97 $this->chooseCancelOnNextConfirmation();
98 $this->click('_qf_Participant_upload-bottom');
99 $this->assertTrue((bool)preg_match("/Payment amount is less than the amount owed. Expected participant status is 'Partially paid'. Are you sure you want to set the participant status to Registered/", $this->getConfirmation()));
100
101 // select partially paid status again and click on save
102 $this->select('status_id', 'label=Partially paid');
103
104 // Clicking save.
105 $this->click('_qf_Participant_upload-bottom');
106 $this->waitForPageToLoad($this->getTimeoutMsec());
107
108 // Is status message correct?
109 $this->waitForText('crm-notification-container', "Event registration for $displayName has been added");
110 $this->waitForElementPresent("xpath=//form[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
111 //click through to the participant view screen
112 $this->click("xpath=//form[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
113 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
114
115 $this->webtestVerifyTabularData(
116 array(
117 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
118 'Participant Role' => 'Volunteer',
119 'Status' => 'Partially paid',
120 'Event Source' => 'Event Partially Paid Webtest',
121 )
122 );
123
124 // check the fee amount and contribution amount
125 $this->_checkPaymentInfoTable(800.00, 400.00);
126 $balance = 800.00 - 400.00;
127 //click through to the contribution view screen
128 $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
129 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
130
131 $this->webtestVerifyTabularData(
132 array(
133 'From' => $displayName,
134 'Financial Type' => 'Event Fee',
135 'Total Amount' => '$ 800.00',
136 'Contribution Status' => 'Partially paid',
137 'Paid By' => 'Check',
138 'Check Number' => '1044',
139 )
140 );
141
142 $this->click('_qf_ContributionView_cancel-top');
143 $this->waitForElementPresent("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
144 // make additional payment
145 // 1 - check for links presence on participant view and edit page
146 $this->assertElementPresent("xpath=id('Search')/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span[2]/ul/li[2]/a[text()='Record Payment']");
147 $this->click("xpath=id('Search')/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
148 $this->waitForElementPresent("xpath=id('ParticipantView')");
149 //$this->assertElementPresent("xpath=id('ParticipantView')//td[@id='payment-info']//a/span[contains(text(), 'Record Payment')]");
150 $this->assertElementPresent("xpath=id('ParticipantView')//td[@id='payment-info']/a/span[contains(text(), 'Record Payment')]");
151
152 $this->click("xpath=id('ParticipantView')//div[@class='action-link']/div/a/span[contains(text(), 'Edit')]");
153 $this->waitForElementPresent("xpath=id('Participant')");
154 $this->assertElementPresent("xpath=id('Participant')//td[@id='payment-info']//a/span[contains(text(), 'Record Payment')]");
155 $location = $this->getAttribute("xpath=id('Participant')//td[@id='payment-info']/a/span[contains(text(), 'Record Payment')]/../@href");
156
157 $this->open($location);
158 $this->waitForElementPresent("xpath=id('AdditionalPayment')");
159 $this->assertElementContainsText("xpath=id('AdditionalPayment')/h3", 'New Event Payment');
160
161 // input data
162 //$this->select('financial_type_id', 'label=Donation');
163 // verify balance
164 $text = $this->getText("xpath=id('AdditionalPayment')/div[2]//table/tbody/tr[3]/td[2]");
165 $this->assertTrue((bool)preg_match("/{$balance}/", $text));
166
167 // check form rule error
168 $errorBalance = $balance + 1;
169 $this->type('total_amount', $errorBalance);
170 $this->select('payment_instrument_id', 'label=Cash');
171 $this->click('_qf_AdditionalPayment_upload-bottom');
172 $this->waitForText("xpath=//span[@id='totalAmount']/span", 'Payment amount cannot be greater than owed amount');
173 $this->type('total_amount', $balance);
174 $this->click('_qf_AdditionalPayment_upload-bottom');
175 $this->waitForText('crm-notification-container', 'The payment record has been processed.');
176
177 $this->waitForElementPresent("xpath=id('Search')/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
178 $this->click("xpath=id('Search')/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
179 $this->waitForElementPresent("_qf_ParticipantView_cancel-top");
180
181 $this->webtestVerifyTabularData(
182 array(
183 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
184 'Participant Role' => 'Volunteer',
185 'Status' => 'Registered',
186 'Event Source' => 'Event Partially Paid Webtest',
187 )
188 );
189 // check the fee amount and contribution amount
190 $this->_checkPaymentInfoTable(800.00, 800.00);
191
192 // check for not apprence of record payment button
193 $this->assertFalse($this->isElementPresent("xpath=id('ParticipantView')//td[@id='payment-info']//a/span[contains(text(), 'Record Payment')]"));
194
195 $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
196 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
197
198 $this->webtestVerifyTabularData(
199 array(
200 'From' => $displayName,
201 'Financial Type' => 'Event Fee',
202 'Total Amount' => '$ 800.00',
203 'Contribution Status' => 'Completed',
204 'Paid By' => 'Check',
205 'Check Number' => '1044',
206 )
207 );
208 $this->click('_qf_ContributionView_cancel-bottom');
209
210 // view transaction popup info check
211 $this->waitForElementPresent("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td[2]/a");
212 $this->click("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td[2]/a");
213 $this->waitForElementPresent("xpath=//table[@id='info']/tbody/tr/th[contains(text(), 'Amount')]/../../tr[2]/td[contains(text(), '$ 400.00')]/../../tr[3]/td[contains(text(), '$ 400.00')]");
214 $this->waitForElementPresent("xpath=//table[@id='info']/tbody/tr/th[3][contains(text(), 'Paid By')]/../../tr[2]/td[3][contains(text(), 'Check')]/../../tr[3]/td[3][contains(text(), 'Cash')]");
215 $this->waitForElementPresent("xpath=//table[@id='info']/tbody/tr/th[6][contains(text(), 'Status')]/../../tr[2]/td[6][contains(text(), 'Completed')]/../../tr[3]/td[6][contains(text(), 'Completed')]");
216 }
217
218 function _checkPaymentInfoTable($feeAmt, $amtPaid) {
219 $this->assertElementContainsText("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td", "$ {$feeAmt}", 'Missing text: appropriate fee amount');
220 $this->assertElementContainsText("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td[2]", "$ {$amtPaid}", 'Missing text: appropriate fee amount');
221 }
222 }