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