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