⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leaverequeststest.php

📁 国外的人才求职招聘最新版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
/**
 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
 * all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA
 *
 */


// Call LeaveRequestTest::main() if this source file is executed directly.
if (!defined("PHPUnit_MAIN_METHOD")) {
    define("PHPUnit_MAIN_METHOD", "LeaveRequestTest::main");
}

require_once "PHPUnit/Framework/TestCase.php";
require_once "PHPUnit/Framework/TestSuite.php";

require_once "testConf.php";

$_SESSION['WPATH'] = WPATH;

require_once 'LeaveRequests.php';
require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';

/**
 * Test class for LeaveRequest.
 * Generated by PHPUnit_Util_Skeleton on 2006-12-28 at 05:15:40.
 */
class LeaveRequestsTest extends PHPUnit_Framework_TestCase {

	public $classLeaveRequest = null;
    public $connection = null;

	/**
     * 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("LeaveRequestsTest");
        $result = PHPUnit_TextUI_TestRunner::run($suite);
    }

    /**
     * Sets up the fixture, for example, open a network connection.
     * This method is called before a test is executed.
     *
     * @access protected
     */
    protected function setUp() {
    	$this->classLeaveRequest = new LeaveRequests();

    	$conf = new Conf();

    	$this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);

        mysql_select_db($conf->dbname);

		mysql_query("INSERT INTO `hs_hr_employee` VALUES ('011', NULL, 'Arnold', 'Subasinghe', '', 'Arnold', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', 'AF', '', '', '', '', '', '', NULL, '0000-00-00', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
		mysql_query("INSERT INTO `hs_hr_employee` VALUES ('012', NULL, 'Mohanjith', 'Sudirikku', 'Hannadige', 'MOHA', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, '0000-00-00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
		mysql_query("INSERT INTO `hs_hr_employee` VALUES ('013', NULL, 'MohanjithX', 'SudirikkuX', 'HannadigeX', 'MOHAX', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, '0000-00-00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
		mysql_query("INSERT INTO `hs_hr_employee` VALUES ('014', NULL, 'Mohanjith1', 'Sudirikku1', 'Hannadige1', 'MOHA1', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, '0000-00-00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
		mysql_query("INSERT INTO `hs_hr_employee` VALUES ('015', NULL, 'Jack', 'Bauer', '', 'John', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', 'AF', '', '', '', '', '', '', NULL, '0000-00-00', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");

		mysql_query("INSERT INTO `hs_hr_emp_reportto` VALUES ('012', '011', 1);");

		mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY010', 'Medical', 1)");

		mysql_query("TRUNCATE TABLE `hs_hr_weekends`;");
		$this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (1, 0);"), mysql_error());
		$this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (2, 0);"), mysql_error());
		$this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (3, 0);"), mysql_error());
		$this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (4, 0);"), mysql_error());
		$this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (5, 0);"), mysql_error());
		$this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (6, 0);"), mysql_error());
		$this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (7, 0);"), mysql_error());

		//Leave 1
		mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (10, 'LTY010', 'Medical', '".date('Y-m-d', time()+3600*24)."', '011')");
		mysql_query("INSERT INTO `hs_hr_leave` (`leave_request_id`, `leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_days`, `leave_length_hours`, `leave_status`, `leave_comments`) VALUES (10, 10, '011', 'LTY010', '".date('Y-m-d', time()+3600*24)."', 0.12, 1, 1, 'Leave 1')");

		//Leave 2
		mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (11, 'LTY010', 'Hospital', '".date('Y-m-d', time()+3600*24)."', '011')");
		mysql_query("INSERT INTO `hs_hr_leave` (`leave_request_id`, `leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_days`, `leave_length_hours`, `leave_status`, `leave_comments`) VALUES (11, 11, '011', 'LTY010', '".date('Y-m-d', time()+3600*24)."', 0.12, 1, 1, 'Leave 2-1')");
		mysql_query("INSERT INTO `hs_hr_leave` (`leave_request_id`, `leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_days`, `leave_length_hours`, `leave_status`, `leave_comments`) VALUES (11, 13, '011', 'LTY010', '".date('Y-m-d', time()+3600*24*2)."', 0.12, 1, 1, 'Leave 2-2')");

		mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (12, 'LTY010', 'Hospital', '".date('Y-m-d', time()+3600*24)."', '015')");

        UniqueIDGenerator::getInstance()->initTable();
    }

    /**
     * Tears down the fixture, for example, close a network connection.
     * This method is called after a test is executed.
     *
     * @access protected
     */
    protected function tearDown() {
    	mysql_query("DELETE FROM `hs_hr_emp_reportto` WHERE `erep_sup_emp_number` = '012' AND `erep_sub_emp_number` = '011'", $this->connection);

    	mysql_query("TRUNCATE TABLE `hs_hr_leave`");
    	mysql_query("TRUNCATE TABLE `hs_hr_leave_requests`");
    	mysql_query("TRUNCATE TABLE `hs_hr_weekends`;");

    	mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY010'");

    	mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '011'");
    	mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '012'");
    	mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '013'");
    	mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '014'");
    	mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '015'");
    }

    public function testRetriveLeaveRequestsEmployee1() {
    	$leaveObj = $this->classLeaveRequest;

    	$res = $leaveObj->retriveLeaveRequestsEmployee('051');

    	$this->assertNull($res, 'Non exsistent record found');
    }

    public function testRetriveLeaveRequestsEmployee2() {
    	$leaveObj = $this->classLeaveRequest;
    	$employeeId = '011';

    	$res = $leaveObj->retriveLeaveRequestsEmployee($employeeId);

    	$this->assertNotNull($res, 'Record not found');

    	$this->assertSame(2, count($res), 'Wrong number of records found');

    	$expected[0] = array('10', 'Medical', date('Y-m-d', time()+3600*24), null);
    	$expected[1] = array('11', 'Hospital', date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*2));

    	for ($i=0; $i<count($res); $i++) {
    		$this->assertSame($expected[$i][0], $res[$i]->getLeaveRequestId(), 'Wrong Leave Request Id');
    		$this->assertSame($expected[$i][1], $res[$i]->getLeaveTypeName(), 'Wrong Leave Type Name');
    		$this->assertSame($expected[$i][2], $res[$i]->getLeaveFromDate(), 'Wrong From Date');
    		$this->assertSame($expected[$i][3], $res[$i]->getLeaveToDate(), 'Wrong To Date');
    	}
    }

    public function testRetriveLeaveRequestsSupervisor1() {
    	$leaveObj = $this->classLeaveRequest;

    	$res = $leaveObj->retriveLeaveRequestsSupervisor('051');

    	$this->assertNull($res, 'Non exsistent record found');
    }

    public function testRetriveLeaveRequestsSupervisor2() {
    	$leaveObj = $this->classLeaveRequest;
    	$employeeId = '012';

    	$res = $leaveObj->retriveLeaveRequestsSupervisor($employeeId);

    	$this->assertNotNull($res, 'Record not found');

    	$this->assertSame(2, count($res), 'Wrong number of records found');

    	$expected[0] = array('10', 'Medical', date('Y-m-d', time()+3600*24), null);
    	$expected[1] = array('11', 'Hospital', date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*2));

    	for ($i=0; $i<count($res); $i++) {
    		$this->assertSame($expected[$i][0], $res[$i]->getLeaveRequestId(), 'Wrong Leave Request Id');
    		$this->assertSame($expected[$i][1], $res[$i]->getLeaveTypeName(), 'Wrong Leave Type Name');
    		$this->assertSame($expected[$i][2], $res[$i]->getLeaveFromDate(), 'Wrong From Date');
    		$this->assertSame($expected[$i][3], $res[$i]->getLeaveToDate(), 'Wrong To Date');
    	}
    }

    /**
     * Tests that retrieveLeaveRequestsSupervisor only retrieves leave requests with the
     * statuses: Pending approval, approved and rejected
     */
    public function testRetriveLeaveRequestsSupervisorStatuses() {
    	$leaveObj = $this->classLeaveRequest;
    	$supervisorId = '012';

		// Change status to Pending approval
		$this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL." WHERE leave_request_id = 10"), mysql_error());
		$this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL." WHERE leave_request_id = 11"), mysql_error());
    	$res = $leaveObj->retriveLeaveRequestsSupervisor($supervisorId);

    	$this->assertNotNull($res, 'Record not found');
    	$this->assertSame(2, count($res), 'Wrong number of records found');

		// Change status to Rejected
		$this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_REJECTED." WHERE leave_request_id = 10"), mysql_error());
		$this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_REJECTED." WHERE leave_request_id = 11"), mysql_error());
    	$res = $leaveObj->retriveLeaveRequestsSupervisor($supervisorId);

    	$this->assertNotNull($res, 'Record not found');
    	$this->assertSame(2, count($res), 'Wrong number of records found');

		// Change status to Approved
		$this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_APPROVED." WHERE leave_request_id = 10"), mysql_error());
		$this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_APPROVED." WHERE leave_request_id = 11"), mysql_error());
    	$res = $leaveObj->retriveLeaveRequestsSupervisor($supervisorId);

    	$this->assertNotNull($res, 'Record not found');
    	$this->assertSame(2, count($res), 'Wrong number of records found');

		// Change one leave request's status to 'Status Differ'11, 13
		$this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_APPROVED." WHERE leave_id = 11"), mysql_error());
		$this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_REJECTED." WHERE leave_id = 13"), mysql_error());
    	$res = $leaveObj->retriveLeaveRequestsSupervisor($supervisorId);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -