Merge pull request #2762 from amitajgaonkar/WebtestIssues
[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 $financialAccountTitle = 'Financial Account '.substr(sha1(rand()), 0, 4);
40 $financialAccountDescription = "{$financialAccountTitle} Description";
41 $accountingCode = 1033;
42 $financialAccountType = 'Expenses';
43 $taxDeductible = FALSE;
44 $isActive = TRUE;
45 $isTax = TRUE;
46 $taxRate = 9.99999999;
47 $isDefault = FALSE;
48
49 //Add new organisation
50 if($orgName) {
51 $this->webtestAddOrganization($orgName);
52 }
53
54 $this->_testAddFinancialAccount($financialAccountTitle,
55 $financialAccountDescription,
56 $accountingCode,
57 $orgName,
58 $financialAccountType,
59 $taxDeductible,
60 $isActive,
61 $isTax,
62 $taxRate,
63 $isDefault
64 );
65
66 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
67
68 $this->clickLink("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']", '_qf_FinancialAccount_cancel-botttom');
69 //Varify Data after Adding new Financial Account
70 $verifyData = array('name' => $financialAccountTitle,
71 'description' => $financialAccountDescription,
72 'accounting_code' => $accountingCode,
73 'contact_name' => $orgName,
74 'tax_rate' => $taxRate,
75 'is_tax' => 'on',
76 'is_deductible' => 'off',
77 'is_default' => 'off'
78 );
79
80 $this->_assertFinancialAccount($verifyData);
81 $verifySelectFieldData = array('financial_account_type_id' => $financialAccountType);
82 $this->_assertSelectVerify($verifySelectFieldData);
83 $this->click('_qf_FinancialAccount_cancel-botttom');
84
85 //Edit Financial Account
86 $editfinancialAccount = $financialAccountTitle;
87 $financialAccountTitle .= ' Edited';
88 $orgNameEdit = FALSE;
89 $financialAccountType = 'Revenue';
90
91 if ($orgNameEdit) {
92 $orgNameEdit = 'NGO '.substr(sha1(rand()), 0, 7);
93 $this->webtestAddOrganization($orgNameEdit);
94 }
95
96 $this->_testEditFinancialAccount($editfinancialAccount,
97 $financialAccountTitle,
98 $financialAccountDescription,
99 $accountingCode,
100 $orgNameEdit,
101 $financialAccountType,
102 $taxDeductible,
103 $isActive,
104 $isTax,
105 $taxRate,
106 $isDefault
107 );
108
109 if($orgNameEdit) {
110 $orgName = $orgNameEdit;
111 }
112 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
113 $this->clickLink("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']", '_qf_FinancialAccount_cancel-botttom');
114
115 $verifyData = array( 'name' => $financialAccountTitle,
116 'description' => $financialAccountDescription,
117 'accounting_code' => $accountingCode,
118 'contact_name' => $orgName,
119 'tax_rate' => $taxRate,
120 'is_tax' => 'on',
121 'is_deductible' => 'off',
122 'is_default' => 'off',
123 );
124 $verifySelectFieldData = array('financial_account_type_id' => $financialAccountType);
125 $this->_assertFinancialAccount($verifyData);
126 $this->_assertSelectVerify($verifySelectFieldData);
127 $this->click('_qf_FinancialAccount_cancel-botttom');
128 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Delete']");
129
130 //Delete Financial Account
131 $this->_testDeleteFinancialAccount($financialAccountTitle);
132 }
133 }