PageRenderTime 24ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/models/eimadmin/EmailNotificationConfigurationTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 178 lines | 90 code | 45 blank | 43 comment | 6 complexity | 7c1b0a9f8a4cd117f6986dfdc37f139e 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 EmailNotificationConfigurationTest::main() if this source file is executed directly.
  21. if (!defined("PHPUnit_MAIN_METHOD")) {
  22. define("PHPUnit_MAIN_METHOD", "EmailNotificationConfigurationTest::main");
  23. }
  24. require_once "PHPUnit/Framework/TestCase.php";
  25. require_once "PHPUnit/Framework/TestSuite.php";
  26. require_once "testConf.php";
  27. require_once 'EmailNotificationConfiguration.php';
  28. /**
  29. * Test class for EmailNotificationConfiguration.
  30. * Generated by PHPUnit_Util_Skeleton on 2007-02-20 at 10:17:50.
  31. */
  32. class EmailNotificationConfigurationTest extends PHPUnit_Framework_TestCase {
  33. public $classNotifications = null;
  34. public $connection = null;
  35. /**
  36. * Runs the test methods of this class.
  37. *
  38. * @access public
  39. * @static
  40. */
  41. public static function main() {
  42. require_once "PHPUnit/TextUI/TestRunner.php";
  43. $suite = new PHPUnit_Framework_TestSuite("EmailNotificationConfigurationTest");
  44. $result = PHPUnit_TextUI_TestRunner::run($suite);
  45. }
  46. /**
  47. * Sets up the fixture, for example, open a network connection.
  48. * This method is called before a test is executed.
  49. *
  50. * @access protected
  51. */
  52. protected function setUp() {
  53. $this->classNotifications = new EmailNotificationConfiguration('USR010');
  54. $conf = new Conf();
  55. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  56. mysql_select_db($conf->dbname);
  57. mysql_query("DELETE FROM `hs_hr_users` WHERE `id` = 'USR010'", $this->connection);
  58. mysql_query("DELETE FROM `hs_hr_users` WHERE `id` = 'USR011'", $this->connection);
  59. mysql_query("INSERT INTO `hs_hr_users` VALUES ('USR010', 'demo1', 'fe01ce2a7fbac8fafaed7c982a04e229', 'Admin', NULL, NULL, NULL, 'Yes', '1', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'Enabled', NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 'USG001')");
  60. mysql_query("INSERT INTO `hs_hr_users` VALUES ('USR011', 'demo2', 'fe01ce2a7fbac8fafaed7c982a04e229', 'Admin', NULL, NULL, NULL, 'Yes', '1', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'Enabled', NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 'USG001')");
  61. mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 0, 1)");
  62. mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 2, 0)");
  63. }
  64. /**
  65. * Tears down the fixture, for example, close a network connection.
  66. * This method is called after a test is executed.
  67. *
  68. * @access protected
  69. */
  70. protected function tearDown() {
  71. mysql_query("DELETE FROM `hs_hr_users` WHERE `id` = 'USR010'", $this->connection);
  72. mysql_query("DELETE FROM `hs_hr_users` WHERE `id` = 'USR011'", $this->connection);
  73. mysql_query("TRUNCATE TABLE `hs_hr_mailnotifications`", $this->connection);
  74. }
  75. public function testFetchNotifcationStatus() {
  76. $res = $this->classNotifications->fetchNotifcationStatus();
  77. $expected[0] = array('USR010', 0, 1);
  78. $expected[1] = array('USR010', 2, 0);
  79. $this->assertNotNull($res, 'Unexpected behavior');
  80. $this->assertTrue(is_array($res), 'Invalid result type');
  81. //$this->assertEquals(2, count($res), 'Invallid Number of records');
  82. for ($i=0; $i<count($expected); $i++) {
  83. $this->assertEquals($expected[$i][0], $res[$i]->getUserId(), 'Invallid employee id');
  84. $this->assertEquals($expected[$i][1], $res[$i]->getNotifcationTypeId(), 'Invallid notification');
  85. $this->assertEquals($expected[$i][2], $res[$i]->getNotificationStatus(), 'Invallid notification status');
  86. }
  87. }
  88. public function testFetchNotifcationStatus1() {
  89. $obj = new EmailNotificationConfiguration('USR092');
  90. $res = $obj->fetchNotifcationStatus();
  91. $this->assertNull($res, 'Unexpected behavior');
  92. }
  93. public function testUpdateNotificationStatus() {
  94. $this->classNotifications->setUserId('USR011');
  95. $this->classNotifications->setNotifcationTypeId(0);
  96. $this->classNotifications->setNotificationStatus(1);
  97. $res = $this->classNotifications->updateNotificationStatus();
  98. $this->assertTrue($res, 'Update failed');
  99. $res = $this->classNotifications->fetchNotifcationStatus();
  100. $expected[0] = array('USR011', 0, 1);
  101. $this->assertNotNull($res, 'Unexpected behavior');
  102. $this->assertTrue(is_array($res), 'Invalid result type');
  103. $this->assertEquals(1, count($res), 'Invallid Number of records');
  104. for ($i=0; $i<count($expected); $i++) {
  105. $this->assertEquals($expected[$i][0], $res[$i]->getUserId(), 'Invallid employee id');
  106. $this->assertEquals($expected[$i][1], $res[$i]->getNotifcationTypeId(), 'Invallid notification');
  107. $this->assertEquals($expected[$i][2], $res[$i]->getNotificationStatus(), 'Invallid notification status');
  108. }
  109. }
  110. public function testUpdateNotificationStatus1() {
  111. $this->classNotifications->setUserId('USR010');
  112. $this->classNotifications->setNotifcationTypeId(0);
  113. $this->classNotifications->setNotificationStatus(0);
  114. $res = $this->classNotifications->updateNotificationStatus();
  115. $this->assertTrue($res, 'Update failed');
  116. $res = $this->classNotifications->fetchNotifcationStatus();
  117. $expected[0] = array('USR010', 0, 0);
  118. $expected[1] = array('USR010', 2, 0);
  119. $this->assertNotNull($res, 'Unexpected behavior');
  120. $this->assertTrue(is_array($res), 'Invalid result type');
  121. $this->assertEquals(2, count($res), 'Invallid Number of records');
  122. for ($i=0; $i<count($res); $i++) {
  123. $this->assertEquals($expected[$i][0], $res[$i]->getUserId(), 'Invallid employee id');
  124. $this->assertEquals($expected[$i][1], $res[$i]->getNotifcationTypeId(), 'Invallid notification');
  125. $this->assertEquals($expected[$i][2], $res[$i]->getNotificationStatus(), 'Invallid notification status');
  126. }
  127. }
  128. }
  129. // Call EmailNotificationConfigurationTest::main() if this source file is executed directly.
  130. if (PHPUnit_MAIN_METHOD == "EmailNotificationConfigurationTest::main") {
  131. EmailNotificationConfigurationTest::main();
  132. }
  133. ?>