PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/models/benefits/mail/HspMailNotificationTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 193 lines | 125 code | 40 blank | 28 comment | 1 complexity | ba688bf4bebd0486e6ce8f8f22fbdc1c 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. if (!defined('PHPUnit_MAIN_METHOD')) {
  3. define('PHPUnit_MAIN_METHOD', 'HspMailNotificationTest::main');
  4. }
  5. require_once "PHPUnit/Framework/TestCase.php";
  6. require_once "PHPUnit/Framework/TestSuite.php";
  7. require_once "testConf.php";
  8. require_once ROOT_PATH."/lib/confs/Conf.php";
  9. require_once ROOT_PATH . '/lib/models/benefits/mail/HspMailNotification.php';
  10. require_once ROOT_PATH . '/lib/models/benefits/HspPaymentRequest.php';
  11. require_once ROOT_PATH . '/lib/models/eimadmin/EmailNotificationConfiguration.php';
  12. class HspMailNotificationTest extends PHPUnit_Framework_TestCase {
  13. private $hspMailNotification;
  14. private $hspPaymentRequest;
  15. private $connection;
  16. private $employeeFields;
  17. protected function setUp() {
  18. $this->employeeFields = "`emp_number`, `employee_id`, `emp_lastname`, `emp_firstname`, `emp_middle_name`, `emp_nick_name`, " .
  19. "`emp_smoker`, `ethnic_race_code`, `emp_birthday`, `nation_code`, `emp_gender`, `emp_marital_status`, " .
  20. "`emp_ssn_num`, `emp_sin_num`, `emp_other_id`, `emp_dri_lice_num`, `emp_dri_lice_exp_date`, `emp_military_service`, " .
  21. "`emp_status`, `job_title_code`, `eeo_cat_code`, `work_station`, `emp_street1`, `emp_street2`, " .
  22. "`city_code`, `coun_code`, `provin_code`, `emp_zipcode`, `emp_hm_telephone`, `emp_mobile`, " .
  23. "`emp_work_telephone`, `emp_work_email`, `sal_grd_code`, `joined_date`, `emp_oth_email`";
  24. $this -> hspMailNotification = new HspMailNotification();
  25. $this -> hspPaymentRequest = new HspPaymentRequest();
  26. $conf = new Conf();
  27. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  28. mysql_select_db($conf->dbname);
  29. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_employee`"), mysql_error());
  30. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (10, '010', 'Notharis', 'Chuck', '', 'Arnold', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', 'AF', '', '', '', '', '', 'dimuthu@orangehrm.com', NULL, NULL, 'dsamarasekara@gmail.com')"), mysql_error());
  31. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ($this->employeeFields) VALUES (11, '011', 'Subasinghe', 'Arnold', '', 'Arnold', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', 'AF', '', '', '', '', '', 'dimuthu@orangehrm.com', NULL, NULL, 'dsamarasekara@gmail.com')"), mysql_error());
  32. $this->assertTrue(mysql_query("DELETE FROM `hs_hr_users` WHERE `id` IN ('USR011', 'USR010')"), mysql_error());
  33. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_users` (`id`, `user_name`, `email1`) VALUES ('USR010', 'chuck', 'dimuthu@beyondm.net')"), mysql_error());
  34. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_users` (`id`, `user_name`, `email1`) VALUES ('USR011', 'arnorld', 'dimuthu@beyondm.net')"), mysql_error());
  35. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_mailnotifications`"), mysql_error());
  36. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR011', -1, 1)"), mysql_error());
  37. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 0, 1)"), mysql_error());
  38. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 1, 1)"), mysql_error());
  39. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 2, 1)"), mysql_error());
  40. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 3, 1)"), mysql_error());
  41. }
  42. protected function tearDown() {
  43. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_employee`"), mysql_error());
  44. $this->assertTrue(mysql_query("DELETE FROM `hs_hr_users` WHERE `id` IN ('USR010', 'USR011')"), mysql_error());
  45. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_mailnotifications`"), mysql_error());
  46. }
  47. /**
  48. *
  49. */
  50. public function testGetEmployeeName() {
  51. $this -> assertEquals($this -> hspMailNotification -> _getEmployeeName('011'), 'Arnold Subasinghe');
  52. $this -> assertEquals($this ->hspMailNotification -> _getEmployeeName('999'), '');
  53. }
  54. /**
  55. *
  56. */
  57. public function testGetNotificationAddress() {
  58. $type1 = EmailNotificationConfiguration :: EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_REJECTED;
  59. $type2 = EmailNotificationConfiguration :: EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_CANCELLED;
  60. $type3 = EmailNotificationConfiguration :: EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_PENDING_APPROVAL;
  61. $type4 = EmailNotificationConfiguration :: EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_APPROVED;
  62. $type5 = EmailNotificationConfiguration :: EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_HSP;
  63. $email = $this -> hspMailNotification -> _getNotificationAddress($type1);
  64. //$this -> assertTrue(is_array($email));
  65. $this -> assertEquals('dimuthu@beyondm.net', is_array($email));
  66. $email = $this -> hspMailNotification -> _getNotificationAddress($type2);
  67. $this -> assertTrue(is_array($email));
  68. $this -> assertEquals('dimuthu@beyondm.net', is_array($email));
  69. $email = $this -> hspMailNotification -> _getNotificationAddress($type3);
  70. $this -> assertTrue(is_array($email));
  71. $this -> assertEquals('dimuthu@beyondm.net', is_array($email));
  72. $email = $this -> hspMailNotification -> _getNotificationAddress($type4);
  73. $this -> assertTrue(is_array($email));
  74. $this -> assertEquals('dimuthu@beyondm.net', is_array($email));
  75. $email = $this -> hspMailNotification -> _getNotificationAddress($type5);
  76. $this -> assertTrue(is_array($email));
  77. $this -> assertEquals('dimuthu@beyondm.net', is_array($email));
  78. }
  79. /**
  80. *
  81. */
  82. public function testGetPaymentRequestSubject() {
  83. $expected = 'HSP Notification - dimuthu has submitted a request';
  84. $this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentRequestSubject("dimuthu"));
  85. $expected = 'HSP Notification - dimuthu samarasekara has submitted a request';
  86. $this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentRequestSubject("dimuthu samarasekara"));
  87. $expected = 'HSP Notification - Employee has submitted a request';
  88. $this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentRequestSubject(''));
  89. }
  90. /**
  91. *
  92. */
  93. public function testGetPaymentRequestMsg() {
  94. $result = $this -> hspMailNotification -> _getPaymentRequestMsg("dimuthu", '2007-01-01', 'flu');
  95. $this->assertEquals(preg_match("/#employee/", $result), 0);
  96. $this->assertEquals(preg_match("/##dateInquired/", $result), 0);
  97. $this->assertEquals(preg_match("/#empName/", $result), 0);
  98. $this->assertEquals(preg_match("/#expenseDesc/", $result), 0);
  99. }
  100. /**
  101. *
  102. */
  103. public function testGetEmployeeAddress() {
  104. $address = $this -> hspMailNotification -> getEmployeeAddress('011');
  105. $this -> assertTrue(is_array($address));
  106. $this -> assertEquals(count($address), 2);
  107. $this -> assertEquals("dimuthu@orangehrm.com", $address[0]);
  108. $this -> assertEquals("dsamarasekara@gmail.com", $address[1]);
  109. $address = $this -> hspMailNotification -> getEmployeeAddress('777');
  110. $this -> assertFalse(isset($address));
  111. }
  112. /**
  113. *
  114. */
  115. public function testGetPaymentAcceptSubject() {
  116. $expected = 'HSP Notification - Payment Request Approved';
  117. $this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentAcceptSubject());
  118. }
  119. /**
  120. *
  121. */
  122. public function testGetPaymentAcceptMsg() {
  123. $result = $this -> hspMailNotification -> _getPaymentAcceptMsg("dimuthu", '2007-01-01', 'flu', 'person inquire', 150, '2007-02-01', 'http://www.example.com');
  124. $this->assertEquals(preg_match("/#firstName/", $result), 0);
  125. $this->assertEquals(preg_match("/##dateInquired/", $result), 0);
  126. $this->assertEquals(preg_match("/#employee/", $result), 0);
  127. $this->assertEquals(preg_match("/#expenseDesc/", $result), 0);
  128. $this->assertEquals(preg_match("/#personInquiring/", $result), 0);
  129. $this->assertEquals(preg_match("/#amount/", $result), 0);
  130. $this->assertEquals(preg_match("/#paidDate/", $result), 0);
  131. $this->assertEquals(preg_match("/#link/", $result), 0);
  132. }
  133. /**
  134. *
  135. */
  136. public function testGetPaymentDenySubject() {
  137. $expected = 'HSP Notification - Payment Request Denied';
  138. $this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentDenySubject());
  139. }
  140. /**
  141. *
  142. */
  143. public function testGetPaymentDeleteSubject() {
  144. $expected = 'HSP Notification - Payment Request Deleted';
  145. $this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentRequestDeleteSubject());
  146. }
  147. public static function main() {
  148. require_once 'PHPUnit/TextUI/TestRunner.php';
  149. $suite = new PHPUnit_Framework_TestSuite('HspMailNotficationTest');
  150. $result = PHPUnit_TextUI_TestRunner::run($suite);
  151. }
  152. }
  153. ?>