Webtest fix - 4.6
[civicrm-core.git] / tests / phpunit / WebTest / Event / AdditionalPaymentTest.php
CommitLineData
c5bb67f1
PJ
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
c5bb67f1 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
c5bb67f1
PJ
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
c5bb67f1
PJ
26
27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Event_AdditionalPaymentTest
31 */
c5bb67f1
PJ
32class WebTest_Event_AdditionalPaymentTest extends CiviSeleniumTestCase {
33 protected function setUp() {
34 parent::setUp();
35 }
36
546b78fa
CW
37 /**
38 * CRM-13964 and CRM-13965
39 */
00be9182 40 public function testParticipantParitalPaymentInitiation() {
c5bb67f1
PJ
41 // Log in using webtestLogin() method
42 $this->webtestLogin();
43
44 $firstName = substr(sha1(rand()), 0, 7);
45 $this->webtestAddContact($firstName, 'Anderson', TRUE);
46 $contactName = "Anderson, $firstName";
47 $displayName = "$firstName Anderson";
48
49 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
50
c5bb67f1
PJ
51 $this->webtestFillAutocomplete($firstName);
52
53 // Select event. Based on label for now.
ed174dea 54 $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament");
c5bb67f1
PJ
55
56 // Select role
60709d21 57 $this->multiselect2('role_id', array('Volunteer'));
c5bb67f1
PJ
58
59 // Choose Registration Date.
60 // Using helper webtestFillDate function.
61 $this->webtestFillDate('register_date', 'now');
62 $today = date('F jS, Y', strtotime('now'));
c5bb67f1
PJ
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
ed174dea 76 $this->click("xpath=//input[@class='crm-form-radio']");
c5bb67f1
PJ
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
e42c089b 92 $this->waitForAjaxContent();
c5bb67f1
PJ
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');
6c6e6187 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()));
c5bb67f1
PJ
103
104 // select partially paid status again and click on save
105 $this->select('status_id', 'label=Partially paid');
106
107 // Clicking save.
e42c089b 108 $this->clickLink('_qf_Participant_upload-bottom');
c5bb67f1
PJ
109
110 // Is status message correct?
111 $this->waitForText('crm-notification-container', "Event registration for $displayName has been added");
f58bc0ab 112 $this->waitForElementPresent("xpath=//form[@class='CRM_Event_Form_Search crm-search-form']/table//tbody/tr[1]/td[8]/span//a[text()='View']");
c5bb67f1 113 //click through to the participant view screen
f58bc0ab 114 $this->click("xpath=//form[@class='CRM_Event_Form_Search crm-search-form']/table/tbody/tr[1]/td[8]/span//a[text()='View']");
7542b691 115 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]");
c5bb67f1
PJ
116
117 $this->webtestVerifyTabularData(
118 array(
119 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
44a0d8ea 120 'Participant Role' => 'Volunteer',
c5bb67f1
PJ
121 'Status' => 'Partially paid',
122 'Event Source' => 'Event Partially Paid Webtest',
123 )
124 );
125
dfbeebc5
PJ
126 // check the fee amount and contribution amount
127 $this->_checkPaymentInfoTable(800.00, 400.00);
128 $balance = 800.00 - 400.00;
c5bb67f1 129 //click through to the contribution view screen
663e94e8 130 $this->waitForElementPresent("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
ed174dea 131 $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
7542b691 132 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]");
c5bb67f1
PJ
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 );
dfbeebc5 144
7542b691 145 $this->clickAjaxLink("xpath=//button//span[contains(text(),'Done')]");
f58bc0ab 146 $this->waitForElementPresent("xpath=//form[@id='ParticipantView']//div/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span//a[text()='View']");
dfbeebc5
PJ
147 // make additional payment
148 // 1 - check for links presence on participant view and edit page
5175c5ab 149 $this->waitForElementPresent("xpath=//form[@id='ParticipantView']//div//table//tbody//td[@id='payment-info']//a[contains(text(), 'Record Payment')]");
dfbeebc5 150 $this->click("xpath=id('ParticipantView')//div[@class='action-link']/div/a/span[contains(text(), 'Edit')]");
7542b691 151 $this->waitForElementPresent("xpath=id('ParticipantView')//td[@id='payment-info']//a[contains(text(), 'Record Payment')]");
152 $this->clickLinkSuppressPopup("xpath=id('ParticipantView')//td[@id='payment-info']//a[contains(text(), 'Record Payment')]", 'AdditionalPayment');
dfbeebc5 153
dfbeebc5 154 // verify balance
44a0d8ea 155 $text = $this->getText("xpath=id('AdditionalPayment')/div[2]//table/tbody/tr[3]/td[2]");
6c6e6187 156 $this->assertTrue((bool) preg_match("/{$balance}/", $text));
dfbeebc5
PJ
157
158 // check form rule error
159 $errorBalance = $balance + 1;
160 $this->type('total_amount', $errorBalance);
161 $this->select('payment_instrument_id', 'label=Cash');
162 $this->click('_qf_AdditionalPayment_upload-bottom');
163 $this->waitForText("xpath=//span[@id='totalAmount']/span", 'Payment amount cannot be greater than owed amount');
164 $this->type('total_amount', $balance);
165 $this->click('_qf_AdditionalPayment_upload-bottom');
e42c089b 166 $this->checkCRMAlert('The payment record has been processed.');
7542b691 167 $this->waitForElementPresent("xpath=//*[contains(@class, 'CRM_Event_Form_Search')]//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
168 $this->click("xpath=//*[contains(@class, 'CRM_Event_Form_Search')]//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
169 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]");
dfbeebc5
PJ
170 $this->webtestVerifyTabularData(
171 array(
172 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
44a0d8ea 173 'Participant Role' => 'Volunteer',
dfbeebc5
PJ
174 'Status' => 'Registered',
175 'Event Source' => 'Event Partially Paid Webtest',
176 )
177 );
178 // check the fee amount and contribution amount
179 $this->_checkPaymentInfoTable(800.00, 800.00);
180
e42c089b 181 // check for absence of record payment button
7542b691 182 $this->assertFalse($this->isElementPresent("xpath=id('ParticipantView')//td[@id='payment-info']//a[contains(text(), 'Record Payment')]"));
dfbeebc5 183
e42c089b 184 $this->clickAjaxLink("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
dfbeebc5
PJ
185
186 $this->webtestVerifyTabularData(
187 array(
188 'From' => $displayName,
189 'Financial Type' => 'Event Fee',
190 'Total Amount' => '$ 800.00',
191 'Contribution Status' => 'Completed',
192 'Paid By' => 'Check',
193 'Check Number' => '1044',
194 )
195 );
7542b691 196 $this->click("xpath=//button//span[contains(text(),'Done')]");
794abb2e
PJ
197
198 // view transaction popup info check
199 $this->waitForElementPresent("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td[2]/a");
e42c089b 200 $this->clickAjaxLink("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td[2]/a");
794abb2e
PJ
201 $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')]");
202 $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')]");
203 $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')]");
dfbeebc5
PJ
204 }
205
4cbe18b8
EM
206 /**
207 * @param $feeAmt
100fef9d 208 * @param int $amtPaid
4cbe18b8 209 */
00be9182 210 public function _checkPaymentInfoTable($feeAmt, $amtPaid) {
dfbeebc5 211 $this->assertElementContainsText("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td", "$ {$feeAmt}", 'Missing text: appropriate fee amount');
ed174dea 212 $this->assertElementContainsText("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td[2]", "$ {$amtPaid}", 'Missing text: appropriate fee amount');
c5bb67f1 213 }
96025800 214
44a0d8ea 215}