Merge pull request #2998 from yashodha/CRM-14500
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / ContactContextAddTest.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 class WebTest_Contribute_ContactContextAddTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testContactContextAdd() {
35
36 // Log in using webtestLogin() method
37 $this->webtestLogin();
38
39 // Create a contact to be used as soft creditor
40 $softCreditFname = substr(sha1(rand()), 0, 7);
41 $softCreditLname = substr(sha1(rand()), 0, 7);
42 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
43
44 // Adding contact with randomized first name (so we can then select that contact when creating contribution.)
45 // We're using Quick Add block on the main page for this.
46 $firstName = substr(sha1(rand()), 0, 7);
47 // Add new Financial Account
48 $orgName = 'Alberta '.substr(sha1(rand()), 0, 7);
49 $financialAccountTitle = 'Financial Account '.substr(sha1(rand()), 0, 4);
50 $financialAccountDescription = "{$financialAccountTitle} Description";
51 $accountingCode = 1033;
52 $financialAccountType = 'Asset';
53 $taxDeductible = FALSE;
54 $isActive = FALSE;
55 $isTax = TRUE;
56 $taxRate = 9.99999999;
57 $isDefault = FALSE;
58
59 //Add new organisation
60 if($orgName) {
61 $this->webtestAddOrganization($orgName);
62 }
63 $this->_testAddFinancialAccount($financialAccountTitle,
64 $financialAccountDescription,
65 $accountingCode,
66 $orgName,
67 $financialAccountType,
68 $taxDeductible,
69 $isActive,
70 $isTax,
71 $taxRate,
72 $isDefault
73 );
74
75 $this->webtestAddContact($firstName, "Anderson", true);
76
77 // Get the contact id of the new contact
78 $contactUrl = $this->parseURL();
79 $cid = $contactUrl['queryString']['cid'];
80 $this->assertType('numeric', $cid);
81
82 // go to contribution tab and add contribution.
83 $this->click("css=li#tab_contribute a");
84
85 // wait for Record Contribution elenment.
86 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
87 $this->click("link=Record Contribution (Check, Cash, EFT ...)");
88
89 $this->waitForElementPresent("_qf_Contribution_cancel-bottom");
90 // fill financial type.
91 $this->select("financial_type_id", "Donation");
92
93 // fill in Received Date
94 $this->webtestFillDate('receive_date');
95
96 // source
97 $this->type("source", "Mailer 1");
98
99 // total amount
100 $this->type("total_amount", "100");
101
102 // select payment instrument type = Check and enter chk number
103 $this->select("payment_instrument_id", "value=4");
104 $this->waitForElementPresent("check_number");
105 $this->type("check_number", "check #1041");
106
107 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
108
109 // soft credit
110 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_id_1');
111 $this->type("soft_credit_amount_1", "100");
112
113 //Custom Data
114 //$this->waitForElementPresent('CIVICRM_QFID_3_6');
115 //$this->click('CIVICRM_QFID_3_6');
116
117 //Additional Detail section
118 $this->click("AdditionalDetail");
119 $this->waitForElementPresent("thankyou_date");
120
121 $this->type("note", "Test note for {$firstName}.");
122 $this->type("fee_amount", "0");
123 $this->type("net_amount", "0");
124 $this->type("invoice_id", time());
125 $this->webtestFillDate('thankyou_date');
126
127
128 //Premium section
129 $this->click("Premium");
130 $this->waitForElementPresent("fulfilled_date");
131 $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )");
132 $this->select("product_name[1]", "label=Black");
133 $this->webtestFillDate('fulfilled_date');
134
135 // Clicking save.
136 $this->clickLink("_qf_Contribution_upload-bottom", 'civicrm-footer');
137 // Is status message correct?
138 $this->waitForText('crm-notification-container', "The contribution record has been saved");
139
140 $this->waitForElementPresent("xpath=//div[@class='view-content']/table[2]/tbody/tr/td[8]/span/a[text()='View']");
141
142 // click through to the Contribution view screen
143 $this->click("xpath=//div[@class='view-content']/table[2]/tbody/tr/td[8]/span/a[text()='View']");
144 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
145
146 // verify Contribution created. Non-deductible amount derived from market value of selected 'sample' coffee mug premium (CRM-11956)
147 $verifyData = array(
148 'From' => $firstName . " Anderson",
149 'Financial Type' => 'Donation',
150 'Contribution Status' => 'Completed',
151 'Paid By' => 'Check',
152 'Total Amount' => '$ 100.00',
153 'Non-deductible Amount' => '$ 12.50',
154 'Check Number' => 'check #1041',
155 );
156 foreach ($verifyData as $label => $value) {
157 $this->verifyText("xpath=//form[@id='ContributionView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
158 preg_quote($value)
159 );
160 }
161
162 // check values of contribution record in the DB
163 $viewUrl = $this->parseURL();
164 $id = $viewUrl['queryString']['id'];
165 $this->assertType('numeric', $id);
166
167 $searchParams = array('id' => $id);
168 $compareParams = array(
169 'contact_id' => $cid,
170 'total_amount' => '100.00',
171 );
172 $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $searchParams, $compareParams);
173
174 // go to soft creditor contact view page
175 $this->click("css=table.crm-soft-credit-listing tbody tr td a");
176
177 // go to contribution tab
178 $this->waitForElementPresent("css=li#tab_contribute a");
179 $this->click("css=li#tab_contribute a");
180 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
181
182 // verify soft credit details
183 $expected = array(
184 4 => 'Donation',
185 2 => '100.00',
186 6 => 'Completed',
187 1 => "{$firstName} Anderson",
188 );
189 foreach ($expected as $value => $label) {
190 $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));
191 }
192 }
193 }
194