Merge branch 4.5 into master
[civicrm-core.git] / tests / phpunit / WebTest / Financial / FinancialAccountTest.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035
TO
26
27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Financial_FinancialAccountTest
31 */
6a488035
TO
32class WebTest_Financial_FinancialAccountTest extends CiviSeleniumTestCase {
33
071a6d2e
CW
34 /**
35 * Test To Add Financial Account class attributes.
36 */
00be9182 37 public function testFinancialAccount() {
6a488035 38 $this->webtestLogin();
76e86fd8 39
6a488035 40 // Add new Financial Account
92fcb95f 41 $orgName = 'Alberta ' . substr(sha1(rand()), 0, 7);
6c6e6187 42 $uniqueName = explode(" ", $orgName);
92fcb95f 43 $financialAccountTitle = 'Financial Account ' . substr(sha1(rand()), 0, 4);
6a488035
TO
44 $financialAccountDescription = "{$financialAccountTitle} Description";
45 $accountingCode = 1033;
1187b883 46 $financialAccountType = 'Liability';
6a488035
TO
47 $taxDeductible = FALSE;
48 $isActive = TRUE;
49 $isTax = TRUE;
50 $taxRate = 9.99999999;
51 $isDefault = FALSE;
76e86fd8 52
6a488035 53 //Add new organisation
22e263ad 54 if ($orgName) {
6a488035
TO
55 $this->webtestAddOrganization($orgName);
56 }
76e86fd8 57
6a488035
TO
58 $this->_testAddFinancialAccount($financialAccountTitle,
59 $financialAccountDescription,
60 $accountingCode,
6cbe4dc3 61 $uniqueName[1],
6a488035
TO
62 $financialAccountType,
63 $taxDeductible,
64 $isActive,
65 $isTax,
66 $taxRate,
67 $isDefault
68 );
76e86fd8 69
4a058f26 70 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1]/div[text()='{$financialAccountTitle}']/../../td[9]/span/a[text()='Edit']");
76e86fd8 71
4a058f26 72 $this->clickLink("xpath=//table/tbody//tr/td[1]/div[text()='{$financialAccountTitle}']/../../td[9]/span/a[text()='Edit']", '_qf_FinancialAccount_cancel-botttom', FALSE);
6a488035 73 //Varify Data after Adding new Financial Account
6c6e6187 74 $verifyData = array(
92915c55 75 'name' => $financialAccountTitle,
6a488035
TO
76 'description' => $financialAccountDescription,
77 'accounting_code' => $accountingCode,
92915c55 78 'tax_rate' => $taxRate,
6a488035
TO
79 'is_tax' => 'on',
80 'is_deductible' => 'off',
21dfd5f5 81 'is_default' => 'off',
6a488035 82 );
e9479dcf 83
6cbe4dc3 84 $this->assertEquals($orgName, $this->getText("xpath=//*[@id='s2id_contact_id']/a/span[1]"));
76e86fd8 85
6a488035
TO
86 $this->_assertFinancialAccount($verifyData);
87 $verifySelectFieldData = array('financial_account_type_id' => $financialAccountType);
88 $this->_assertSelectVerify($verifySelectFieldData);
89 $this->click('_qf_FinancialAccount_cancel-botttom');
76e86fd8 90
6a488035
TO
91 //Edit Financial Account
92 $editfinancialAccount = $financialAccountTitle;
93 $financialAccountTitle .= ' Edited';
94 $orgNameEdit = FALSE;
1187b883 95 $financialAccountType = 'Liability';
76e86fd8 96
6a488035 97 if ($orgNameEdit) {
92fcb95f 98 $orgNameEdit = 'NGO ' . substr(sha1(rand()), 0, 7);
6a488035 99 $this->webtestAddOrganization($orgNameEdit);
6c6e6187 100 $uniqueName = explode(" ", $orgNameEdit);
6a488035 101 }
76e86fd8 102
6a488035
TO
103 $this->_testEditFinancialAccount($editfinancialAccount,
104 $financialAccountTitle,
105 $financialAccountDescription,
106 $accountingCode,
6cbe4dc3 107 $uniqueName[1],
6a488035
TO
108 $financialAccountType,
109 $taxDeductible,
110 $isActive,
111 $isTax,
112 $taxRate,
113 $isDefault
76e86fd8
CW
114 );
115
22e263ad 116 if ($orgNameEdit) {
6a488035
TO
117 $orgName = $orgNameEdit;
118 }
4a058f26
WA
119 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1]/div[text()='{$financialAccountTitle}']/../../td[9]/span/a[text()='Edit']");
120 $this->clickLink("xpath=//table/tbody//tr/td[1]/div[text()='{$financialAccountTitle}']/../../td[9]/span/a[text()='Edit']", '_qf_FinancialAccount_cancel-botttom', FALSE);
76e86fd8 121
6c6e6187 122 $verifyData = array(
92915c55 123 'name' => $financialAccountTitle,
6a488035
TO
124 'description' => $financialAccountDescription,
125 'accounting_code' => $accountingCode,
92915c55 126 'tax_rate' => $taxRate,
6a488035
TO
127 'is_tax' => 'on',
128 'is_deductible' => 'off',
129 'is_default' => 'off',
130 );
e9479dcf 131
6cbe4dc3 132 $this->assertEquals($orgName, $this->getText("xpath=//*[@id='s2id_contact_id']/a/span[1]"));
e9479dcf 133
6a488035 134 $this->_assertFinancialAccount($verifyData);
6c6e6187 135 $verifySelectFieldData = array('financial_account_type_id' => $financialAccountType);
6a488035
TO
136 $this->_assertSelectVerify($verifySelectFieldData);
137 $this->click('_qf_FinancialAccount_cancel-botttom');
4a058f26 138 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1]/div[text()='{$financialAccountTitle}']/../../td[9]/span/a[text()='Delete']");
76e86fd8 139
6a488035
TO
140 //Delete Financial Account
141 $this->_testDeleteFinancialAccount($financialAccountTitle);
142 }
96025800 143
6a488035 144}