--fixed webtest, crm test and upgrade script for CRM-12470
[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
35 // class attributes.
36
37 // Log in using webtestLogin() method
38 $this->webtestLogin();
39
40 //Add new Financial Type
41 $financialType['name'] = 'FinancialType '.substr(sha1(rand()), 0, 4);
42 $financialType['is_deductible'] = true;
43 $financialType['is_reserved'] = false;
44 $this->addeditFinancialType($financialType);
45 $expected = array(
46 array(
47 'financial_account' => $financialType['name'],
48 'account_relationship' => "Income Account is",
49 ),
50 array(
51 'financial_account' => 'Banking Fees',
52 'account_relationship' => 'Expense Account is',
53 ),
54 array(
55 'financial_account' => 'Accounts Receivable',
56 'account_relationship' => 'Accounts Receivable Account is',
57 ),
58 array(
59 'financial_account' => 'Premiums',
60 'account_relationship' => 'Cost of Sales Account is',
61 ),
62 );
63
64 foreach ($expected as $value => $label) {
65 $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='$label[financial_account]']/../td[1]", preg_quote($label['account_relationship']));
66 }
67 $this->openCiviPage('admin/financial/financialType', 'reset=1', 'newFinancialType');
68 $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$financialType[name]']/../td[3]", 'Accounts Receivable,Banking Fees,Premiums,' . $financialType['name']);
69 $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$financialType[name]']/../td[7]/span/a[text()='Accounts']");
70 $this->waitForElementPresent('newfinancialTypeAccount');
71 $this->click("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Banking Fees']/../td[7]/span/a[text()='Edit']");
72 $this->waitForElementPresent('_qf_FinancialTypeAccount_next');
73 $this->select('account_relationship', "value=select");
74 // Because it tends to cause problems, all uses of sleep() must be justified in comments
75 // Sleep should never be used for wait for anything to load from the server
76 // Justification for this instance: FIXME
77 sleep(1);
78 $this->select('account_relationship', "label=Premiums Inventory Account is");
79 $this->select('financial_account_id', "label=Premiums inventory");
80 $this->click('_qf_FinancialTypeAccount_next');
81 $this->waitForElementPresent("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Premiums inventory']/../td[7]/span/a[text()='Edit']");
82 $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Premiums inventory']/../td[1]", preg_quote('Premiums Inventory Account is'));
83 $this->clickLink("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Premiums inventory']/../td[7]/span/a[text()='Delete']", '_qf_FinancialTypeAccount_next-botttom');
84 $this->click('_qf_FinancialTypeAccount_next-botttom');
85 $this->waitForPageToLoad($this->getTimeoutMsec());
86 $this->waitForText('crm-notification-container', 'Selected financial type account has been deleted.');
87
88 //edit financial type
89 $financialType['oldname'] = $financialType['name'];
90 $financialType['name'] = 'Edited FinancialType '.substr(sha1(rand()), 0, 4);
91 $financialType['is_deductible'] = true;
92 $financialType['is_reserved'] = false;
93 $this->addeditFinancialType($financialType , 'Edit');
94 //delete financialtype
95 $this->addeditFinancialType($financialType , 'Delete');
96 }
97 }