PageRenderTime 33ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/models/benefits/HspSummaryTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 470 lines | 285 code | 123 blank | 62 comment | 14 complexity | 8c35ee0fbcca310db275c7c6826b35ff 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 HspSummaryTest::main() if this source file is executed directly.
  3. if (!defined('PHPUnit_MAIN_METHOD')) {
  4. define('PHPUnit_MAIN_METHOD', 'HspSummaryTest::main');
  5. }
  6. require_once 'PHPUnit/Framework.php';
  7. require_once "testConf.php";
  8. require_once ROOT_PATH."/lib/confs/Conf.php";
  9. require_once ROOT_PATH."/lib/common/UniqueIDGenerator.php";
  10. require_once 'HspSummary.php';
  11. /**
  12. * Test class for HspSummary.
  13. * Generated by PHPUnit on 2008-02-15 at 15:36:45.
  14. */
  15. class HspSummaryTest extends PHPUnit_Framework_TestCase {
  16. private $oldValues = array();
  17. private $oldHspValue = null;
  18. private $employeeFields = null;
  19. /**
  20. * Runs the test methods of this class.
  21. *
  22. * @access public
  23. * @static
  24. */
  25. public static function main() {
  26. require_once 'PHPUnit/TextUI/TestRunner.php';
  27. $suite = new PHPUnit_Framework_TestSuite('HspSummaryTest');
  28. $result = PHPUnit_TextUI_TestRunner::run($suite);
  29. }
  30. /**
  31. * Sets up the fixture, for example, opens a network connection.
  32. * This method is called before a test is executed.
  33. *
  34. * @access protected
  35. */
  36. protected function setUp() {
  37. $this->employeeFields = "`emp_number`, `employee_id`, `emp_lastname`, `emp_firstname`, `emp_middle_name`, `emp_nick_name`, " .
  38. "`emp_smoker`, `ethnic_race_code`, `emp_birthday`, `nation_code`, `emp_gender`, `emp_marital_status`, " .
  39. "`emp_ssn_num`, `emp_sin_num`, `emp_other_id`, `emp_dri_lice_num`, `emp_dri_lice_exp_date`, `emp_military_service`, " .
  40. "`emp_status`, `job_title_code`, `eeo_cat_code`, `work_station`, `emp_street1`, `emp_street2`, " .
  41. "`city_code`, `coun_code`, `provin_code`, `emp_zipcode`, `emp_hm_telephone`, `emp_mobile`, " .
  42. "`emp_work_telephone`, `emp_work_email`, `sal_grd_code`, `joined_date`, `emp_oth_email`";
  43. $conf = new Conf();
  44. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  45. mysql_select_db($conf->dbname);
  46. $tableList = array('hs_hr_hsp_summary','hs_hr_employee');
  47. $this->_backupTables($tableList);
  48. $result = mysql_query("SELECT `nilai` FROM `hs_hr_config` WHERE `key` = 'hsp_current_plan';");
  49. $row = mysql_fetch_array($result, MYSQL_NUM);
  50. $this->oldHspValue = $row[0];
  51. $result = mysql_query("SELECT `last_id`, `table_name`, `field_name` FROM `hs_hr_unique_id`;");
  52. while($row = mysql_fetch_array($result, MYSQL_NUM)) {
  53. $this->oldValues['AUTO_INC_PK_TABLE']['hs_hr_unique_id'][] = $row;
  54. }
  55. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"),mysql_error());
  56. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_employee`"),mysql_error());
  57. $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `nilai` = '1' WHERE `key` = 'hsp_current_plan';"),mysql_error());
  58. $this->assertTrue(mysql_query("UPDATE `hs_hr_unique_id` SET `last_id` = '0' WHERE `table_name` = 'hs_hr_hsp_summary' AND `field_name` = 'summary_id'"),mysql_error());
  59. // Used in testSaveInitialSummaryForOneEmployee()
  60. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (1, 1, 1, ".date('Y').", 1, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  61. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (2, 1, 3, ".date('Y').", 1, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  62. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (3, 1, 1, ".(date('Y')+1).", 1, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  63. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (4, 1, 3, ".(date('Y')+1).", 1, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  64. $this->assertTrue(mysql_query("UPDATE `hs_hr_unique_id` SET `last_id` = '4' WHERE `table_name` = 'hs_hr_hsp_summary' AND `field_name` = 'summary_id'"),mysql_error());
  65. }
  66. /**
  67. * Tears down the fixture, for example, closes a network connection.
  68. * This method is called after a test is executed.
  69. *
  70. * @access protected
  71. */
  72. protected function tearDown() {
  73. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"),mysql_error());
  74. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_employee`"),mysql_error());
  75. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_unique_id`"),mysql_error());
  76. foreach($this->oldValues['AUTO_INC_PK_TABLE']['hs_hr_unique_id'] as $row) {
  77. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_unique_id` VALUES (NULL, '" . implode("', '", $row) . "')"), mysql_error());
  78. }
  79. $this->_restoreTables();
  80. UniqueIDGenerator::getInstance()->resetIDs();
  81. $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `nilai` = '$this->oldHspValue' WHERE `key` = 'hsp_current_plan';"),mysql_error());
  82. }
  83. public function testFetchSummary() {
  84. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"),mysql_error());
  85. // Add 3 records to `hs_hr_hsp_summary`
  86. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (1, 1, 1, ".date('Y').", 0, 1200.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  87. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (2, 2, 1, ".date('Y').", 0, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  88. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (3, 3, 1, ".date('Y').", 0, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  89. //Add 3 employees to `hs_hr_employee`
  90. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (1, '001', 'Bauer', 'Jack', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"),mysql_error());
  91. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (2, '002', 'Bond', 'James', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"),mysql_error());
  92. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (3, '003', 'Owen', 'David', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"),mysql_error());
  93. $hspSummary = new HspSummary();
  94. $summary = $hspSummary->fetchHspSummary(date('Y'), 1);
  95. $this->assertTrue(is_array($summary));
  96. $this->assertTrue(is_object($summary[0]));
  97. $this->assertEquals(count($summary), 3);
  98. $this->assertEquals($summary[0]->getAnnualLimit(), 1200);
  99. }
  100. public function testFetchPersonalSummary() {
  101. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"),mysql_error());
  102. // Add 3 records to `hs_hr_hsp_summary`
  103. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (1, 1, 1, ".date('Y').", 0, 1200.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  104. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (2, 2, 1, ".date('Y').", 0, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  105. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (3, 3, 1, ".date('Y').", 0, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  106. //Add 3 employees to `hs_hr_employee`
  107. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (1, '001', 'Bauer', 'Jack', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"),mysql_error());
  108. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (2, '002', 'Bond', 'James', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"),mysql_error());
  109. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (3, '003', 'Owen', 'David', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"),mysql_error());
  110. $hspSummary = new HspSummary();
  111. $summary = $hspSummary->fetchPersonalHspSummary(date('Y'), 1);
  112. $this->assertTrue(is_array($summary));
  113. $this->assertTrue(is_object($summary[0]));
  114. $this->assertEquals(count($summary), 1);
  115. $this->assertEquals($summary[0]->getAnnualLimit(), 1200);
  116. $summary = $hspSummary->fetchPersonalHspSummary(date('Y'), 5);
  117. $this->assertNull($summary);
  118. }
  119. public function testSaveInitialSummary() {
  120. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_employee`"),mysql_error());
  121. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"),mysql_error());
  122. UniqueIDGenerator::getInstance()->resetIDs();
  123. //Add 3 employees to `hs_hr_employee`
  124. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (1, '001', 'Bauer', 'Jack', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"),mysql_error());
  125. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (2, '002', 'Bond', 'James', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"),mysql_error());
  126. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (3, '003', 'Owen', 'David', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"),mysql_error());
  127. HspSummary::saveInitialSummary(date('Y'), 1);
  128. $result = mysql_query("SELECT COUNT(*) FROM `hs_hr_hsp_summary`");
  129. $row = mysql_fetch_array($result);
  130. $this->assertEquals($row[0], 3);
  131. // Checking for important fields
  132. // `hsp_plan_id`
  133. $result = mysql_query("SELECT `hsp_plan_id` FROM `hs_hr_hsp_summary`");
  134. $i=0;
  135. while ($row = mysql_fetch_array($result)) {
  136. $actual[$i] = $row[0];
  137. $i++;
  138. }
  139. $expected[0] = 1;
  140. $expected[1] = 1;
  141. $expected[2] = 1;
  142. $this->assertEquals($expected, $actual); // Two arrays should be equal
  143. // `summary_id`
  144. $result = mysql_query("SELECT `summary_id` FROM `hs_hr_hsp_summary`");
  145. $i=0;
  146. while ($row = mysql_fetch_array($result)) {
  147. $actual[$i] = $row[0];
  148. $i++;
  149. }
  150. $expected[0] = 1;
  151. $expected[1] = 2;
  152. $expected[2] = 3;
  153. $this->assertEquals($expected, $actual); // Two arrays should be equal
  154. // `employee_id`
  155. $result = mysql_query("SELECT `employee_id` FROM `hs_hr_hsp_summary`");
  156. $i=0;
  157. while ($row = mysql_fetch_array($result)) {
  158. $actual[$i] = $row[0];
  159. $i++;
  160. }
  161. $expected[0] = 1;
  162. $expected[1] = 2;
  163. $expected[2] = 3;
  164. $this->assertEquals($expected, $actual); // Two arrays should be equal
  165. // Cleaning the database
  166. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"),mysql_error());
  167. $this->assertTrue(mysql_query("UPDATE `hs_hr_unique_id` SET `last_id` = '0' WHERE `table_name` = 'hs_hr_hsp_summary' AND `field_name` = 'summary_id'"),mysql_error());
  168. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_employee`"),mysql_error());
  169. $this->assertTrue(mysql_query("UPDATE `hs_hr_unique_id` SET `last_id` = '0' WHERE `table_name` = 'hs_hr_employee' AND `field_name` = 'emp_number'"),mysql_error());
  170. }
  171. /**
  172. * This test is to check whether the function accepts zero for HSP Plan ID
  173. */
  174. public function testSaveInitialSummary2() {
  175. try {
  176. HspSummary::saveInitialSummary(date('Y'), 0);
  177. $this->fail("Zero is accepted for HSP Plan ID");
  178. } catch (HspSummaryException $e) {
  179. $this->assertEquals(HspSummaryException::HSP_PLAN_NOT_DEFINED, $e->getCode());
  180. }
  181. }
  182. /**
  183. * This test is to check whether the function throws an excpetion when no employee has been defined.
  184. */
  185. public function testSaveInitialSummary3() {
  186. try {
  187. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_employee`"),mysql_error());
  188. HspSummary::saveInitialSummary(date('Y'), 1);
  189. $this->fail("No exception is thrown when no employee exists");
  190. } catch (HspSummaryException $e) {
  191. $this->assertEquals(HspSummaryException::NO_EMPLOYEE_EXISTS, $e->getCode());
  192. }
  193. }
  194. public function testRecordsExist() {
  195. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"),mysql_error());
  196. // Add 2 records to `hs_hr_hsp_summary`
  197. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (1, 1, 1, ".date('Y').", 0, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  198. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (2, 2, 1, ".date('Y').", 0, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  199. $this->assertTrue(HspSummary::recordsExist(date('Y')));
  200. $this->assertTrue(HspSummary::recordsExist(date('Y'), 1));
  201. $this->assertFalse(HspSummary::recordsExist(date('Y')+1));
  202. $this->assertFalse(HspSummary::recordsExist(date('Y'), 2));
  203. $this->assertFalse(HspSummary::recordsExist(date('Y')+1, 2));
  204. }
  205. public function testRecordsCount() {
  206. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"),mysql_error());
  207. // Add 2 records to `hs_hr_hsp_summary`
  208. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (1, 1, 1, ".date('Y').", 0, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  209. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (2, 2, 1, ".date('Y').", 0, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  210. $this->assertEquals(HspSummary::recordsCount(date('Y'), 1), 2);
  211. }
  212. public function testSaveHspSummary() {
  213. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"),mysql_error());
  214. // Add 2 records to `hs_hr_hsp_summary`
  215. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (1, 1, 1, ".date('Y').", 1, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  216. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (2, 2, 1, ".date('Y').", 1, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  217. $summaryObj[0] = new HspSummary();
  218. $summaryObj[0]->setSummaryId(1);
  219. $summaryObj[0]->setAnnualLimit(1200);
  220. $summaryObj[0]->setEmployerAmount(60);
  221. $summaryObj[0]->setEmployeeAmount(50);
  222. $summaryObj[0]->setTotalAccrued(110);
  223. $summaryObj[0]->setTotalUsed(75);
  224. $summaryObj[1] = new HspSummary();
  225. $summaryObj[1]->setSummaryId(2);
  226. $summaryObj[1]->setAnnualLimit(1800);
  227. $summaryObj[1]->setEmployerAmount(80);
  228. $summaryObj[1]->setEmployeeAmount(70);
  229. $summaryObj[1]->setTotalAccrued(150);
  230. $summaryObj[1]->setTotalUsed(200);
  231. $saveObj = new HspSummary();
  232. $saveObj->saveHspSummary($summaryObj);
  233. $result = mysql_query("SELECT `annual_limit`, `employer_amount`, `employee_amount`, `total_accrued`, `total_used` FROM `hs_hr_hsp_summary`");
  234. $i = 0;
  235. while ($row = mysql_fetch_array($result)) {
  236. $actual[$i][0] = (int)$row[0];
  237. $actual[$i][1] = (int)$row[1];
  238. $actual[$i][2] = (int)$row[2];
  239. $actual[$i][3] = (int)$row[3];
  240. $actual[$i][4] = (int)$row[4];
  241. $i++;
  242. }
  243. $expected[0][0] = 1200;
  244. $expected[0][1] = 60;
  245. $expected[0][2] = 50;
  246. $expected[0][3] = 110;
  247. $expected[0][4] = 75;
  248. $expected[1][0] = 1800;
  249. $expected[1][1] = 80;
  250. $expected[1][2] = 70;
  251. $expected[1][3] = 150;
  252. $expected[1][4] = 200;
  253. $this->assertEquals($expected[0], $actual[0]);
  254. $this->assertEquals($actual[1], $expected[1]);
  255. }
  256. public function testSaveInitialSummaryForOneEmployee1() {
  257. HspSummary::saveInitialSummaryForOneEmployee(2);
  258. $result = mysql_query("SELECT COUNT(`employee_id`) FROM `hs_hr_hsp_summary` WHERE `employee_id` = '2'");
  259. $row = mysql_fetch_array($result, MYSQL_NUM);
  260. // There should be 4 records for employee 2
  261. $this->assertEquals(4, $row[0]);
  262. }
  263. public function testSaveInitialSummaryForOneEmployee2() {
  264. // Four records for employee-1 are added at setup
  265. HspSummary::saveInitialSummaryForOneEmployee(2);
  266. $result = mysql_query("SELECT `hsp_plan_id`, `hsp_plan_year` FROM `hs_hr_hsp_summary` WHERE `employee_id` = '2'");
  267. $k = 0;
  268. while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
  269. $actual[$k][0] = $row[0];
  270. $actual[$k][1] = $row[1];
  271. $k++;
  272. }
  273. $expected[0][0] = 1;
  274. $expected[0][1] = date('Y');
  275. $expected[1][0] = 3;
  276. $expected[1][1] = date('Y');
  277. $expected[2][0] = 1;
  278. $expected[2][1] = date('Y')+1;
  279. $expected[3][0] = 3;
  280. $expected[3][1] = date('Y')+1;
  281. for ($i=0; $i<4; $i++) {
  282. $this->assertEquals($expected[$i][0], $actual[$i][0]);
  283. $this->assertEquals($expected[$i][1], $actual[$i][1]);
  284. }
  285. }
  286. public function testGetYears() {
  287. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"),mysql_error());
  288. // Add 2 records to `hs_hr_hsp_summary`
  289. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (2, 1, 1, ". (date('Y') - 2) .", 1, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  290. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (3, 1, 1, ". (date('Y') + 5) .", 1, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  291. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (6, 1, 1, ". (date('Y') + 2) .", 1, 0.00, 0.00, 0.00, 0.00, 0.00)"),mysql_error());
  292. $year = (int) date('Y');
  293. $expected = array($year -2, $year - 1, $year, $year + 1, $year + 2, $year + 5);
  294. $result = HspSummary::getYears();
  295. $this->assertEquals($expected, $result);
  296. }
  297. public function testGetYearsAndPlans() {
  298. /* DB values are as follows
  299. * hsp_plan_id hsp_plan_year
  300. * 1 date('Y')
  301. * 3 date('Y')
  302. * 1 date('Y')+1
  303. * 3 date('Y')+1
  304. */
  305. /* Expected array should be as follows
  306. * $both[0]['year'] = date('Y');
  307. * $both[0]['plan'][0] = 1;
  308. * $both[0]['plan'][1] = 3;
  309. * $both[1]['year'] = date('Y')+1;
  310. * $both[1]['plan'][0] = 1;
  311. * $both[1]['plan'][1] = 3;
  312. */
  313. $both = HspSummary::getYearsAndPlans();
  314. $this->assertEquals(date('Y'), $both[0]['year']);
  315. $this->assertEquals(date('Y')+1, $both[1]['year']);
  316. $this->assertEquals(1, $both[0]['plan'][0]);
  317. $this->assertEquals(3, $both[0]['plan'][1]);
  318. $this->assertEquals(1, $both[1]['plan'][0]);
  319. $this->assertEquals(3, $both[1]['plan'][1]);
  320. }
  321. private function _backupTables($arrTableList) {
  322. foreach ($arrTableList as $table) {
  323. $result = mysql_query("SELECT * FROM `$table`");
  324. while($row = mysql_fetch_array($result, MYSQL_NUM)) {
  325. $this->oldValues["$table"][] = $row;
  326. }
  327. mysql_free_result($result);
  328. }
  329. }
  330. private function _restoreTables() {
  331. $arrTableList = array_keys($this->oldValues);
  332. if (count($arrTableList) == 0) {
  333. return;
  334. }
  335. foreach ($arrTableList as $table) {
  336. if ($table == 'AUTO_INC_PK_TABLE') {
  337. continue;
  338. }
  339. $this->assertTrue(mysql_query("INSERT INTO `$table` VALUES ('" . implode("', '", $this->oldValues["$table"]) . "')"), mysql_error());
  340. }
  341. }
  342. }
  343. // Call HspSummaryTest::main() if this source file is executed directly.
  344. if (PHPUnit_MAIN_METHOD == 'HspSummaryTest::main') {
  345. HspSummaryTest::main();
  346. }
  347. ?>