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

Language PHP Lines 194
MD5 Hash ba688bf4bebd0486e6ce8f8f22fbdc1c Estimated Cost $2,993 (why?)
Repository https://bitbucket.org/wildanm/orangehrm View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
if (!defined('PHPUnit_MAIN_METHOD')) {
    define('PHPUnit_MAIN_METHOD', 'HspMailNotificationTest::main');
}

require_once "PHPUnit/Framework/TestCase.php";
require_once "PHPUnit/Framework/TestSuite.php";

require_once "testConf.php";
require_once ROOT_PATH."/lib/confs/Conf.php";

require_once ROOT_PATH . '/lib/models/benefits/mail/HspMailNotification.php';
require_once ROOT_PATH . '/lib/models/benefits/HspPaymentRequest.php';
require_once ROOT_PATH . '/lib/models/eimadmin/EmailNotificationConfiguration.php';


class HspMailNotificationTest extends PHPUnit_Framework_TestCase {

	private $hspMailNotification;
	private $hspPaymentRequest;
	private $connection;
	private $employeeFields;

	protected function setUp() {
		$this->employeeFields = "`emp_number`, `employee_id`, `emp_lastname`, `emp_firstname`, `emp_middle_name`, `emp_nick_name`, " .
								"`emp_smoker`, `ethnic_race_code`, `emp_birthday`, `nation_code`, `emp_gender`, `emp_marital_status`, " .
								"`emp_ssn_num`, `emp_sin_num`, `emp_other_id`, `emp_dri_lice_num`, `emp_dri_lice_exp_date`, `emp_military_service`, " .
								"`emp_status`, `job_title_code`, `eeo_cat_code`, `work_station`, `emp_street1`, `emp_street2`, " .
								"`city_code`, `coun_code`, `provin_code`, `emp_zipcode`, `emp_hm_telephone`, `emp_mobile`, " .
								"`emp_work_telephone`, `emp_work_email`, `sal_grd_code`, `joined_date`, `emp_oth_email`";

		$this -> hspMailNotification = new HspMailNotification();
		$this -> hspPaymentRequest = new HspPaymentRequest();

		$conf = new Conf();
   		$this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
       	mysql_select_db($conf->dbname);

       	$this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_employee`"), mysql_error());

		$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());
		$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());

		$this->assertTrue(mysql_query("DELETE FROM `hs_hr_users` WHERE `id` IN ('USR011', 'USR010')"), mysql_error());
		$this->assertTrue(mysql_query("INSERT INTO `hs_hr_users` (`id`, `user_name`, `email1`) VALUES ('USR010', 'chuck', 'dimuthu@beyondm.net')"), mysql_error());
		$this->assertTrue(mysql_query("INSERT INTO `hs_hr_users` (`id`, `user_name`, `email1`) VALUES ('USR011', 'arnorld', 'dimuthu@beyondm.net')"), mysql_error());

		$this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_mailnotifications`"), mysql_error());
    	$this->assertTrue(mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR011', -1, 1)"), mysql_error());
    	$this->assertTrue(mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 0, 1)"), mysql_error());
    	$this->assertTrue(mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 1, 1)"), mysql_error());
    	$this->assertTrue(mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 2, 1)"), mysql_error());
    	$this->assertTrue(mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 3, 1)"), mysql_error());
	}

	protected function tearDown() {
		$this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_employee`"), mysql_error());
		$this->assertTrue(mysql_query("DELETE FROM `hs_hr_users` WHERE `id` IN ('USR010',  'USR011')"), mysql_error());
		$this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_mailnotifications`"), mysql_error());
	}

	/**
	*
	*/
	public function testGetEmployeeName() {
		$this -> assertEquals($this -> hspMailNotification -> _getEmployeeName('011'), 'Arnold Subasinghe');

		$this -> assertEquals($this ->hspMailNotification -> _getEmployeeName('999'), '');
	}

	/**
	*
	*/
	public function testGetNotificationAddress() {

		$type1 = EmailNotificationConfiguration :: EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_REJECTED;
		$type2 = EmailNotificationConfiguration :: EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_CANCELLED;
		$type3 = EmailNotificationConfiguration :: EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_PENDING_APPROVAL;
		$type4 = EmailNotificationConfiguration :: EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_APPROVED;
		$type5 = EmailNotificationConfiguration :: EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_HSP;

		$email = $this -> hspMailNotification -> _getNotificationAddress($type1);
		//$this -> assertTrue(is_array($email));
		$this -> assertEquals('dimuthu@beyondm.net', is_array($email));

		$email = $this -> hspMailNotification -> _getNotificationAddress($type2);
		$this -> assertTrue(is_array($email));
		$this -> assertEquals('dimuthu@beyondm.net', is_array($email));

		$email = $this -> hspMailNotification -> _getNotificationAddress($type3);
		$this -> assertTrue(is_array($email));
		$this -> assertEquals('dimuthu@beyondm.net', is_array($email));

		$email = $this -> hspMailNotification -> _getNotificationAddress($type4);
		$this -> assertTrue(is_array($email));
		$this -> assertEquals('dimuthu@beyondm.net', is_array($email));

		$email = $this -> hspMailNotification -> _getNotificationAddress($type5);
		$this -> assertTrue(is_array($email));
		$this -> assertEquals('dimuthu@beyondm.net', is_array($email));

	}

	/**
	*
	*/
	public function testGetPaymentRequestSubject() {
		$expected = 'HSP Notification - dimuthu has submitted a request';
		$this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentRequestSubject("dimuthu"));

		$expected = 'HSP Notification - dimuthu samarasekara has submitted a request';
		$this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentRequestSubject("dimuthu samarasekara"));

		$expected = 'HSP Notification - Employee has submitted a request';
		$this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentRequestSubject(''));
	}

	/**
	*
	*/
	public function testGetPaymentRequestMsg() {
		$result = $this -> hspMailNotification -> _getPaymentRequestMsg("dimuthu", '2007-01-01', 'flu');
		$this->assertEquals(preg_match("/#employee/", $result), 0);
		$this->assertEquals(preg_match("/##dateInquired/", $result), 0);
		$this->assertEquals(preg_match("/#empName/", $result), 0);
		$this->assertEquals(preg_match("/#expenseDesc/", $result), 0);
	}

	/**
	 *
	 */
	public function testGetEmployeeAddress() {
		$address = $this -> hspMailNotification -> getEmployeeAddress('011');

		$this -> assertTrue(is_array($address));
		$this -> assertEquals(count($address), 2);
		$this -> assertEquals("dimuthu@orangehrm.com", $address[0]);
		$this -> assertEquals("dsamarasekara@gmail.com", $address[1]);

		$address = $this -> hspMailNotification -> getEmployeeAddress('777');

		$this -> assertFalse(isset($address));
	}

	/**
	*
	*/
	public function testGetPaymentAcceptSubject() {
		$expected = 'HSP Notification - Payment Request Approved';
		$this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentAcceptSubject());
	 }

	/**
	*
	*/
	public function testGetPaymentAcceptMsg() {
		$result = $this -> hspMailNotification -> _getPaymentAcceptMsg("dimuthu", '2007-01-01', 'flu', 'person inquire', 150, '2007-02-01', 'http://www.example.com');
		$this->assertEquals(preg_match("/#firstName/", $result), 0);
		$this->assertEquals(preg_match("/##dateInquired/", $result), 0);
		$this->assertEquals(preg_match("/#employee/", $result), 0);
		$this->assertEquals(preg_match("/#expenseDesc/", $result), 0);
		$this->assertEquals(preg_match("/#personInquiring/", $result), 0);
		$this->assertEquals(preg_match("/#amount/", $result), 0);
		$this->assertEquals(preg_match("/#paidDate/", $result), 0);
		$this->assertEquals(preg_match("/#link/", $result), 0);
	 }

	/**
	*
	*/
	public function testGetPaymentDenySubject() {
		$expected = 'HSP Notification - Payment Request Denied';
		$this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentDenySubject());
	 }

	/**
	*
	*/
	public function testGetPaymentDeleteSubject() {
		$expected = 'HSP Notification - Payment Request Deleted';
		$this -> assertEquals($expected, $this -> hspMailNotification -> _getPaymentRequestDeleteSubject());
	}

	public static function main() {
        	require_once 'PHPUnit/TextUI/TestRunner.php';

        	$suite  = new PHPUnit_Framework_TestSuite('HspMailNotficationTest');
        	$result = PHPUnit_TextUI_TestRunner::run($suite);
	}


}
?>
Back to Top