PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/models/time/TimesheetSubmissionPeriodTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 157 lines | 89 code | 26 blank | 42 comment | 4 complexity | 5cb62ea5aaebc98a62cc15fa96043693 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 TimesheetSubmissionPeriodTest::main() if this source file is executed directly.
  21. if (!defined("PHPUnit_MAIN_METHOD")) {
  22. define("PHPUnit_MAIN_METHOD", "TimesheetSubmissionPeriodTest::main");
  23. }
  24. require_once "PHPUnit/Framework/TestCase.php";
  25. require_once "PHPUnit/Framework/TestSuite.php";
  26. require_once "testConf.php";
  27. require_once ROOT_PATH."/lib/confs/Conf.php";
  28. require_once 'TimesheetSubmissionPeriod.php';
  29. /**
  30. * Test class for TimesheetSubmissionPeriod.
  31. * Generated by PHPUnit_Util_Skeleton on 2007-03-27 at 16:43:39.
  32. */
  33. class TimesheetSubmissionPeriodTest extends PHPUnit_Framework_TestCase {
  34. public $classTimesheetSubmissionPeriod = 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("TimesheetSubmissionPeriodTest");
  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->classTimesheetSubmissionPeriod = new TimesheetSubmissionPeriod();
  55. $conf = new Conf();
  56. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  57. mysql_select_db($conf->dbname);
  58. mysql_query("UPDATE `hs_hr_timesheet_submission_period` SET `start_day` = 0, `end_day` = 6 WHERE `timesheet_period_id` = 1");
  59. }
  60. /**
  61. * Tears down the fixture, for example, close a network connection.
  62. * This method is called after a test is executed.
  63. *
  64. * @access protected
  65. */
  66. protected function tearDown() {
  67. mysql_query("UPDATE `hs_hr_timesheet_submission_period` SET `start_day` = 0, `end_day` = 6 WHERE `timesheet_period_id` = 1");
  68. }
  69. public function testSaveTimesheetSubmissionPeriod() {
  70. $expected[0] = array(1, 'week', 7, 1, 1, 7, 'Weekly');
  71. $this->classTimesheetSubmissionPeriod->setTimesheetPeriodId(1);
  72. $this->classTimesheetSubmissionPeriod->setStartDay($expected[0][4]);
  73. try {
  74. $res = $this->classTimesheetSubmissionPeriod->saveTimesheetSubmissionPeriod();
  75. } catch (TimesheetSubmissionPeriodException $err) {
  76. $errCode = $err->getCode();
  77. $errMessage = $err->getMessage();
  78. $this->assertEquals($errCode, -2, "Unexpected error code");
  79. $this->assertEquals($errMessage, "Unable to determine the end date", "Unexpected error message");
  80. return;
  81. }
  82. $this->fail('An expected Exception has not been raised.');
  83. }
  84. public function testSaveTimesheetSubmissionPeriod3() {
  85. $expected[0] = array(1, 'week', 7, 1, 2, 1, 'Weekly');
  86. $this->classTimesheetSubmissionPeriod->setTimesheetPeriodId(1);
  87. $this->classTimesheetSubmissionPeriod->setStartDay($expected[0][4]);
  88. $this->classTimesheetSubmissionPeriod->setFrequency($expected[0][2]);
  89. $res = $this->classTimesheetSubmissionPeriod->saveTimesheetSubmissionPeriod();
  90. $this->assertTrue($res, "Failed to save");
  91. $res = $this->classTimesheetSubmissionPeriod->fetchTimesheetSubmissionPeriods();
  92. $this->assertNotNull($res, "Returned nothing");
  93. $this->assertEquals(count($res), 1, "Didn't return the expected number of records");
  94. for ($i=0; $i<count($res); $i++) {
  95. $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetPeriodId(), "Invalid timesheet period id");
  96. $this->assertEquals($expected[$i][1], $res[$i]->getName(), "Invalid timesheet period name");
  97. $this->assertEquals($expected[$i][2], $res[$i]->getFrequency(), "Invalid timesheet period frequency");
  98. $this->assertEquals($expected[$i][3], $res[$i]->getPeriod(), "Invalid timesheet period period");
  99. $this->assertEquals($expected[$i][4], $res[$i]->getStartDay(), "Invalid timesheet period start day");
  100. $this->assertEquals($expected[$i][5], $res[$i]->getEndDay(), "Invalid timesheet period end day");
  101. $this->assertEquals($expected[$i][6], $res[$i]->getDescription(), "Invalid timesheet period description");
  102. }
  103. }
  104. public function testFetchTimesheetSubmissionPeriods() {
  105. $this->classTimesheetSubmissionPeriod->setTimesheetPeriodId(1);
  106. $res = $this->classTimesheetSubmissionPeriod->fetchTimesheetSubmissionPeriods();
  107. $expected[0] = array(1, 'week', 7, 1, 0, 6, 'Weekly');
  108. $this->assertNotNull($res, "Returned nothing");
  109. $this->assertEquals(count($res), 1, "Didn't return the expected number of records");
  110. for ($i=0; $i<count($res); $i++) {
  111. $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetPeriodId(), "Invalid timesheet period id");
  112. $this->assertEquals($expected[$i][1], $res[$i]->getName(), "Invalid timesheet period name");
  113. $this->assertEquals($expected[$i][2], $res[$i]->getFrequency(), "Invalid timesheet period frequency");
  114. $this->assertEquals($expected[$i][3], $res[$i]->getPeriod(), "Invalid timesheet period period");
  115. $this->assertEquals($expected[$i][4], $res[$i]->getStartDay(), "Invalid timesheet period start day");
  116. $this->assertEquals($expected[$i][5], $res[$i]->getEndDay(), "Invalid timesheet period end day");
  117. $this->assertEquals($expected[$i][6], $res[$i]->getDescription(), "Invalid timesheet period description");
  118. }
  119. }
  120. }
  121. // Call TimesheetSubmissionPeriodTest::main() if this source file is executed directly.
  122. if (PHPUnit_MAIN_METHOD == "TimesheetSubmissionPeriodTest::main") {
  123. TimesheetSubmissionPeriodTest::main();
  124. }
  125. ?>