3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contribute_ContactContextAddTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testContactContextAdd() {
36 // Log in using webtestLogin() method
37 $this->webtestLogin();
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);
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;
56 $taxRate = 9.99999999;
59 //Add new organisation
61 $this->webtestAddOrganization($orgName);
63 $this->_testAddFinancialAccount($financialAccountTitle,
64 $financialAccountDescription,
67 $financialAccountType,
75 $this->webtestAddContact($firstName, "Anderson", true);
77 // Get the contact id of the new contact
78 $contactUrl = $this->parseURL();
79 $cid = $contactUrl['queryString']['cid'];
80 $this->assertType('numeric', $cid);
82 // go to contribution tab and add contribution.
83 $this->click("css=li#tab_contribute a");
85 // wait for Record Contribution elenment.
86 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
87 $this->click("link=Record Contribution (Check, Cash, EFT ...)");
89 $this->waitForElementPresent("_qf_Contribution_cancel-bottom");
90 // fill financial type.
91 $this->select("financial_type_id", "Donation");
93 // fill in Received Date
94 $this->webtestFillDate('receive_date');
97 $this->type("source", "Mailer 1");
100 $this->type("total_amount", "100");
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");
107 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
110 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_id_1');
111 $this->type("soft_credit_amount_1", "100");
114 //$this->waitForElementPresent('CIVICRM_QFID_3_6');
115 //$this->click('CIVICRM_QFID_3_6');
117 //Additional Detail section
118 $this->click("AdditionalDetail");
119 $this->waitForElementPresent("thankyou_date");
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');
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');
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");
140 $this->waitForElementPresent("xpath=//div[@class='view-content']/table[2]/tbody/tr/td[8]/span/a[text()='View']");
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');
146 // verify Contribution created. Non-deductible amount derived from market value of selected 'sample' coffee mug premium (CRM-11956)
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',
156 foreach ($verifyData as $label => $value) {
157 $this->verifyText("xpath=//form[@id='ContributionView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
162 // check values of contribution record in the DB
163 $viewUrl = $this->parseURL();
164 $id = $viewUrl['queryString']['id'];
165 $this->assertType('numeric', $id);
167 $searchParams = array('id' => $id);
168 $compareParams = array(
169 'contact_id' => $cid,
170 'total_amount' => '100.00',
172 $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $searchParams, $compareParams);
174 // go to soft creditor contact view page
175 $this->click("css=table.crm-soft-credit-listing tbody tr td a");
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 ...)");
182 // verify soft credit details
187 1 => "{$firstName} Anderson",
189 foreach ($expected as $value => $label) {
190 $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));