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