orangehrm /lib/models/eimadmin/EmailNotificationConfigurationTest.php

Language PHP Lines 179
MD5 Hash 7c1b0a9f8a4cd117f6986dfdc37f139e Estimated Cost $2,105 (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
<?php
/**
 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
 * all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA
 *
 */


// Call EmailNotificationConfigurationTest::main() if this source file is executed directly.
if (!defined("PHPUnit_MAIN_METHOD")) {
    define("PHPUnit_MAIN_METHOD", "EmailNotificationConfigurationTest::main");
}

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

require_once "testConf.php";

require_once 'EmailNotificationConfiguration.php';

/**
 * Test class for EmailNotificationConfiguration.
 * Generated by PHPUnit_Util_Skeleton on 2007-02-20 at 10:17:50.
 */
class EmailNotificationConfigurationTest extends PHPUnit_Framework_TestCase {
	public $classNotifications = null;
    public $connection = null;

    /**
     * Runs the test methods of this class.
     *
     * @access public
     * @static
     */
    public static function main() {
        require_once "PHPUnit/TextUI/TestRunner.php";

        $suite  = new PHPUnit_Framework_TestSuite("EmailNotificationConfigurationTest");
        $result = PHPUnit_TextUI_TestRunner::run($suite);
    }

    /**
     * Sets up the fixture, for example, open a network connection.
     * This method is called before a test is executed.
     *
     * @access protected
     */
    protected function setUp() {
		$this->classNotifications = new EmailNotificationConfiguration('USR010');

		$conf = new Conf();

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

		mysql_query("DELETE FROM `hs_hr_users` WHERE `id` = 'USR010'", $this->connection);
    	mysql_query("DELETE FROM `hs_hr_users` WHERE `id` = 'USR011'", $this->connection);

    	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')");
		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')");

    	mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 0, 1)");
    	mysql_query("INSERT INTO `hs_hr_mailnotifications` (`user_id`, `notification_type_id`, `status`) VALUES ('USR010', 2, 0)");
    }

    /**
     * Tears down the fixture, for example, close a network connection.
     * This method is called after a test is executed.
     *
     * @access protected
     */
    protected function tearDown() {
		mysql_query("DELETE FROM `hs_hr_users` WHERE `id` = 'USR010'", $this->connection);
    	mysql_query("DELETE FROM `hs_hr_users` WHERE `id` = 'USR011'", $this->connection);

		mysql_query("TRUNCATE TABLE `hs_hr_mailnotifications`", $this->connection);
    }

    public function testFetchNotifcationStatus() {
		$res = $this->classNotifications->fetchNotifcationStatus();

		$expected[0] = array('USR010', 0, 1);
		$expected[1] = array('USR010', 2, 0);

		$this->assertNotNull($res, 'Unexpected behavior');
		$this->assertTrue(is_array($res), 'Invalid result type');

		//$this->assertEquals(2, count($res), 'Invallid Number of records');

		for ($i=0; $i<count($expected); $i++) {
			$this->assertEquals($expected[$i][0], $res[$i]->getUserId(), 'Invallid employee id');
			$this->assertEquals($expected[$i][1], $res[$i]->getNotifcationTypeId(), 'Invallid notification');
			$this->assertEquals($expected[$i][2], $res[$i]->getNotificationStatus(), 'Invallid notification status');
		}
    }

    public function testFetchNotifcationStatus1() {
		$obj = new EmailNotificationConfiguration('USR092');

		$res = $obj->fetchNotifcationStatus();

		$this->assertNull($res, 'Unexpected behavior');
    }

    public function testUpdateNotificationStatus() {

		$this->classNotifications->setUserId('USR011');
 		$this->classNotifications->setNotifcationTypeId(0);
		$this->classNotifications->setNotificationStatus(1);

 		$res = $this->classNotifications->updateNotificationStatus();

 		$this->assertTrue($res, 'Update failed');

 		$res = $this->classNotifications->fetchNotifcationStatus();

		$expected[0] = array('USR011', 0, 1);

		$this->assertNotNull($res, 'Unexpected behavior');
		$this->assertTrue(is_array($res), 'Invalid result type');

		$this->assertEquals(1, count($res), 'Invallid Number of records');

		for ($i=0; $i<count($expected); $i++) {
			$this->assertEquals($expected[$i][0], $res[$i]->getUserId(), 'Invallid employee id');
			$this->assertEquals($expected[$i][1], $res[$i]->getNotifcationTypeId(), 'Invallid notification');
			$this->assertEquals($expected[$i][2], $res[$i]->getNotificationStatus(), 'Invallid notification status');
		}
    }


 	public function testUpdateNotificationStatus1() {

		$this->classNotifications->setUserId('USR010');
 		$this->classNotifications->setNotifcationTypeId(0);
		$this->classNotifications->setNotificationStatus(0);

 		$res = $this->classNotifications->updateNotificationStatus();

 		$this->assertTrue($res, 'Update failed');

		$res = $this->classNotifications->fetchNotifcationStatus();

		$expected[0] = array('USR010', 0, 0);
		$expected[1] = array('USR010', 2, 0);

		$this->assertNotNull($res, 'Unexpected behavior');
		$this->assertTrue(is_array($res), 'Invalid result type');

		$this->assertEquals(2, count($res), 'Invallid Number of records');

		for ($i=0; $i<count($res); $i++) {
			$this->assertEquals($expected[$i][0], $res[$i]->getUserId(), 'Invallid employee id');
			$this->assertEquals($expected[$i][1], $res[$i]->getNotifcationTypeId(), 'Invallid notification');
			$this->assertEquals($expected[$i][2], $res[$i]->getNotificationStatus(), 'Invallid notification status');
		}
    }

}

// Call EmailNotificationConfigurationTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "EmailNotificationConfigurationTest::main") {
    EmailNotificationConfigurationTest::main();
}
?>
Back to Top