PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/models/hrfunct/EmpTaxTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 142 lines | 87 code | 21 blank | 34 comment | 3 complexity | 0a4bb595a41003be1c2126f13d4d5c47 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, AGPL-3.0, BSD-3-Clause, AGPL-1.0, GPL-2.0, LGPL-2.1, LGPL-3.0
  1. <?php
  2. // Call EmpTaxTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "EmpTaxTest::main");
  5. }
  6. require_once "PHPUnit/Framework/TestCase.php";
  7. require_once "PHPUnit/Framework/TestSuite.php";
  8. require_once "testConf.php";
  9. require_once ROOT_PATH . '/lib/confs/Conf.php';
  10. require_once ROOT_PATH . '/lib/dao/DMLFunctions.php';
  11. require_once ROOT_PATH . '/lib/dao/SQLQBuilder.php';
  12. require_once ROOT_PATH . '/lib/common/CommonFunctions.php';
  13. require_once 'EmpTax.php';
  14. /**
  15. * Test class for EmpTax.
  16. * Generated by PHPUnit_Util_Skeleton on 2007-12-04 at 19:56:17.
  17. */
  18. class EmpTaxTest extends PHPUnit_Framework_TestCase {
  19. /**
  20. * Runs the test methods of this class.
  21. *
  22. * @access public
  23. * @static
  24. */
  25. public static function main() {
  26. require_once "PHPUnit/TextUI/TestRunner.php";
  27. $suite = new PHPUnit_Framework_TestSuite("EmpTaxTest");
  28. $result = PHPUnit_TextUI_TestRunner::run($suite);
  29. }
  30. /**
  31. * Sets up the fixture, for example, open a network connection.
  32. * This method is called before a test is executed.
  33. *
  34. * @access protected
  35. */
  36. protected function setUp() {
  37. $conf = new Conf();
  38. mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  39. mysql_select_db($conf->dbname);
  40. $this->_deleteTables();
  41. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_nick_name) " .
  42. "VALUES (11, 'Arnold', 'Subasinghe', 'Arnold')");
  43. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_nick_name) " .
  44. "VALUES (10, 'John', 'Subasinghe', 'Arnold')");
  45. $this->_runQuery("INSERT INTO hs_hr_emp_us_tax(emp_number, tax_federal_status, tax_federal_exceptions, tax_state_status, tax_state_exceptions, " .
  46. "tax_state, tax_unemp_state, tax_work_state) VALUES(11, 'M', 1, 'NA', 2, 'TX', 'NY', 'CA')");
  47. }
  48. /**
  49. * Tears down the fixture, for example, close a network connection.
  50. * This method is called after a test is executed.
  51. *
  52. * @access protected
  53. */
  54. protected function tearDown() {
  55. $this->_deleteTables();
  56. }
  57. private function _deleteTables() {
  58. $this->_runQuery("TRUNCATE hs_hr_emp_us_tax");
  59. $this->_runQuery("DELETE FROM hs_hr_employee WHERE `emp_number` IN (10, 11, 101)");
  60. }
  61. private function _runQuery($sql) {
  62. $this->assertTrue(mysql_query($sql), mysql_error());
  63. }
  64. /**
  65. * @todo Implement testGetEmployeeTaxInfo().
  66. */
  67. public function testGetEmployeeTaxInfo() {
  68. $empTaxObj = new EmpTax();
  69. // Employee without tax info
  70. $expected = array(EmpTax::EMP_TAX_TABLE_EMP_NUMBER=>10, EmpTax::EMP_TAX_FEDERAL_STATUS => null,
  71. EmpTax::EMP_TAX_FEDERAL_EXCEPTIONS => null, EmpTax::EMP_TAX_STATE => null,
  72. EmpTax::EMP_TAX_STATE_STATUS => null, EmpTax::EMP_TAX_STATE_EXCEPTIONS => null,
  73. EmpTax::EMP_TAX_UNEMP_STATE => null, EmpTax::EMP_TAX_WORK_STATE => null);
  74. $empTaxInfo = $empTaxObj->getEmployeeTaxInfo(10);
  75. $this->assertEquals($expected, $empTaxInfo);
  76. // Employee with tax info
  77. $expected = array(EmpTax::EMP_TAX_TABLE_EMP_NUMBER=>11, EmpTax::EMP_TAX_FEDERAL_STATUS => 'M',
  78. EmpTax::EMP_TAX_FEDERAL_EXCEPTIONS => 1, EmpTax::EMP_TAX_STATE => 'TX',
  79. EmpTax::EMP_TAX_STATE_STATUS => 'NA', EmpTax::EMP_TAX_STATE_EXCEPTIONS => 2,
  80. EmpTax::EMP_TAX_UNEMP_STATE => 'NY', EmpTax::EMP_TAX_WORK_STATE => 'CA');
  81. $empTaxInfo = $empTaxObj->getEmployeeTaxInfo(11);
  82. $this->assertEquals($expected, $empTaxInfo);
  83. }
  84. /**
  85. * @todo Implement testUpdateEmpTax().
  86. */
  87. public function testUpdateEmpTax() {
  88. $taxInfo = new EmpTax();
  89. $taxInfo->setFederalTaxStatus('S');
  90. $taxInfo->setFederalTaxExceptions(5);
  91. $taxInfo->setTaxState('NM');
  92. $taxInfo->setStateTaxStatus('NRA');
  93. $taxInfo->setStateTaxExceptions(6);
  94. $taxInfo->setTaxUnemploymentState('NJ');
  95. $taxInfo->setTaxWorkState('SC');
  96. $empTaxObj = new EmpTax();
  97. // Employee with no existing tax info
  98. $taxInfo->setEmpNumber(10);
  99. $taxInfo->updateEmpTax();
  100. $empTax1 = $empTaxObj->getEmployeeTaxInfo(10);
  101. $expected = array(EmpTax::EMP_TAX_TABLE_EMP_NUMBER=>10, EmpTax::EMP_TAX_FEDERAL_STATUS => 'S',
  102. EmpTax::EMP_TAX_FEDERAL_EXCEPTIONS => 5, EmpTax::EMP_TAX_STATE => 'NM',
  103. EmpTax::EMP_TAX_STATE_STATUS => 'NRA', EmpTax::EMP_TAX_STATE_EXCEPTIONS => 6,
  104. EmpTax::EMP_TAX_UNEMP_STATE => 'NJ', EmpTax::EMP_TAX_WORK_STATE => 'SC');
  105. $this->assertEquals($expected, $empTax1);
  106. // Employee with tax information
  107. $taxInfo->setEmpNumber(11);
  108. $taxInfo->updateEmpTax();
  109. $empTax2 = $empTaxObj->getEmployeeTaxInfo(11);
  110. $expected = array(EmpTax::EMP_TAX_TABLE_EMP_NUMBER=>11, EmpTax::EMP_TAX_FEDERAL_STATUS => 'S',
  111. EmpTax::EMP_TAX_FEDERAL_EXCEPTIONS => 5, EmpTax::EMP_TAX_STATE => 'NM',
  112. EmpTax::EMP_TAX_STATE_STATUS => 'NRA', EmpTax::EMP_TAX_STATE_EXCEPTIONS => 6,
  113. EmpTax::EMP_TAX_UNEMP_STATE => 'NJ', EmpTax::EMP_TAX_WORK_STATE => 'SC');
  114. $this->assertEquals($expected, $empTax2);
  115. }
  116. }
  117. // Call EmpTaxTest::main() if this source file is executed directly.
  118. if (PHPUnit_MAIN_METHOD == "EmpTaxTest::main") {
  119. EmpTaxTest::main();
  120. }
  121. ?>