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