PageRenderTime 72ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/models/eimadmin/CompPropertyTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 199 lines | 108 code | 48 blank | 43 comment | 3 complexity | bd2c6dedb0c4ed6361d9e74b8665ac71 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 CompPropertyTest::main() if this source file is executed directly.
  3. if (!defined('PHPUnit_MAIN_METHOD')) {
  4. define('PHPUnit_MAIN_METHOD', 'CompPropertyTest::main');
  5. }
  6. require_once "testConf.php";
  7. require_once 'PHPUnit/Framework.php';
  8. require_once 'CompProperty.php';
  9. /**
  10. * Test class for CompProperty.
  11. * Generated by PHPUnit on 2008-02-22 at 12:54:05.
  12. */
  13. class CompPropertyTest extends PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @var CompProperty
  17. * @access protected
  18. */
  19. protected $object;
  20. /**
  21. * Runs the test methods of this class.
  22. *
  23. * @access public
  24. * @static
  25. */
  26. public static function main()
  27. {
  28. require_once 'PHPUnit/TextUI/TestRunner.php';
  29. $suite = new PHPUnit_Framework_TestSuite('CompPropertyTest');
  30. $result = PHPUnit_TextUI_TestRunner::run($suite);
  31. }
  32. /**
  33. * Sets up the fixture, for example, opens a network connection.
  34. * This method is called before a test is executed.
  35. *
  36. * @access protected
  37. */
  38. protected function setUp()
  39. {
  40. $conf = new Conf();
  41. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  42. mysql_select_db($conf->dbname);
  43. mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);
  44. }
  45. /**
  46. * Tears down the fixture, for example, closes a network connection.
  47. * This method is called after a test is executed.
  48. *
  49. * @access protected
  50. */
  51. protected function tearDown()
  52. {
  53. mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);
  54. mysql_close($this->connection);
  55. }
  56. /**
  57. * @todo Implement testAddProperty().
  58. */
  59. public function testAddProperty() {
  60. mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);
  61. $prop = new CompProperty();
  62. $prop->setPropName('new Item');
  63. $prop->addProperty();
  64. $res=mysql_query("SELECT * FROM `hs_hr_comp_property`", $this->connection);
  65. $row=mysql_fetch_array($res);
  66. $this->assertEquals($row['prop_name'],'new Item');
  67. $this->assertEquals($row['prop_id'],'1');
  68. }
  69. /**
  70. * @todo Implement testEditProperty().
  71. */
  72. public function testEditProperty() {
  73. mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);
  74. mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item','1')", $this->connection);
  75. $prop = new CompProperty();
  76. $prop->setPropName('new Item Edited');
  77. $prop->editProperty(1);
  78. $res=mysql_query("SELECT * FROM `hs_hr_comp_property`", $this->connection);
  79. $row=mysql_fetch_array($res);
  80. $this->assertEquals($row['prop_name'],'new Item Edited');
  81. $this->assertEquals($row['emp_id'],'1');
  82. $this->assertEquals($row['prop_id'],'1');
  83. }
  84. /**
  85. * @todo Implement testGetPropertyList().
  86. */
  87. public function testGetPropertyList() {
  88. mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);
  89. mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item','1')", $this->connection);
  90. mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item 2','10')", $this->connection);
  91. $prop = new CompProperty();
  92. $prop->setPropName('new Item Edited');
  93. $rows=$prop->getPropertyList();
  94. $this->assertEquals($rows[0]['prop_name'],'new Item');
  95. $this->assertEquals($rows[0]['emp_id'],'1');
  96. $this->assertEquals($rows[0]['prop_id'],'1');
  97. $this->assertEquals($rows[1]['prop_name'],'new Item 2');
  98. $this->assertEquals($rows[1]['emp_id'],'10');
  99. $this->assertEquals($rows[1]['prop_id'],'2');
  100. }
  101. /**
  102. * @todo Implement testEditPropertyList().
  103. */
  104. public function testEditPropertyList() {
  105. mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);
  106. mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item','1')", $this->connection);
  107. mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item 2','10')", $this->connection);
  108. $prop = new CompProperty();
  109. $prop->setEditPropIds(array('1','2'));
  110. $prop->setEditEmpIds(array('5','6'));
  111. $prop->editPropertyList();
  112. $res=mysql_query("SELECT * FROM `hs_hr_comp_property`", $this->connection);
  113. $row=mysql_fetch_array($res);
  114. $this->assertEquals($row['prop_name'],'new Item');
  115. $this->assertEquals($row['emp_id'],'5');
  116. $this->assertEquals($row['prop_id'],'1');
  117. $row=mysql_fetch_array($res);
  118. $this->assertEquals($row['prop_name'],'new Item 2');
  119. $this->assertEquals($row['emp_id'],'6');
  120. $this->assertEquals($row['prop_id'],'2');
  121. }
  122. /**
  123. * @todo Implement testDeleteProperties().
  124. */
  125. public function testDeleteProperties() {
  126. mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);
  127. mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item','1')", $this->connection);
  128. mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item 2','10')", $this->connection);
  129. mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item 3','11')", $this->connection);
  130. mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item 5','20')", $this->connection);
  131. $prop = new CompProperty();
  132. $prop->setDeleteList(array('2','3'));
  133. $prop->deleteProperties();
  134. $res=mysql_query("SELECT * FROM `hs_hr_comp_property`", $this->connection);
  135. $numRows= mysql_num_rows($res);
  136. $this->assertEquals($numRows,2,'Number of rows invalid');
  137. $row=mysql_fetch_array($res);
  138. $this->assertEquals($row['prop_name'],'new Item');
  139. $this->assertEquals($row['emp_id'],'1');
  140. $this->assertEquals($row['prop_id'],'1');
  141. $row=mysql_fetch_array($res);
  142. $this->assertEquals($row['prop_name'],'new Item 5');
  143. $this->assertEquals($row['emp_id'],'20');
  144. $this->assertEquals($row['prop_id'],'4');
  145. }
  146. }
  147. // Call CompPropertyTest::main() if this source file is executed directly.
  148. if (PHPUnit_MAIN_METHOD == 'CompPropertyTest::main') {
  149. CompPropertyTest::main();
  150. }
  151. ?>