Merge pull request #2973 from GinkgoFJG/CRM-14354v2
[civicrm-core.git] / tests / phpunit / WebTest / Financial / FinancialAccountTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License along with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Financial_FinancialAccountTest extends CiviSeleniumTestCase {
30
31 /**
32 * Test To Add Financial Account class attributes.
33 */
34 function testFinancialAccount() {
35 $this->webtestLogin();
36
37 // Add new Financial Account
38 $orgName = 'Alberta '.substr(sha1(rand()), 0, 7);
39 $uniqueName = explode(" ",$orgName);
40 $financialAccountTitle = 'Financial Account '.substr(sha1(rand()), 0, 4);
41 $financialAccountDescription = "{$financialAccountTitle} Description";
42 $accountingCode = 1033;
43 $financialAccountType = 'Expenses';
44 $taxDeductible = FALSE;
45 $isActive = TRUE;
46 $isTax = TRUE;
47 $taxRate = 9.99999999;
48 $isDefault = FALSE;
49
50 //Add new organisation
51 if($orgName) {
52 $this->webtestAddOrganization($orgName);
53 }
54
55 $this->_testAddFinancialAccount($financialAccountTitle,
56 $financialAccountDescription,
57 $accountingCode,
58 $uniqueName[1],
59 $financialAccountType,
60 $taxDeductible,
61 $isActive,
62 $isTax,
63 $taxRate,
64 $isDefault
65 );
66
67 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
68
69 $this->clickLink("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']", '_qf_FinancialAccount_cancel-botttom', FALSE);
70 //Varify Data after Adding new Financial Account
71 $verifyData = array('name' => $financialAccountTitle,
72 'description' => $financialAccountDescription,
73 'accounting_code' => $accountingCode,
74 'tax_rate' => $taxRate,
75 'is_tax' => 'on',
76 'is_deductible' => 'off',
77 'is_default' => 'off'
78 );
79
80 $this->assertEquals($orgName, $this->getText("xpath=//*[@id='s2id_contact_id']/a/span[1]"));
81
82 $this->_assertFinancialAccount($verifyData);
83 $verifySelectFieldData = array('financial_account_type_id' => $financialAccountType);
84 $this->_assertSelectVerify($verifySelectFieldData);
85 $this->click('_qf_FinancialAccount_cancel-botttom');
86
87 //Edit Financial Account
88 $editfinancialAccount = $financialAccountTitle;
89 $financialAccountTitle .= ' Edited';
90 $orgNameEdit = FALSE;
91 $financialAccountType = 'Revenue';
92
93 if ($orgNameEdit) {
94 $orgNameEdit = 'NGO '.substr(sha1(rand()), 0, 7);
95 $this->webtestAddOrganization($orgNameEdit);
96 $uniqueName = explode(" ",$orgNameEdit);
97 }
98
99 $this->_testEditFinancialAccount($editfinancialAccount,
100 $financialAccountTitle,
101 $financialAccountDescription,
102 $accountingCode,
103 $uniqueName[1],
104 $financialAccountType,
105 $taxDeductible,
106 $isActive,
107 $isTax,
108 $taxRate,
109 $isDefault
110 );
111
112 if($orgNameEdit) {
113 $orgName = $orgNameEdit;
114 }
115 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
116 $this->clickLink("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']", '_qf_FinancialAccount_cancel-botttom', FALSE);
117
118 $verifyData = array( 'name' => $financialAccountTitle,
119 'description' => $financialAccountDescription,
120 'accounting_code' => $accountingCode,
121 'tax_rate' => $taxRate,
122 'is_tax' => 'on',
123 'is_deductible' => 'off',
124 'is_default' => 'off',
125 );
126
127 $this->assertEquals($orgName, $this->getText("xpath=//*[@id='s2id_contact_id']/a/span[1]"));
128
129 $this->_assertFinancialAccount($verifyData);
130 $verifySelectFieldData = array('financial_account_type_id' => $financialAccountType);
131 $this->_assertSelectVerify($verifySelectFieldData);
132 $this->click('_qf_FinancialAccount_cancel-botttom');
133 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Delete']");
134
135 //Delete Financial Account
136 $this->_testDeleteFinancialAccount($financialAccountTitle);
137 }
138 }