Commit | Line | Data |
---|---|---|
c5bb67f1 PJ |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
c5bb67f1 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
25 | */ | |
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 | ||
dfbeebc5 | 37 | // CRM-13964 and CRM-13965 |
c5bb67f1 PJ |
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 | ||
c5bb67f1 PJ |
49 | $this->webtestFillAutocomplete($firstName); |
50 | ||
51 | // Select event. Based on label for now. | |
ed174dea | 52 | $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament"); |
c5bb67f1 PJ |
53 | |
54 | // Select role | |
60709d21 | 55 | $this->multiselect2('role_id', array('Volunteer')); |
c5bb67f1 PJ |
56 | |
57 | // Choose Registration Date. | |
58 | // Using helper webtestFillDate function. | |
59 | $this->webtestFillDate('register_date', 'now'); | |
60 | $today = date('F jS, Y', strtotime('now')); | |
c5bb67f1 PJ |
61 | |
62 | // Select participant status | |
63 | $this->select('status_id', 'value=1'); | |
64 | ||
65 | // Setting registration source | |
66 | $this->type('source', 'Event Partially Paid Webtest'); | |
67 | ||
68 | // Since we're here, let's check of screen help is being displayed properly | |
69 | $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).')); | |
70 | ||
71 | // Select an event fee | |
72 | $this->waitForElementPresent('priceset'); | |
73 | ||
ed174dea | 74 | $this->click("xpath=//input[@class='crm-form-radio']"); |
c5bb67f1 PJ |
75 | sleep(1); |
76 | // record payment total amount | |
77 | // amount populated after fee selection | |
78 | $amtTotalOwed = (int) $this->getValue('id=total_amount'); | |
79 | $this->assertEquals($amtTotalOwed, 800, 'The amount owed doesn\'t match to fee amount selected'); | |
80 | ||
81 | // now change the amount to lesser amount value | |
82 | $this->type('total_amount', '400'); | |
83 | ||
84 | // Select payment method = Check and enter chk number | |
85 | $this->select('payment_instrument_id', 'value=4'); | |
86 | $this->waitForElementPresent('check_number'); | |
87 | $this->type('check_number', '1044'); | |
88 | ||
89 | // give some time for js to process | |
e42c089b | 90 | $this->waitForAjaxContent(); |
c5bb67f1 PJ |
91 | $this->verifySelectedLabel("status_id", 'Partially paid'); |
92 | ||
93 | // later on change the status | |
94 | $this->select('status_id', 'value=1'); | |
95 | ||
96 | // Clicking save. | |
97 | // check for proper info message displayed regarding status | |
98 | $this->chooseCancelOnNextConfirmation(); | |
99 | $this->click('_qf_Participant_upload-bottom'); | |
100 | $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())); | |
101 | ||
102 | // select partially paid status again and click on save | |
103 | $this->select('status_id', 'label=Partially paid'); | |
104 | ||
105 | // Clicking save. | |
e42c089b | 106 | $this->clickLink('_qf_Participant_upload-bottom'); |
c5bb67f1 PJ |
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', | |
44a0d8ea | 118 | 'Participant Role' => 'Volunteer', |
c5bb67f1 PJ |
119 | 'Status' => 'Partially paid', |
120 | 'Event Source' => 'Event Partially Paid Webtest', | |
121 | ) | |
122 | ); | |
123 | ||
dfbeebc5 PJ |
124 | // check the fee amount and contribution amount |
125 | $this->_checkPaymentInfoTable(800.00, 400.00); | |
126 | $balance = 800.00 - 400.00; | |
c5bb67f1 | 127 | //click through to the contribution view screen |
ed174dea | 128 | $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']"); |
c5bb67f1 PJ |
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 | ); | |
dfbeebc5 | 141 | |
e42c089b | 142 | $this->clickAjaxLink('_qf_ContributionView_cancel-top'); |
ed174dea | 143 | $this->waitForElementPresent("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']"); |
dfbeebc5 PJ |
144 | // make additional payment |
145 | // 1 - check for links presence on participant view and edit page | |
ed174dea | 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']"); | |
dfbeebc5 | 148 | $this->waitForElementPresent("xpath=id('ParticipantView')"); |
e42c089b | 149 | $this->waitForElementPresent("xpath=id('ParticipantView')//td[@id='payment-info']/a/span[contains(text(), 'Record Payment')]"); |
dfbeebc5 PJ |
150 | |
151 | $this->click("xpath=id('ParticipantView')//div[@class='action-link']/div/a/span[contains(text(), 'Edit')]"); | |
152 | $this->waitForElementPresent("xpath=id('Participant')"); | |
e42c089b CW |
153 | $this->waitForElementPresent("xpath=id('Participant')//td[@id='payment-info']//a/span[contains(text(), 'Record Payment')]"); |
154 | $this->clickLinkSuppressPopup("xpath=id('Participant')//td[@id='payment-info']/a/span[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]"); |
dfbeebc5 PJ |
158 | $this->assertTrue((bool)preg_match("/{$balance}/", $text)); |
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.'); |
dfbeebc5 | 169 | |
ed174dea | 170 | $this->waitForElementPresent("xpath=id('Search')/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']"); |
171 | $this->click("xpath=id('Search')/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']"); | |
dfbeebc5 PJ |
172 | $this->waitForElementPresent("_qf_ParticipantView_cancel-top"); |
173 | ||
174 | $this->webtestVerifyTabularData( | |
175 | array( | |
176 | 'Event' => 'Rain-forest Cup Youth Soccer Tournament', | |
44a0d8ea | 177 | 'Participant Role' => 'Volunteer', |
dfbeebc5 PJ |
178 | 'Status' => 'Registered', |
179 | 'Event Source' => 'Event Partially Paid Webtest', | |
180 | ) | |
181 | ); | |
182 | // check the fee amount and contribution amount | |
183 | $this->_checkPaymentInfoTable(800.00, 800.00); | |
184 | ||
e42c089b | 185 | // check for absence of record payment button |
44a0d8ea | 186 | $this->assertFalse($this->isElementPresent("xpath=id('ParticipantView')//td[@id='payment-info']//a/span[contains(text(), 'Record Payment')]")); |
dfbeebc5 | 187 | |
e42c089b | 188 | $this->clickAjaxLink("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']"); |
dfbeebc5 PJ |
189 | |
190 | $this->webtestVerifyTabularData( | |
191 | array( | |
192 | 'From' => $displayName, | |
193 | 'Financial Type' => 'Event Fee', | |
194 | 'Total Amount' => '$ 800.00', | |
195 | 'Contribution Status' => 'Completed', | |
196 | 'Paid By' => 'Check', | |
197 | 'Check Number' => '1044', | |
198 | ) | |
199 | ); | |
794abb2e PJ |
200 | $this->click('_qf_ContributionView_cancel-bottom'); |
201 | ||
202 | // view transaction popup info check | |
203 | $this->waitForElementPresent("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td[2]/a"); | |
e42c089b | 204 | $this->clickAjaxLink("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td[2]/a"); |
794abb2e PJ |
205 | $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')]"); |
206 | $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')]"); | |
207 | $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 |
208 | } |
209 | ||
4cbe18b8 EM |
210 | /** |
211 | * @param $feeAmt | |
212 | * @param $amtPaid | |
213 | */ | |
dfbeebc5 PJ |
214 | function _checkPaymentInfoTable($feeAmt, $amtPaid) { |
215 | $this->assertElementContainsText("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td", "$ {$feeAmt}", 'Missing text: appropriate fee amount'); | |
ed174dea | 216 | $this->assertElementContainsText("xpath=//td[@id='payment-info']/table[@id='info']/tbody/tr[2]/td[2]", "$ {$amtPaid}", 'Missing text: appropriate fee amount'); |
c5bb67f1 | 217 | } |
44a0d8ea | 218 | } |