more test cleanup
[civicrm-core.git] / tests / phpunit / WebTest / Financial / FinancialAccountTypeTest.php
CommitLineData
6a488035
TO
1<?php
2
3/*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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
28require_once 'CiviTest/CiviSeleniumTestCase.php';
29
30class WebTest_Financial_FinancialAccountTypeTest extends CiviSeleniumTestCase {
31
32 function testFinancialAccount() {
33 // To Add Financial Account
34 // class attributes.
35 $this->open($this->sboxPath);
36
37 // Log in using webtestLogin() method
38 $this->webtestLogin();
39
40 // Add new Financial Account
41 $orgName = 'Alberta '.substr(sha1(rand()), 0, 7);
42 $financialAccountTitle = 'Financial Account '.substr(sha1(rand()), 0, 4);
43 $financialAccountDescription = "{$financialAccountTitle} Description";
44 $accountingCode = 1033;
45 $financialAccountType = 'Revenue';
46 $taxDeductible = FALSE;
47 $isActive = FALSE;
48 $isTax = TRUE;
49 $taxRate = 5.20;
50 $isDefault = FALSE;
51
52 //Add new organisation
53 if ($orgName) {
54 $this->webtestAddOrganization($orgName);
55 }
56
57 $this->_testAddFinancialAccount(
58 $financialAccountTitle,
59 $financialAccountDescription,
60 $accountingCode,
61 $orgName,
62 $financialAccountType,
63 $taxDeductible,
64 $isActive,
65 $isTax,
66 $taxRate,
67 $isDefault
68 );
69
70 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
71
72 $this->click("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
73 $this->waitForPageToLoad($this->getTimeoutMsec());
74 $this->waitForElementPresent('_qf_FinancialAccount_cancel-botttom');
75
76 //Varify Data after Adding new Financial Account
77 $verifyData = array(
78 'name' => $financialAccountTitle,
79 'description' => $financialAccountDescription,
80 'accounting_code' => $accountingCode,
81 'contact_name' => $orgName,
82 'tax_rate' => $taxRate,
83 'is_tax' => 'on',
84 'is_deductible' => 'off',
85 'is_default' => 'off',
86 );
87
88 $this->_assertFinancialAccount($verifyData);
89 $verifySelectFieldData = array(
90 'financial_account_type_id' => $financialAccountType,
91 );
92 $this->_assertSelectVerify($verifySelectFieldData);
93 $this->click('_qf_FinancialAccount_cancel-botttom');
94 $this->waitForPageToLoad($this->getTimeoutMsec());
95
96 //Add new Financial Type
97 $financialType['name'] = 'FinancialType '.substr(sha1(rand()), 0, 4);
98 $financialType['is_deductible'] = true;
99 $financialType['is_reserved'] = false;
100 $this->addeditFinancialType($financialType);
101 $accountRelationship = "Income Account is";
102 $expected[] = array(
103 'financial_account' => $financialAccountTitle,
104 'account_relationship' => $accountRelationship
105 );
106
107 $this->select('account_relationship', "label={$accountRelationship}");
108 $this->select('financial_account_id', "label={$financialAccountTitle}");
109 $this->click('_qf_FinancialTypeAccount_next_new');
110 $this->waitForPageToLoad($this->getTimeoutMsec());
111 $text = 'The financial type Account has been saved.';
112 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
113 $text = 'You can add another Financial Account Type.';
114 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
115 $accountRelationship = 'Expense Account is';
116 $expected[] = array(
117 'financial_account' => 'Banking Fees',
118 'account_relationship' => $accountRelationship
119 );
120
121 $this->select('account_relationship', "label={$accountRelationship}");
122 $this->select('financial_account_id', "label=Banking Fees");
123 $this->click('_qf_FinancialTypeAccount_next');
124 $this->waitForElementPresent( 'newfinancialTypeAccount');
125 $text = 'The financial type Account has been saved.';
126 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
127
128 foreach ($expected as $value => $label) {
129 $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$label[financial_account]']/../td[2]", preg_quote($label['account_relationship']));
130 }
131 $this->open($this->sboxPath . 'civicrm/admin/financial/financialType?reset=1');
132 $this->waitForElementPresent('newFinancialType');
133 $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$financialType[name]']/../td[3]", $financialAccountTitle. ',Banking Fees');
134 $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$financialType[name]']/../td[7]/span/a[text()='Accounts']");
135 $this->waitForElementPresent('newfinancialTypeAccount');
136 $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='Banking Fees']/../td[7]/span/a[text()='Edit']");
137 $this->waitForElementPresent('_qf_FinancialTypeAccount_next');
138 $this->select('account_relationship', "value=select");
139 sleep(1);
140 $this->select('account_relationship', "label=Accounts Receivable Account is");
141 $this->select('financial_account_id', "label=Accounts Receivable");
142 $this->click('_qf_FinancialTypeAccount_next');
143 $this->waitForElementPresent("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='Accounts Receivable']/../td[7]/span/a[text()='Edit']");
144 $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='Accounts Receivable']/../td[2]", preg_quote('Accounts Receivable Account is'));
145 $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='Accounts Receivable']/../td[7]/span/a[text()='Delete']");
146 $this->waitForPageToLoad($this->getTimeoutMsec());
147 $this->waitForElementPresent('_qf_FinancialTypeAccount_next-botttom');
148 $this->click('_qf_FinancialTypeAccount_next-botttom');
149 $this->waitForPageToLoad($this->getTimeoutMsec());
150 $this->assertTrue($this->isTextPresent('Selected financial type account has been deleted.'), 'Missing text: ' . 'Selected financial type account has been deleted.' );
151
152 //edit financial type
153 $financialType['oldname'] = $financialType['name'];
154 $financialType['name'] = 'Edited FinancialType '.substr(sha1(rand()), 0, 4);
155 $financialType['is_deductible'] = true;
156 $financialType['is_reserved'] = false;
157 $this->addeditFinancialType($financialType , 'Edit');
158 //delete financialtype
159 $this->addeditFinancialType($financialType , 'Delete');
160 }
161}