PageRenderTime 60ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/models/time/TimesheetTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 495 lines | 310 code | 137 blank | 48 comment | 11 complexity | 14d24b15e5504ac9857be3f66a9b41e1 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. /**
  3. * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
  4. * all the essential functionalities required for any enterprise.
  5. * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
  6. *
  7. * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
  8. * the GNU General Public License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  12. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program;
  16. * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA
  18. *
  19. */
  20. // Call TimeSheetTest::main() if this source file is executed directly.
  21. if (!defined("PHPUnit_MAIN_METHOD")) {
  22. define("PHPUnit_MAIN_METHOD", "TimesheetTest::main");
  23. }
  24. require_once "PHPUnit/Framework/TestCase.php";
  25. require_once "PHPUnit/Framework/TestSuite.php";
  26. require_once 'testConf.php';
  27. require_once 'Timesheet.php';
  28. require_once ROOT_PATH."/lib/common/UniqueIDGenerator.php";
  29. /**
  30. * Test class for Timesheet.
  31. * Generated by PHPUnit_Util_Skeleton on 2007-03-22 at 12:56:54.
  32. */
  33. class TimesheetTest extends PHPUnit_Framework_TestCase {
  34. public $classTimesheet = null;
  35. public $connection = null;
  36. /**
  37. * Runs the test methods of this class.
  38. *
  39. * @access public
  40. * @static
  41. */
  42. public static function main() {
  43. require_once "PHPUnit/TextUI/TestRunner.php";
  44. $suite = new PHPUnit_Framework_TestSuite("TimesheetTest");
  45. $result = PHPUnit_TextUI_TestRunner::run($suite);
  46. }
  47. /**
  48. * Sets up the fixture, for example, open a network connection.
  49. * This method is called before a test is executed.
  50. *
  51. * @access protected
  52. */
  53. protected function setUp() {
  54. $this->classTimesheet = new Timesheet();
  55. $conf = new Conf();
  56. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  57. $this->assertTrue($this->connection !== false);
  58. $this->assertTrue(mysql_select_db($conf->dbname));
  59. $this->_deleteTestData();
  60. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_nick_name, coun_code) VALUES ('010', 'Arnold', 'Subasinghe', 'Arnold', 'AF')");
  61. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_customer` (`customer_id`, `name`, `description`, `deleted`) ".
  62. "VALUES (10, 'OrangeHRM', 'Implement OrangeHRM', 0)"));
  63. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_project` (`project_id`, `customer_id`, `name`, `description`, `deleted`) ".
  64. "VALUES (10, 10, 'OrangeHRM', 'Implement OrangeHRM', 0)"));
  65. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_timesheet_submission_period` (`timesheet_period_id`, `name`, `frequency`, `period`, `start_day`, `end_day`, `description`) ".
  66. "VALUES (10, 'Permanent', 7, 1, ".date('N').", ".date('N', time()+3600*24*7).", 'Testing')"));
  67. $this->assertTrue(mysql_query("INSERT IGNORE INTO `hs_hr_project_activity`(activity_id, project_id, name) " .
  68. "VALUES (10, 10, 'Test Activity')"));
  69. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_timesheet` (`timesheet_id`, `employee_id`, `timesheet_period_id`, `start_date`, `end_date`, `status`) ".
  70. "VALUES (10, 10, 10, '".date('Y-m-d')."', '".date('Y-m-d', time()+3600*24*7)."', 0)"));
  71. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_timesheet` (`timesheet_id`, `employee_id`, `timesheet_period_id`, `start_date`, `end_date`, `status`) ".
  72. "VALUES (11, 10, 10, '".date('Y-m-d', time()+3600*24*7)."', '".date('Y-m-d', time()+3600*24*7*2)."', 10)"));
  73. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_timesheet` (`timesheet_id`, `employee_id`, `timesheet_period_id`, `start_date`, `end_date`, `status`) ".
  74. "VALUES (12, 10, 10, '".date('Y-m-d', time()+3600*24*7*2)."', '".date('Y-m-d', time()+3600*24*7*3)."', 20)"));
  75. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_timesheet` (`timesheet_id`, `employee_id`, `timesheet_period_id`, `start_date`, `end_date`, `status`) ".
  76. "VALUES (13, 10, 10, '".date('Y-m-d', time()+3600*24*7*3)."', '".date('Y-m-d', time()+3600*24*7*4)."', 30)"));
  77. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_timesheet` (`timesheet_id`, `employee_id`, `timesheet_period_id`, `start_date`, `end_date`, `status`) ".
  78. "VALUES (14, 10, 10, '".date('Y-m-d')."', '".date('Y-m-d', time()+3600*24*7)."', 10)"));
  79. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_time_event` (`time_event_id`, `project_id`, `activity_id`, `employee_id`, `timesheet_id`, `start_time`, `end_time`, `reported_date`, `duration`, `description`) ".
  80. "VALUES (10, 10, 10, 10, 10, '".date('Y-m-d H:i:00')."', '".date('Y-m-d H:i:00', time()+3600)."', '".date('Y-m-d')."', 60, 'Testing1')"), mysql_error());
  81. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_time_event` (`time_event_id`, `project_id`, `activity_id`, `employee_id`, `timesheet_id`, `start_time`, `end_time`, `reported_date`, `duration`, `description`) ".
  82. "VALUES (11, 10, 10, 10, 10, '".date('Y-m-d H:i:00', time()+3600*2)."', '".date('Y-m-d H:i:00', time()+3600*3)."', '".date('Y-m-d')."', 60, 'Testing2')"));
  83. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_time_event` (`time_event_id`, `project_id`, `activity_id`, `employee_id`, `timesheet_id`, `start_time`, `end_time`, `reported_date`, `duration`, `description`) ".
  84. "VALUES (12, 10, 10, 10, 11, '".date('Y-m-d H:i:00', time()+3600*24*7)."', '".date('Y-m-d H:i:00', time()+3600*24*7+3600)."', '".date('Y-m-d', time()+3600*24*7)."', 60, 'Testing3')"));
  85. mysql_query("UPDATE `hs_hr_timesheet_submission_period` SET `start_day` = 1, `end_day` = 7 WHERE `timesheet_period_id` = 1");
  86. UniqueIDGenerator::getInstance()->resetIDs();
  87. }
  88. /**
  89. * Tears down the fixture, for example, close a network connection.
  90. * This method is called after a test is executed.
  91. *
  92. * @access protected
  93. */
  94. protected function tearDown() {
  95. $this->_deleteTestData();
  96. UniqueIDGenerator::getInstance()->resetIDs();
  97. }
  98. /**
  99. * Deletes test data created during test
  100. */
  101. private function _deleteTestData() {
  102. $this->assertTrue(mysql_query("TRUNCATE TABLE hs_hr_time_event"));
  103. $this->assertTrue(mysql_query("TRUNCATE TABLE hs_hr_timesheet"));
  104. $this->assertTrue(mysql_query("DELETE FROM `hs_hr_timesheet_submission_period` WHERE `timesheet_period_id` IN (10)", $this->connection));
  105. $this->assertTrue(mysql_query("DELETE FROM `hs_hr_project_activity` WHERE `project_id` IN (10)", $this->connection));
  106. $this->assertTrue(mysql_query("DELETE FROM `hs_hr_project` WHERE `project_id` IN (10)", $this->connection));
  107. $this->assertTrue(mysql_query("DELETE FROM `hs_hr_customer` WHERE `customer_id` IN (10)", $this->connection));
  108. $this->assertTrue(mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` IN (10)", $this->connection));
  109. $this->_runQuery("UPDATE `hs_hr_timesheet_submission_period` SET `start_day` = 0, `end_day` = 6 WHERE `timesheet_period_id` = 1");
  110. }
  111. /**
  112. * Run given sql query
  113. */
  114. private function _runQuery($sql) {
  115. $this->assertTrue(mysql_query($sql), mysql_error());
  116. }
  117. public function testfetchTimesheets() {
  118. $timesheetObj = $this->classTimesheet;
  119. $timesheetObj->setTimesheetId(50);
  120. $res = $timesheetObj->fetchTimesheets();
  121. $this->assertNull($res, "Returned non existing record");
  122. }
  123. public function testfetchTimesheets2() {
  124. $timesheetObj = $this->classTimesheet;
  125. $timesheetObj->setTimesheetId(10);
  126. $res = $timesheetObj->fetchTimesheets();
  127. $this->assertNotNull($res, "Returned non existing record");
  128. $expected[0]= array(10, 10, 10, date('Y-m-d'), date('Y-m-d', time()+3600*24*7), 0);
  129. $this->assertEquals(count($res), count($expected), "Returned invalid number of records");
  130. for ($i=0; $i<count($res); $i++) {
  131. $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId());
  132. $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId());
  133. $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId());
  134. $this->assertEquals($expected[$i][3], $res[$i]->getStartDate());
  135. $this->assertEquals($expected[$i][4], $res[$i]->getEndDate());
  136. $this->assertEquals($expected[$i][5], $res[$i]->getStatus());
  137. }
  138. }
  139. public function testfetchTimesheets3() {
  140. $timesheetObj = $this->classTimesheet;
  141. $timesheetObj->setStartDate(date('Y-m-d', time()+3600*24*7));
  142. $res = $timesheetObj->fetchTimesheets();
  143. $this->assertNotNull($res, "Returned non existing record");
  144. $expected[0]= array(11, 10, 10, date('Y-m-d', time()+3600*24*7), date('Y-m-d', time()+3600*24*7*2), 10);
  145. $this->assertEquals(count($res), count($expected), "Returned invalid number of records");
  146. for ($i=0; $i<count($res); $i++) {
  147. $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id");
  148. $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id");
  149. $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id");
  150. $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date");
  151. $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date");
  152. $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status");
  153. }
  154. }
  155. public function testSubmitTimesheet() {
  156. $timesheetObj = $this->classTimesheet;
  157. $timesheetObj->setTimesheetId(11);
  158. $timesheets = $timesheetObj->fetchTimesheets();
  159. $res = $timesheets[0]->submitTimesheet();
  160. $this->assertFalse($res);
  161. }
  162. public function testSubmitTimesheet2() {
  163. $timesheetObj = $this->classTimesheet;
  164. $timesheetObj->setTimesheetId(10);
  165. $timesheets = $timesheetObj->fetchTimesheets();
  166. $res = $timesheets[0]->submitTimesheet();
  167. $this->assertTrue($res);
  168. $timesheetObj->setTimesheetId(10);
  169. $res = $timesheetObj->fetchTimesheets();
  170. $this->assertNotNull($res, "Returned non existing record");
  171. $expected[0]= array(10, 10, 10, date('Y-m-d'), date('Y-m-d', time()+3600*24*7), 10);
  172. $this->assertEquals(count($res), count($expected), "Returned invalid number of records");
  173. for ($i=0; $i<count($res); $i++) {
  174. $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id");
  175. $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id");
  176. $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id");
  177. $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date");
  178. $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date");
  179. $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status");
  180. }
  181. }
  182. public function testCancelTimesheet() {
  183. $timesheetObj = $this->classTimesheet;
  184. $timesheetObj->setTimesheetId(10);
  185. $timesheets = $timesheetObj->fetchTimesheets();
  186. $res = $timesheets[0]->cancelTimesheet();
  187. $this->assertFalse($res);
  188. }
  189. public function testCancelTimesheet1() {
  190. $timesheetObj = $this->classTimesheet;
  191. $timesheetObj->setTimesheetId(11);
  192. $timesheets = $timesheetObj->fetchTimesheets();
  193. $res = $timesheets[0]->cancelTimesheet();
  194. $this->assertTrue($res);
  195. $timesheetObj->setTimesheetId(11);
  196. $res = $timesheetObj->fetchTimesheets();
  197. $this->assertNotNull($res, "Returned non existing record");
  198. $expected[0]= array(11, 10, 10, date('Y-m-d', time()+3600*24*7), date('Y-m-d', time()+3600*24*7*2), 0);
  199. $this->assertEquals(count($res), count($expected), "Returned invalid number of records");
  200. for ($i=0; $i<count($res); $i++) {
  201. $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id");
  202. $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id");
  203. $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id");
  204. $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date");
  205. $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date");
  206. $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status");
  207. }
  208. }
  209. public function testApproveTimesheet() {
  210. $timesheetObj = $this->classTimesheet;
  211. $timesheetObj->setTimesheetId(10);
  212. $timesheets = $timesheetObj->fetchTimesheets();
  213. $res = $timesheets[0]->approveTimesheet();
  214. $this->assertFalse($res);
  215. }
  216. public function testApproveTimesheet1() {
  217. $timesheetObj = $this->classTimesheet;
  218. $timesheetObj->setTimesheetId(11);
  219. $timesheets = $timesheetObj->fetchTimesheets();
  220. $timesheets[0]->setComment('Testing...');
  221. $res = $timesheets[0]->approveTimesheet();
  222. $this->assertTrue($res);
  223. $timesheetObj->setTimesheetId(11);
  224. $res = $timesheetObj->fetchTimesheets();
  225. $this->assertNotNull($res, "Returned non existing record");
  226. $expected[0]= array(11, 10, 10, date('Y-m-d', time()+3600*24*7), date('Y-m-d', time()+3600*24*7*2), 20, 'Testing...');
  227. $this->assertEquals(count($res), count($expected), "Returned invalid number of records");
  228. for ($i=0; $i<count($res); $i++) {
  229. $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id");
  230. $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id");
  231. $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id");
  232. $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date");
  233. $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date");
  234. $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status");
  235. $this->assertEquals($expected[$i][6], $res[$i]->getComment(), "Invalid Comment");
  236. }
  237. }
  238. public function testRejectTimesheet() {
  239. $timesheetObj = $this->classTimesheet;
  240. $timesheetObj->setTimesheetId(10);
  241. $timesheets = $timesheetObj->fetchTimesheets();
  242. $res = $timesheets[0]->rejectTimesheet();
  243. $this->assertFalse($res);
  244. }
  245. public function testRejectTimesheet2() {
  246. $timesheetObj = $this->classTimesheet;
  247. $timesheetObj->setTimesheetId(11);
  248. $timesheets = $timesheetObj->fetchTimesheets();
  249. $res = $timesheets[0]->rejectTimesheet();
  250. $this->assertTrue($res);
  251. $timesheetObj->setTimesheetId(11);
  252. $res = $timesheetObj->fetchTimesheets();
  253. $this->assertNotNull($res, "Returned non existing record");
  254. $expected[0]= array(11, 10, 10, date('Y-m-d', time()+3600*24*7), date('Y-m-d', time()+3600*24*7*2), 30);
  255. $this->assertEquals(count($res), count($expected), "Returned invalid number of records");
  256. for ($i=0; $i<count($res); $i++) {
  257. $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id");
  258. $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id");
  259. $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id");
  260. $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date");
  261. $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date");
  262. $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status");
  263. }
  264. }
  265. public function testAddTimesheet() {
  266. $timesheetObj = $this->classTimesheet;
  267. $timesheetObj->setEmployeeId(10);
  268. $timesheetObj->setTimesheetPeriodId(10);
  269. $timesheetObj->setStartDate(date('Y-m-d', time()+3600*24*7*4));
  270. $timesheetObj->setEndDate(date('Y-m-d', time()+3600*24*7*5));
  271. $timesheetObj->addTimesheet();
  272. $expectedId = $timesheetObj->getTimesheetId();
  273. $res = $timesheetObj->fetchTimesheets();
  274. $this->assertNotNull($res, "Returned non existing record");
  275. $expected[0]= array($expectedId, 10, 10, date('Y-m-d', time()+3600*24*7*4), date('Y-m-d', time()+3600*24*7*5), 0);
  276. $this->assertEquals(count($res), count($expected), "Returned invalid number of records");
  277. for ($i=0; $i<count($res); $i++) {
  278. $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id");
  279. $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id");
  280. $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id");
  281. $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date");
  282. $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date");
  283. $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status");
  284. }
  285. }
  286. public function testAddTimesheet2() {
  287. $timesheetObj = $this->classTimesheet;
  288. $timesheetObj->setEmployeeId(10);
  289. $timesheetObj->setTimesheetPeriodId(10);
  290. $timesheetObj->addTimesheet();
  291. $expectedId = $timesheetObj->getTimesheetId();
  292. $res = $timesheetObj->fetchTimesheets();
  293. $this->assertNotNull($res, "Returned non existing record");
  294. $day=date("w");
  295. $expected[0]= array($expectedId, 10, 1, date('Y-m-d', time()+3600*24*(1-$day)), date('Y-m-d', time()+3600*24*(7-$day)), 0);
  296. $this->assertEquals(count($res), count($expected), "Returned invalid number of records");
  297. for ($i=0; $i<count($res); $i++) {
  298. $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id");
  299. $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id");
  300. $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id");
  301. $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date (FIXME: test fails on sundays!)");
  302. $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date");
  303. $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status");
  304. }
  305. }
  306. public function testFetchTimesheetId() {
  307. $timesheetObj = $this->classTimesheet;
  308. $timesheetObj->setEmployeeId(10);
  309. $timesheetObj->setStartDate(date('Y-m-d'));
  310. $timesheetObj->setEndDate(date('Y-m-d', time()+3600*24*6));
  311. $timesheetObj->setStatus(Timesheet::TIMESHEET_STATUS_SUBMITTED);
  312. $res = $timesheetObj->fetchTimesheetId(Timesheet::TIMESHEET_DIRECTION_PREV);
  313. $this->assertFalse($res, 'Invalid id returned');
  314. }
  315. public function testFetchTimesheetId1() {
  316. $timesheetObj = $this->classTimesheet;
  317. $timesheetObj->setEmployeeId(10);
  318. $timesheetObj->setStartDate(date('Y-m-d'));
  319. $timesheetObj->setEndDate(date('Y-m-d', time()+3600*24*6));
  320. $timesheetObj->setStatus(Timesheet::TIMESHEET_STATUS_SUBMITTED);
  321. $res = $timesheetObj->fetchTimesheetId(Timesheet::TIMESHEET_DIRECTION_NEXT);
  322. $this->assertEquals(11, $res, 'Invalid id returned');
  323. }
  324. public function testFetchTimesheetId2() {
  325. $timesheetObj = $this->classTimesheet;
  326. $timesheetObj->setEmployeeId(10);
  327. $timesheetObj->setStartDate(date('Y-m-d', time()+3600*24*7*1+3600*24*6));
  328. $timesheetObj->setEndDate(date('Y-m-d', time()+3600*24*7*3));
  329. $timesheetObj->setStatus(Timesheet::TIMESHEET_STATUS_SUBMITTED);
  330. $res = $timesheetObj->fetchTimesheetId(Timesheet::TIMESHEET_DIRECTION_PREV);
  331. $this->assertEquals(11, $res, 'Invalid id returned');
  332. }
  333. public function testCheckTimesheetStatus() {
  334. $statusResult = Timesheet::checkTimesheetStatus(12, Timesheet::TIMESHEET_STATUS_APPROVED);
  335. $this->assertTrue($statusResult);
  336. $statusResult = Timesheet::checkTimesheetStatus(13, Timesheet::TIMESHEET_STATUS_REJECTED);
  337. $this->assertTrue($statusResult);
  338. $statusResult = Timesheet::checkTimesheetStatus(10, Timesheet::TIMESHEET_STATUS_REJECTED);
  339. $this->assertFalse($statusResult);
  340. }
  341. public function testCheckDateInApprovedTimesheet() {
  342. $timesheetObj = $this->classTimesheet;
  343. $timesheetObj->setTimesheetId(14);
  344. $timesheets = $timesheetObj->fetchTimesheets();
  345. $res = $timesheets[0]->approveTimesheet();
  346. $statusResult = Timesheet::checkDateInApprovedTimesheet(date('Y-m-d'), 10);
  347. $this->assertTrue($statusResult);
  348. $statusResult1 = Timesheet::checkDateInApprovedTimesheet(date('Y-m-d', time()+3600*24*7), 10);
  349. $this->assertTrue($statusResult1);
  350. $statusResult3 = Timesheet::checkDateInApprovedTimesheet(date('Y-m-d', time()+3600*24*7*6), 10);
  351. $this->assertFalse($statusResult3);
  352. }
  353. }
  354. // Call TimesheetTest::main() if this source file is executed directly.
  355. if (PHPUnit_MAIN_METHOD == "TimesheetTest::main") {
  356. TimesheetTest::main();
  357. }
  358. ?>