PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/controllers/ViewControllerTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 128 lines | 71 code | 24 blank | 33 comment | 3 complexity | a5467a73cc18fd4b4ddb0602881a1830 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. // Call ViewControllerTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "ViewControllerTest::main");
  5. }
  6. require_once "PHPUnit/Framework/TestCase.php";
  7. require_once "PHPUnit/Framework/TestSuite.php";
  8. require_once "testConf.php";
  9. // Required by View Controller
  10. $_SESSION['ldap'] = "disabled";
  11. require_once ROOT_PATH . '/lib/controllers/ViewController.php';
  12. require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';
  13. require_once ROOT_PATH . "/lib/confs/Conf.php";
  14. /**
  15. * Test class for ViewController.
  16. */
  17. class ViewControllerTest extends PHPUnit_Framework_TestCase {
  18. /**
  19. * Runs the test methods of this class.
  20. *
  21. * @access public
  22. * @static
  23. */
  24. public static function main() {
  25. require_once "PHPUnit/TextUI/TestRunner.php";
  26. $suite = new PHPUnit_Framework_TestSuite("ViewControllerTest");
  27. $result = PHPUnit_TextUI_TestRunner::run($suite);
  28. }
  29. /**
  30. * Sets up the fixture, for example, open a network connection.
  31. * This method is called before a test is executed.
  32. *
  33. * @access protected
  34. */
  35. protected function setUp() {
  36. $_SESSION['empID'] = "010";
  37. $conf = new Conf();
  38. mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  39. mysql_select_db($conf->dbname);
  40. $this->_deleteTables();
  41. $this->_runQuery("INSERT INTO hs_hr_job_spec(jobspec_id, jobspec_name, jobspec_desc, jobspec_duties) " .
  42. "VALUES(1, 'Spec 1', 'Desc 1', 'duties 1')");
  43. $this->_runQuery("INSERT INTO hs_hr_job_spec(jobspec_id, jobspec_name, jobspec_desc, jobspec_duties) " .
  44. "VALUES(2, 'Spec 2', 'Desc 2', 'duties 2')");
  45. $this->_runQuery("INSERT INTO hs_pr_salary_grade(sal_grd_code, sal_grd_name) " .
  46. "VALUES('SAL001', 'Director grade')");
  47. $this->_runQuery("INSERT INTO hs_pr_salary_grade(sal_grd_code, sal_grd_name) " .
  48. "VALUES('SAL002', 'Other grade')");
  49. $this->_runQuery("INSERT INTO hs_hr_job_title(jobtit_code, jobtit_name, jobtit_desc,jobtit_comm, " .
  50. "sal_grd_code, jobspec_id) " .
  51. "VALUES('JOB001', 'Driver', 'Driver Desc', 'Driver comments', 'SAL002', null)");
  52. $this->_runQuery("INSERT INTO hs_hr_job_title(jobtit_code, jobtit_name, jobtit_desc,jobtit_comm, " .
  53. "sal_grd_code, jobspec_id) " .
  54. "VALUES('JOB002', 'Typist', 'Typist Desc', 'Typist comments', 'SAL002', 1)");
  55. UniqueIDGenerator::getInstance()->initTable();
  56. }
  57. /**
  58. * Tears down the fixture, for example, close a network connection.
  59. * This method is called after a test is executed.
  60. *
  61. * @access protected
  62. */
  63. protected function tearDown() {
  64. $this->_deleteTables();
  65. UniqueIDGenerator::getInstance()->initTable();
  66. }
  67. private function _deleteTables() {
  68. $this->_runQuery("TRUNCATE TABLE `hs_hr_job_title`");
  69. $this->_runQuery("TRUNCATE TABLE `hs_pr_salary_grade`");
  70. $this->_runQuery("TRUNCATE TABLE `hs_hr_job_spec`");
  71. }
  72. /**
  73. * Tests getJobSpecForJob method.
  74. */
  75. public function testGetJobSpecForJob() {
  76. $viewController = new ViewController();
  77. // invalid job title id
  78. $spec = $viewController->getJobSpecForJob('JOB010');
  79. $this->assertNull($spec);
  80. // job title with no job spec assigned
  81. $spec = $viewController->getJobSpecForJob('JOB001');
  82. $this->assertNull($spec);
  83. // job id with job spec assigned
  84. $spec = $viewController->getJobSpecForJob('JOB002');
  85. $this->assertNotNull($spec);
  86. $expected = new JobSpec();
  87. $expected->setId(1);
  88. $expected->setName('Spec 1');
  89. $expected->setDesc('Desc 1');
  90. $expected->setDuties('duties 1');
  91. $this->assertEquals($expected, $spec);
  92. }
  93. /**
  94. * Run given sql query, checking the return value
  95. */
  96. private function _runQuery($sql) {
  97. $this->assertTrue(mysql_query($sql), mysql_error());
  98. }
  99. }
  100. // Call ViewControllerTest::main() if this source file is executed directly.
  101. if (PHPUnit_MAIN_METHOD == "ViewControllerTest::main") {
  102. ViewControllerTest::main();
  103. }
  104. ?>