orangehrm /lib/models/eimadmin/ProjectsTest.php

Language PHP Lines 279
MD5 Hash 4eba41fe84a095ec9b4212a216d9fac8 Estimated Cost $3,867 (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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?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 ProjectTest::main() if this source file is executed directly.
if (!defined("PHPUnit_MAIN_METHOD")) {
    define("PHPUnit_MAIN_METHOD", "ProjectTest::main");
}

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

require_once "testConf.php";

$_SESSION['WPATH'] = WPATH;

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

/**
 * Test class for Project.
 * Generated by PHPUnit_Util_Skeleton on 2007-03-22 at 15:43:08.
 */
class ProjectTest extends PHPUnit_Framework_TestCase {
    /**
     * Runs the test methods of this class.
     *
     * @access public
     * @static
     */

    public $classProject = null;
    public $connection = null;

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

        $suite  = new PHPUnit_Framework_TestSuite("ProjectTest");
        $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->classProject = new Projects();

    	$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_project`", $this->connection);

        mysql_query("INSERT INTO `hs_hr_customer` VALUES ('1001','zanfer1','forrw',0 )");
        mysql_query("INSERT INTO `hs_hr_customer` VALUES ('1002','zanfer2','forrw',0 )");
        mysql_query("INSERT INTO `hs_hr_customer` VALUES ('1003','zanfer3','forrw',0 )");

        mysql_query("INSERT INTO `hs_hr_project` VALUES ('1001','1001','p1','w',0 )");
        mysql_query("INSERT INTO `hs_hr_project` VALUES ('1002','1002','p2','w',0 )");
        mysql_query("INSERT INTO `hs_hr_project` VALUES ('1003','1003','p3','w',0 )");
		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("TRUNCATE TABLE `hs_hr_project`", $this->connection);

		mysql_query("DELETE FROM `hs_hr_customer` WHERE `customer_id` IN (1001, 1002, 1003);", $this->connection);
		UniqueIDGenerator::getInstance()->initTable();
    }

    public function testFetchProject() {

    	$res  = $this->classProject->fetchProject("1001");

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

    	$this->assertEquals($res->getProjectId(),'1001','Invalid project id');
	   	$this->assertEquals($res->getCustomerId(),'1001','Invalid customer id');
	   	$this->assertEquals($res->getProjectName(),'p1','Invalid description');
	   	$this->assertEquals($res->getProjectDescription(),'w','Invalid description');
	   	$this->assertEquals($res->getDeleted(), Projects::PROJECT_NOT_DELETED,'Invalid description');
    }

    public function testAddProject() {

    	$this->classProject->setCustomerId("1003");
    	$this->classProject->setProjectName("Dodle");
    	$this->classProject->setProjectDescription("jhgjhg");

    	$res  = $this->classProject->addProject();
    	$id = $this->classProject->getProjectId();
    	$this->assertTrue($res, "Adding failed");

    	$res  = $this->classProject->fetchProject($id);
	    $this->assertNotNull($res, "No record found");

	   	$this->assertEquals($res->getProjectId(), $id,'Invalid project id');
	   	$this->assertEquals($res->getCustomerId(),'1003','Invalid customer id');
	   	$this->assertEquals($res->getProjectName(),'Dodle','Invalid description');
	   	$this->assertEquals($res->getProjectDescription(),'jhgjhg','Invalid description');
	   	$this->assertEquals($res->getDeleted(), Projects::PROJECT_NOT_DELETED,'Invalid description');
    }

	public function testFetchProjects() {

      	$res = $this->classProject->fetchProjects();
      	$this->assertNotNull($res, "record Not found");

      	$this->assertEquals(count($res), 3,'count incorrect');

      	$expected[0] = array('1001', '1001', 'p1', 'w', Projects::PROJECT_NOT_DELETED);
      	$expected[1] = array('1002', '1002', 'p2', 'w', Projects::PROJECT_NOT_DELETED);
      	$expected[2] = array('1003', '1003', 'p3', 'w', Projects::PROJECT_NOT_DELETED);

      	$i= 0;

		for ($i=0; $i<count($res); $i++) {

			$this->assertEquals($expected[$i][0], $res[$i]->getProjectId(), 'Wrong Project Request Id');
			$this->assertEquals($expected[$i][1], $res[$i]->getCustomerId(), 'Wrong Cus Id ');
			$this->assertEquals($expected[$i][2], $res[$i]->getProjectName(), 'Wrong Project Name ');
			$this->assertEquals($expected[$i][3], $res[$i]->getProjectDescription(),'Wrong Project Description ');
			$this->assertEquals($expected[$i][4], $res[$i]->getDeleted(),'Invalid description');
      	}

      	// Delete one project
      	mysql_query("UPDATE `hs_hr_project` SET deleted = 1 WHERE project_id = 1001");

      	// By default, all projects are returned
      	$res = $this->classProject->fetchProjects();
      	$this->assertNotNull($res, "record Not found");
      	$this->assertEquals(count($res), 3,'count incorrect');

      	// Fetch only NOT DELETED projects
      	$res = $this->classProject->setDeleted(Projects::PROJECT_NOT_DELETED);
      	$res = $this->classProject->fetchProjects();
      	$this->assertNotNull($res, "record Not found");
      	$this->assertEquals(count($res), 2,'count incorrect');

	}

	public function testGetListOfProjects() {

      	$res = $this->classProject->fetchProjects();
      	$this->assertNotNull($res, "record Not found");

      	$this->assertEquals(count($res), 3,'count incorrect');

      	$expected[0] = array('1001', '1001', 'p1', 'w', Projects::PROJECT_NOT_DELETED);
      	$expected[1] = array('1002', '1002', 'p2', 'w', Projects::PROJECT_NOT_DELETED);
      	$expected[2] = array('1003', '1003', 'p3', 'w', Projects::PROJECT_NOT_DELETED);

      	$i= 0;

		for ($i=0; $i<count($res); $i++) {

			$this->assertEquals($expected[$i][0], $res[$i]->getProjectId(), 'Wrong Project Request Id');
			$this->assertEquals($expected[$i][1], $res[$i]->getCustomerId(), 'Wrong Cus Id ');
			$this->assertEquals($expected[$i][2], $res[$i]->getProjectName(), 'Wrong Project Name ');
			$this->assertEquals($expected[$i][3], $res[$i]->getProjectDescription(),'Wrong Project Description ');
			$this->assertEquals($expected[$i][4], $res[$i]->getDeleted(),'Invalid description');
      	}
	}

	public function testUpdateProject() {
    	$res = $this->classProject->fetchProject("1001");

    	$res->setCustomerId('1002');

    	$res = $res->updateProject();

    	$this->assertTrue($res, "Adding failed");

    	$res = $this->classProject->fetchProject("1001");
    	$this->assertNotNull($res, "No record found");

    	$this->assertEquals($res->getProjectId(),'1001','Invalid project id');
	   	$this->assertEquals($res->getCustomerId(),'1002','Invalid customer id');
	   	$this->assertEquals($res->getProjectName(),'p1','Invalid description');
	   	$this->assertEquals($res->getProjectDescription(),'w','Invalid description');
	   	$this->assertEquals($res->getDeleted(), Projects::PROJECT_NOT_DELETED,'Invalid description');
	}

	public function testUpdateProject2() {
    	$res = $this->classProject->fetchProject("1001");

		$res->setCustomerId('1002');
    	$res->setProjectName('px');
    	$res->setProjectDescription('ogg');

    	$res = $res->updateProject();

    	$this->assertTrue($res, "Adding failed");

    	$res = $this->classProject->fetchProject("1001");
    	$this->assertNotNull($res, "No record found");

    	$this->assertEquals($res->getProjectId(),'1001','Invalid project id');
	   	$this->assertEquals($res->getCustomerId(),'1002','Invalid customer id');
	   	$this->assertEquals($res->getProjectName(),'px','Invalid description');
	   	$this->assertEquals($res->getProjectDescription(),'ogg','Invalid description');
	   	$this->assertEquals($res->getDeleted(), Projects::PROJECT_NOT_DELETED,'Invalid description');
	}

	public function testDeleteProject() {
		$this->classProject->setProjectId("1001");

		$res = $this->classProject->deleteProject();

		$this->assertTrue($res, "Adding failed");

    	$res = $this->classProject->fetchProject("1001");
    	$this->assertNotNull($res, "No record found");

    	$this->assertEquals($res->getProjectId(),'1001','Invalid project id');
	   	$this->assertEquals($res->getCustomerId(),'1001','Invalid customer id');
	   	$this->assertEquals($res->getProjectName(),'p1','Invalid description');
	   	$this->assertEquals($res->getProjectDescription(),'w','Invalid description');
	   	$this->assertEquals($res->getDeleted(), Projects::PROJECT_DELETED,'Invalid description');
	}
	
	public function testRetrieveProjectName() {
		
		$actual = $this->classProject->retrieveProjectName(1001);
		$this->assertEquals('p1', $actual);
		
		$actual = $this->classProject->retrieveProjectName(1009);
		$this->assertEquals('', $actual);
				
	}
	
	public function testRetrieveCustomerName() {
		
		$actual = $this->classProject->retrieveCustomerName(1001);
		$this->assertEquals('zanfer1', $actual);
		
		$actual = $this->classProject->retrieveCustomerName(1009);
		$this->assertEquals('', $actual);

	}

}

// Call ProjectTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "ProjectTest::main") {
    ProjectTest::main();
}

?>
Back to Top