dd16d80a39a16e4e469ca9271f9bc5fa77dff98c
[civicrm-core.git] / tests / phpunit / WebTest / Pledge / StandaloneAddDeleteTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
29 /**
30 * Class WebTest_Pledge_StandaloneAddDeleteTest
31 */
32 class WebTest_Pledge_StandaloneAddDeleteTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testStandalonePledgeAddDelete() {
39 $this->webtestLogin();
40
41 $this->openCiviPage('pledge/add', 'reset=1&context=standalone', '_qf_Pledge_upload');
42
43 // create new contact using dialog
44 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
45 $lastName = 'Za' . substr(sha1(rand()), 0, 7);
46 $this->webtestNewDialogContact($firstName, $lastName, $firstName . '@example.com');
47
48 $this->type('amount', '2400');
49 $this->type('installments', '10');
50 $this->select('frequency_unit', 'value=month');
51 $this->type('frequency_day', '2');
52 $this->webtestFillDate('acknowledge_date', 'now');
53 $this->select('contribution_page_id', 'value=3');
54 $this->click('_qf_Pledge_upload-bottom');
55 $this->waitForPageToLoad("30000");
56
57 $this->waitForText('crm-notification-container', "Pledge has been recorded and the payment schedule has been created.");
58
59 // verify if Pledge is created
60 $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
61
62 //click through to the Pledge view screen
63 $this->click("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
64 $this->waitForElementPresent('_qf_PledgeView_next-bottom');
65 $pledgeDate = date('F jS, Y', strtotime('now'));
66
67 $this->webtestVerifyTabularData(array(
68 'Pledge By' => $firstName . ' ' . $lastName,
69 'Total Pledge Amount' => '$ 2,400.00',
70 'To be paid in' => '10 installments of $ 240.00 every 1 month(s)',
71 'Payments are due on the' => '2 day of the period',
72 'Pledge Made' => $pledgeDate,
73 'Financial Type' => 'Donation',
74 'Pledge Status' => 'Pending',
75 )
76 );
77 $this->click('_qf_PledgeView_next-bottom');
78 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[1]/span/a");
79 $this->waitForAjaxContent();
80 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[1]/span/a");
81 $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[2]/td[2]/table/tbody/tr[2]/td[8]/a[text()='Record Payment']");
82 $this->click("xpath=//div[@class='view-content']//table//tbody/tr[2]/td[2]/table/tbody/tr[2]/td[8]/a");
83 $this->waitForElementPresent("xpath=//form[@id='Contribution']//div[2]/table/tbody/tr[3]/td[2]/a");
84 $this->click("xpath=//form[@id='Contribution']//div[2]/table/tbody/tr[3]/td[2]/a");
85 $this->type('total_amount', '300.00');
86 $this->click('_qf_Contribution_upload-bottom');
87
88 $this->waitForText('crm-notification-container', "The contribution record has been saved.");
89
90 $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
91 $this->waitForAjaxContent();
92 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[1]/span/a");
93 $this->waitForElementPresent("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td[8]/a[text()='Record Payment']");
94 $this->click("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td[8]/a");
95 $this->waitForElementPresent("xpath=//form[@id='Contribution']//div[2]/table/tbody/tr[3]/td[2]/a");
96 $this->click("xpath=//form[@id='Contribution']//div[2]/table/tbody/tr[3]/td[2]/a");
97 $this->type('total_amount', '250.00');
98 $this->click('_qf_Contribution_upload-bottom');
99 $this->waitForText('crm-notification-container', "The contribution record has been saved.");
100
101 $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
102 $this->waitForAjaxContent();
103 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[1]/span/a");
104 $this->waitForElementPresent("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[4]/td[8]/a[text()='Record Payment']");
105 $this->click("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[4]/td[8]/a");
106 $this->waitForElementPresent("xpath=//form[@id='Contribution']//div[2]/table/tbody/tr[3]/td[2]/a");
107 $this->click("xpath=//form[@id='Contribution']//div[2]/table/tbody/tr[3]/td[2]/a");
108
109 $this->type('total_amount', '170.00');
110 $this->click('_qf_Contribution_upload-bottom');
111 $this->waitForText('crm-notification-container', "The contribution record has been saved.");
112
113 // delete the contribution associated with the 2nd payment
114 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[10]/span/a[text()='View']");
115 $this->waitForAjaxContent();
116 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[1]/span/a");
117 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[2]/td[2]/table[@class='nestedSelector']/tbody/tr[3]/td[8]/a[text()='View Payment']");
118 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[2]/td[2]/table[@class='nestedSelector']/tbody/tr[3]/td[8]/a");
119 $this->waitForElementPresent("xpath=//form[@id='ContributionView']//div[2]/div/div/a[2]/span[text()='Delete']");
120 $this->click("xpath=//form[@id='ContributionView']//div[2]/div/div/a[2]/span[text()='Delete']");
121 $this->waitForElementPresent("xpath=//form[@id='Contribution']/div[2]/div[2]/span/input[@value='Delete']");
122 $this->click("xpath=//form[@id='Contribution']/div[2]/div[2]/span/input[@value='Delete']");
123 $this->waitForElementPresent("xpath=//li[@id='tab_pledge']/a");
124 $this->click("xpath=//li[@id='tab_pledge']/a");
125 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[10]/span/a[text()='View']");
126 $this->waitForAjaxContent();
127 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[1]/span/a");
128 $this->waitForElementPresent("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td[7]");
129
130 $this->verifyText("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td[7]","Pending");
131 $this->waitForElementPresent("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td");
132
133 // verify that payment owed amount is correct (250.00)
134 $this->verifyText("xpath=//div[@class='view-content']//table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td","250.00");
135 // verify that Total Paid and Balance sums are correct
136 $this->verifyText("xpath=//div[@class='view-content' and contains(., 'view pledge payments')]/table[@class='selector row-highlight']//tbody/tr[1]/td[3]","470.00");
137 $this->verifyText("xpath=//div[@class='view-content' and contains(., 'view pledge payments')]/table[@class='selector row-highlight']//tbody/tr[1]/td[4]","1,930.00");
138
139 }
140 }
141