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