Merge pull request #4818 from pratikshad/CRM-15770
[civicrm-core.git] / tests / phpunit / WebTest / Financial / FinancialAccountTypeTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
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
30 /**
31 * Class WebTest_Financial_FinancialAccountTypeTest
32 */
33 class WebTest_Financial_FinancialAccountTypeTest extends CiviSeleniumTestCase {
34
35 public function testFinancialAccount() {
36 // To Add Financial Account
37
38 // class attributes.
39
40 // Log in using webtestLogin() method
41 $this->webtestLogin();
42
43 //Add new Financial Type
44 $financialType['name'] = 'FinancialType '.substr(sha1(rand()), 0, 4);
45 $financialType['is_deductible'] = true;
46 $financialType['is_reserved'] = false;
47 $this->addeditFinancialType($financialType);
48 $expected = array(
49 array(
50 'financial_account' => $financialType['name'],
51 'account_relationship' => "Income Account is",
52 ),
53 array(
54 'financial_account' => 'Banking Fees',
55 'account_relationship' => 'Expense Account is',
56 ),
57 array(
58 'financial_account' => 'Accounts Receivable',
59 'account_relationship' => 'Accounts Receivable Account is',
60 ),
61 array(
62 'financial_account' => 'Premiums',
63 'account_relationship' => 'Cost of Sales Account is',
64 ),
65 );
66
67 $this->waitForElementPresent('newFinancialType');
68 $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$financialType[name]']/../td[7]/span/a[text()='Accounts']");
69 $this->waitForElementPresent('newfinancialTypeAccount');
70
71 foreach ($expected as $value => $label) {
72 $this->verifyText("xpath=//div[@id='ltype']/div/table/tbody/tr/td[2][text()='$label[financial_account]']/../td[1]", preg_quote($label['account_relationship']));
73 }
74
75 $this->openCiviPage('admin/financial/financialType', 'reset=1', 'newFinancialType');
76 $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$financialType[name]']/../td[3]", 'Accounts Receivable,Banking Fees,Premiums,' . $financialType['name']);
77 $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$financialType[name]']/../td[7]/span/a[text()='Accounts']");
78 $this->waitForElementPresent('newfinancialTypeAccount');
79 $this->click("xpath=//div[@id='ltype']/div/table/tbody/tr/td[2][text()='Banking Fees']/../td[7]/span/a[text()='Edit']");
80 $this->waitForElementPresent('_qf_FinancialTypeAccount_next');
81 $this->select('account_relationship', "value=select");
82 $this->waitForElementPresent("xpath=//select[@id='account_relationship']/option[text()='- Select Financial Account Relationship -']");
83 $this->select('account_relationship', "label=Premiums Inventory Account is");
84 $this->waitForElementPresent("xpath=//select[@id='financial_account_id']/option[3][text()='Deposit Bank Account']");
85 $this->select('financial_account_id', "label=Premiums inventory");
86 $this->click('_qf_FinancialTypeAccount_next');
87 $this->waitForElementPresent("xpath=//div[@id='ltype']/div/table/tbody/tr/td[2][text()='Premiums inventory']/../td[7]/span/a[text()='Edit']");
88 $this->verifyText("xpath=//div[@id='ltype']/div/table/tbody/tr/td[2][text()='Premiums inventory']/../td[1]", preg_quote('Premiums Inventory Account is'));
89 $this->clickLink("xpath=//div[@id='ltype']/div/table/tbody/tr/td[2][text()='Premiums inventory']/../td[7]/span/a[text()='Delete']", '_qf_FinancialTypeAccount_next-botttom', FALSE);
90 $this->click('_qf_FinancialTypeAccount_next-botttom');
91 $this->waitForText('crm-notification-container', 'Selected financial type account has been deleted.');
92
93 //edit financial type
94 $financialType['oldname'] = $financialType['name'];
95 $financialType['name'] = 'Edited FinancialType '.substr(sha1(rand()), 0, 4);
96 $financialType['is_deductible'] = true;
97 $financialType['is_reserved'] = false;
98 $this->addeditFinancialType($financialType , 'Edit');
99 //delete financialtype
100 $this->addeditFinancialType($financialType , 'Delete');
101 }
102 }