Merge pull request #2991 from colemanw/master
[civicrm-core.git] / tests / phpunit / WebTest / Pledge / AddCancelPaymentTest.php
CommitLineData
b879962e
DG
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
b879962e 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
b879962e
DG
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
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Pledge_AddCancelPaymentTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testAddCancelPayment() {
35 $this->webtestLogin();
36
37 $this->openCiviPage('pledge/add', 'reset=1&context=standalone', '_qf_Pledge_upload');
38
39 // create new contact using dialog
40 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
41 $lastName = 'Za' . substr(sha1(rand()), 0, 7);
42 $this->webtestNewDialogContact($firstName, $lastName, $firstName . '@example.com');
43
44 $this->type('amount', '1200');
45 $this->type('installments', '12');
46 $this->select('frequency_unit', 'value=month');
47 $this->type('frequency_day', '1');
48 $this->webtestFillDate('acknowledge_date', 'now');
49 $this->select('contribution_page_id', 'value=3');
50 $this->click('_qf_Pledge_upload-bottom');
51 $this->waitForPageToLoad("30000");
52
53 $this->waitForText('crm-notification-container', "Pledge has been recorded and the payment schedule has been created.");
54
55 // verify if Pledge is created
45fabf8e 56 $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
b879962e
DG
57
58 //click through to the Pledge view screen
45fabf8e 59 $this->click("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
b879962e
DG
60 $this->waitForElementPresent('_qf_PledgeView_next-bottom');
61 $pledgeDate = date('F jS, Y', strtotime('now'));
62
63 $this->webtestVerifyTabularData(array(
64 'Pledge By' => $firstName . ' ' . $lastName,
65 'Total Pledge Amount' => '$ 1,200.00',
66 'To be paid in' => '12 installments of $ 100.00 every 1 month(s)',
67 'Payments are due on the' => '1 day of the period',
68 'Pledge Made' => $pledgeDate,
69 'Financial Type' => 'Donation',
70 'Pledge Status' => 'Pending',
71 )
72 );
45fabf8e 73 $this->clickLink('_qf_PledgeView_next-bottom', "xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span/a[text()='View']", FALSE);
74 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[1]/span/a");
b879962e 75 //Edit and add the first payment for 300.00
45fabf8e 76 $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody//tr//td/table/tbody/tr[2]/td[8]/a[text()='Record Payment (Check, Cash, EFT ...)']");
77 $this->click("xpath=//div[@class='view-content']//table//tbody//tr//td/table/tbody/tr[2]/td[8]/a");
b879962e
DG
78 $this->waitForElementPresent("xpath=//form[@id='Contribution']//div[2]/table/tbody/tr[3]/td[2]/a");
79 $this->click("xpath=//form[@id='Contribution']//div[2]/table/tbody/tr[3]/td[2]/a");
80 $this->type('total_amount', '300.00');
81 $this->click('_qf_Contribution_upload-bottom');
82 $this->waitForPageToLoad("30000");
83 $this->waitForText('crm-notification-container', "The contribution record has been saved.");
84
45fabf8e 85 $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
86 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[1]/span/a");
b879962e
DG
87
88 //Check whether the next two payments are done or not
45fabf8e 89 $this->waitForElementPresent("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[8]/a[text()='View Payment']");
90 $this->verifyText("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td[7]","Completed");
91 $this->verifyText("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[4]/td[7]","Completed");
b879962e
DG
92
93
94 //Cancel the contribution made for amount of 300.00
45fabf8e 95 $this->waitForElementPresent("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[8]/a[text()='View Payment']");
96 $this->click("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[8]/a");
b879962e
DG
97 $this->waitForElementPresent("xpath=//form[@id='ContributionView']//div[2]/div/div/a");
98 $this->click("xpath=//form[@id='ContributionView']//div[2]/div/div/a");
99 $this->waitForElementPresent("_qf_Contribution_upload-bottom");
100 $this->select('contribution_status_id', 'value=3');
101 $this->click("_qf_Contribution_upload-bottom");
102
45fabf8e 103 $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
104 $this->click("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[1]/span/a");
105 $this->waitForElementPresent("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td[7]");
b879962e
DG
106
107 // verify that first paayment is cancelled and the rest two payments are revert back to the pending status
45fabf8e 108 $this->verifyText("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[7]","Cancelled");
109 $this->verifyText("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td[7]","Pending");
110 $this->verifyText("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[4]/td[7]","Pending");
b879962e
DG
111
112 // Check whether a new payment with pending status is added at the last or not
45fabf8e 113 $this->verifyText("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[14]/td[7]","Pending");
b879962e
DG
114
115 // verify that Balance sum is correct
45fabf8e 116 $this->verifyText("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[4]","1,200.00");
b879962e
DG
117
118 }
119}
120