📄 hsptest.php
字号:
<?php// Call HspTest::main() if this source file is executed directly.if (!defined('PHPUnit_MAIN_METHOD')) { define('PHPUnit_MAIN_METHOD', 'HspTest::main');}require_once 'PHPUnit/Framework.php';require_once "testConf.php";require_once ROOT_PATH."/lib/confs/Conf.php";require_once 'Hsp.php';/** * Test class for Hsp. * Generated by PHPUnit on 2008-02-19 at 11:29:52. */class HspTest extends PHPUnit_Framework_TestCase { /** * Runs the test methods of this class. * * @access public * @static */ public static function main() { require_once 'PHPUnit/TextUI/TestRunner.php'; $suite = new PHPUnit_Framework_TestSuite('HspTest'); $result = PHPUnit_TextUI_TestRunner::run($suite); } /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $conf = new Conf(); $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass); mysql_select_db($conf->dbname); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @access protected */ protected function tearDown() { $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`")); $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_employee`")); $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `value` = '0' WHERE `key` = 'hsp_current_plan'")); } public function testUpdateAccrued() { $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_pay_period`")); $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`")); // Here 'check dates' don't mach with pay periods. They have been added to get three past check dates from current day. $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(1, '".date('Y')."-01-01', '".date('Y')."-01-31', '".date('Y')."-01-31', '".date('Y-m-d', time()-3600*24*3)."', '".date('Y')."-01-20')")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(2, '".date('Y')."-02-01', '".date('Y')."-02-29', '".date('Y')."-02-29', '".date('Y-m-d', time()-3600*24*2)."', '".date('Y')."-02-20')")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(3, '".date('Y')."-03-01', '".date('Y')."-03-31', '".date('Y')."-03-31', '".date('Y-m-d', time()-3600*24*1)."', '".date('Y')."-03-20')")); // Summary Insert $this->assertTrue(mysql_query("INSERT INTO hs_hr_hsp_summary VALUES(1, 1, 1, '".date('Y')."', 1, 1500, 50, 50, 0, 0)"), mysql_error()); $this->assertTrue(mysql_query("INSERT INTO hs_hr_hsp_summary VALUES(2, 2, 1, '".date('Y')."', 1, 2500, 75, 75, 0, 0)"), mysql_error()); $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `value` = '".(date('Y')-1)."-12-31' WHERE `key` = 'hsp_accrued_last_updated'")); $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `value` = '1' WHERE `key` = 'hsp_current_plan'")); $result = mysql_query("SELECT COUNT(*) FROM `hs_hr_pay_period` WHERE `check_date` < '".date('Y-m-d')."'"); $resultArray = mysql_fetch_array($result); $expectedAccrued1 = 100*$resultArray[0]; // 100 comes from Summary Insert (50+50) $expectedAccrued2 = 150*$resultArray[0]; Hsp::updateAccrued(date('Y')); // total_accrued is calculated by function and should be equal to $expectedAccrued $result = mysql_query("SELECT `total_accrued` FROM `hs_hr_hsp_summary` WHERE `summary_id` = 1"); $resultArray = mysql_fetch_array($result); $this->assertEquals($resultArray[0], $expectedAccrued1); $result = mysql_query("SELECT `total_accrued` FROM `hs_hr_hsp_summary` WHERE `summary_id` = 2"); $resultArray = mysql_fetch_array($result); $this->assertEquals($resultArray[0], $expectedAccrued2); } public function testUpdateAccruedHalted() { $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_pay_period`")); $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`")); // Here 'check dates' don't mach with pay periods. They have been added to get three past check dates from current day. $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(1, '".date('Y')."-01-01', '".date('Y')."-01-31', '".date('Y')."-01-31', '".date('Y-m-d', time()-3600*24*3)."', '".date('Y')."-01-20')")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(2, '".date('Y')."-02-01', '".date('Y')."-02-29', '".date('Y')."-02-29', '".date('Y-m-d', time()-3600*24*2)."', '".date('Y')."-02-20')")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(3, '".date('Y')."-03-01', '".date('Y')."-03-31', '".date('Y')."-03-31', '".date('Y-m-d', time()-3600*24*1)."', '".date('Y')."-03-20')")); // Summary Insert $this->assertTrue(mysql_query("INSERT INTO hs_hr_hsp_summary VALUES(1, 1, 1, '".date('Y')."', 0, 1500, 50, 50, 823, 0)"), mysql_error()); $this->assertTrue(mysql_query("INSERT INTO hs_hr_hsp_summary VALUES(2, 2, 1, '".date('Y')."', 0, 2500, 75, 75, 0, 0)"), mysql_error()); $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `value` = '".(date('Y')-1)."-12-31' WHERE `key` = 'hsp_accrued_last_updated'")); $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `value` = '1' WHERE `key` = 'hsp_current_plan'")); $result = mysql_query("SELECT COUNT(*) FROM `hs_hr_pay_period` WHERE `check_date` < '".date('Y-m-d')."'"); $resultArray = mysql_fetch_array($result); // Since `hsp_plan_status` is 0 no accrued should happen $expectedAccrued1 = 823; $expectedAccrued2 = 0; Hsp::updateAccrued(date('Y')); // total_accrued is calculated by function and should be equal to $expectedAccrued $result = mysql_query("SELECT `total_accrued` FROM `hs_hr_hsp_summary` WHERE `summary_id` = 1"); $resultArray = mysql_fetch_array($result); $this->assertEquals($expectedAccrued1, $resultArray[0]); $result = mysql_query("SELECT `total_accrued` FROM `hs_hr_hsp_summary` WHERE `summary_id` = 2"); $resultArray = mysql_fetch_array($result); $this->assertEquals($expectedAccrued2, $resultArray[0]); } public function testUpdateAccruedForTwoPlans() { $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_pay_period`")); $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`")); // Here 'check dates' don't mach with pay periods. They have been added to get three past check dates from current day. $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(1, '".date('Y')."-01-01', '".date('Y')."-01-31', '".date('Y')."-01-31', '".date('Y-m-d', time()-3600*24*3)."', '".date('Y')."-01-20')")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(2, '".date('Y')."-02-01', '".date('Y')."-02-29', '".date('Y')."-02-29', '".date('Y-m-d', time()-3600*24*2)."', '".date('Y')."-02-20')")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(3, '".date('Y')."-03-01', '".date('Y')."-03-31', '".date('Y')."-03-31', '".date('Y-m-d', time()-3600*24*1)."', '".date('Y')."-03-20')")); // Summary Insert $this->assertTrue(mysql_query("INSERT INTO hs_hr_hsp_summary VALUES(1, 1, 1, '".date('Y')."', 1, 1500, 50, 50, 0, 0)"), mysql_error()); $this->assertTrue(mysql_query("INSERT INTO hs_hr_hsp_summary VALUES(2, 1, 3, '".date('Y')."', 1, 2500, 75, 75, 0, 0)"), mysql_error()); $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `value` = '".(date('Y')-1)."-12-31' WHERE `key` = 'hsp_accrued_last_updated'")); $result = mysql_query("SELECT COUNT(*) FROM `hs_hr_pay_period` WHERE `check_date` < '".date('Y-m-d')."'"); $resultArray = mysql_fetch_array($result); $expectedAccrued1 = 100*$resultArray[0]; // 100 comes from Summary Insert (50+50) $expectedAccrued2 = 150*$resultArray[0]; $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `value` = '4' WHERE `key` = 'hsp_current_plan'")); Hsp::updateAccrued(date('Y')); // total_accrued is calculated by function and should be equal to $expectedAccrued $result = mysql_query("SELECT `total_accrued` FROM `hs_hr_hsp_summary` WHERE `summary_id` = 1"); $resultArray = mysql_fetch_array($result); $this->assertEquals($expectedAccrued1, $resultArray[0]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -