orangehrm /lib/models/leave/LeaveTypeTest.php

Language PHP Lines 259
MD5 Hash f5022c08124206a7e38fa010e220a722 Estimated Cost $3,018 (why?)
Repository https://bitbucket.org/wildanm/orangehrm View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?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 LeaveTypeTest::main() if this source file is executed directly.
if (!defined("PHPUnit_MAIN_METHOD")) {
    define("PHPUnit_MAIN_METHOD", "LeaveTypeTest::main");
}

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

require_once "testConf.php";

$_SESSION['WPATH'] = WPATH;

require_once "LeaveType.php";
require_once ROOT_PATH."/lib/confs/Conf.php";
require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';

/**
 * Test class for LeaveType.
 * Generated by PHPUnit_Util_Skeleton on 2006-10-18 at 10:36:24.
 */
class LeaveTypeTest extends PHPUnit_Framework_TestCase {
    /**
     * Runs the test methods of this class.
     *
     * @access public
     * @static
     */

    public $classLeaveType = null;
    public $connection = null;

    public static function main() {
        require_once "PHPUnit/TextUI/TestRunner.php";

        $suite  = new PHPUnit_Framework_TestSuite("LeaveTypeTest");
        $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->classLeaveType = new LeaveType();

    	$conf = new Conf();

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

        mysql_select_db($conf->dbname);

        mysql_query("TRUNCATE TABLE `hs_hr_leavetype`");
        mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY011', 'Medical', 1)");
        mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY012', 'Medicals', 1)");
        mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY013', 'Medicalx', 1)");

        mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY014', 'Casual', 1)");
        mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY015', 'Casual', 1)");
        mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY016', 'Casual', 1)");


        
        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_leavetype` WHERE `Leave_Type_ID` = 'LTY011'", $this->connection);
    	 mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY012'", $this->connection);
    	 mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY013'", $this->connection);
    	 
         mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY014'", $this->connection);
         mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY015'", $this->connection);
         mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY016'", $this->connection);

    }

   public function testAddLeaveType() {

    	$this->classLeaveType->setLeaveTypeName("Anual");

    	$res = $this->classLeaveType->addLeaveType();
    	$id = $this->classLeaveType->getLeaveTypeId();

    	$res = $this->classLeaveType->retriveLeaveType($id);
		$this->assertNotNull($res);

        $expected = array($id, 'Anual');

        $this->assertEquals($res[0]->getLeaveTypeId(), $expected[0], "Didn't return expected result 1");
        $this->assertEquals($res[0]->getLeaveTypeName(), $expected[1], "Didn't return expected result 2");



        $this->assertEquals(count($res), 1, "Number of records found is not accurate ");

   }

   public function testRetriveLeaveType() {

        $res = $this->classLeaveType->retriveLeaveType("LTY017");

        $this->assertEquals($res, null, "Retured non exsistant record ");
   }



   public function testRetriveLeaveAccuracy() {

        $res = $this->classLeaveType->retriveLeaveType("LTY011");

        $expected[0] = array('Anual', 'LTY011');


        $this->assertNotNull($res, "No record found ");



   }


   public function testEditLeavetype () {

   		$this->classLeaveType->setLeaveTypeName("New Medicals");
   		$this->classLeaveType->setLeaveTypeId("LTY012");
   		$res = $this->classLeaveType->editLeaveType();

   		$res = $this->classLeaveType->retriveLeaveType("LTY012");

   		$expected = array('LTY012', 'New Medicals');

        $this->assertEquals($res[0]->getLeaveTypeId(), $expected[0], "Didn't return expected result 1");
        $this->assertEquals($res[0]->getLeaveTypeName(), $expected[1], "Didn't return expected result 2");


        $this->assertNotNull($res, "No record found ");

   }


   public function testDeleteLeaveType () {

   		$this ->classLeaveType->setLeaveTypeId("LTY012");

   		$res = $this->classLeaveType->deleteLeaveType("LTY012");

   		$res = $this->classLeaveType->retriveLeaveType("LTY012");


        $expected = array('LTY012', 'Medicals' , $res[0]->unAvailableStatusFlag);

        $this->assertEquals($res[0]->getLeaveTypeId(), $expected[0], "Didn't return expected result 1");
        $this->assertEquals($res[0]->getLeaveTypeName(), $expected[1], "Didn't return expected result 2");


        $this->assertNotNull($res, "No record found ");
   }

   public function testFetchLeave() {
        $res = $this->classLeaveType->fetchLeaveTypes();

        $this->assertNotNull($res, "No record found ");
    }


    public function testFetchLeaveAccuracy() {

        $res = $this->classLeaveType->fetchLeaveTypes();

        $expected[] = array("LTY014", "Casual");
        $expected[] = array("LTY015", "Casual");
        $expected[] = array("LTY016", "Casual");
        $expected[] = array("LTY011", "Medical");
        $expected[] = array("LTY012", "Medicals");
        $expected[] = array("LTY013", "Medicalx");

        for ($i=0; $i < count($res); $i++) {
        	$this->assertEquals($expected[$i][0], $res[$i]->getLeaveTypeId(), "Didn't return expected result 1");
        	$this->assertEquals($expected[$i][1], $res[$i]->getLeaveTypeName(), "Didn't return expected result 2");
        }
    }

    public function testGetLeaveTypeWithName() {

    	// Undeleted leave types
    	$typeList = $this->classLeaveType->getLeaveTypeWithName("Medical");
    	$this->assertNotNull($typeList);
		$this->assertEquals(1, count($typeList));
		$type = $typeList[0];

    	$this->assertEquals("LTY011", $type->getLeaveTypeId());
    	$this->assertEquals(1, $type->getLeaveTypeAvailable());

    	// Deleted leave types
    	$this->assertTrue(mysql_query("UPDATE `hs_hr_leavetype` SET available_flag = 0 WHERE leave_type_id='LTY011'"));

    	$typeList = $this->classLeaveType->getLeaveTypeWithName("Medical");
    	$this->assertNull($typeList);

    	$typeList = $this->classLeaveType->getLeaveTypeWithName("Medical", true);
    	$this->assertNotNull($typeList);
		$this->assertEquals(1, count($typeList));
		$type = $typeList[0];

    	$this->assertEquals("LTY011", $type->getLeaveTypeId());
    	$this->assertEquals(0, $type->getLeaveTypeAvailable());

		// Unavailable leave type name
    	$typeList = $this->classLeaveType->getLeaveTypeWithName("Annual");
    	$this->assertNull($typeList);

                //Chek for same leave type error, checks if its returning only one record
        $typeList = $this->classLeaveType->getLeaveTypeWithName("Casual");
        $this->assertEquals(1, count($typeList));

        // test if the most recent levetype is selected
        $myres=mysql_query("SELECT * FROM `hs_hr_leavetype` WHERE `leave_type_name` = 'Casual' ORDER BY `leave_type_id` DESC LIMIT 0,1", $this->connection);
        $myarr=mysql_fetch_array($myres);
        $this->assertEquals('LTY016',$myarr[0]);

    }

}

// Call LeaveTypeTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "LeaveTypeTest::main") {
    LeaveTypeTest::main();
}
?>
Back to Top