orangehrm /lib/models/eimadmin/CompPropertyTest.php

Language PHP Lines 200
MD5 Hash bd2c6dedb0c4ed6361d9e74b8665ac71
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
194
195
196
197
198
199
<?php
// Call CompPropertyTest::main() if this source file is executed directly.
if (!defined('PHPUnit_MAIN_METHOD')) {
    define('PHPUnit_MAIN_METHOD', 'CompPropertyTest::main');
}

require_once "testConf.php";
require_once 'PHPUnit/Framework.php';
require_once 'CompProperty.php';

/**
 * Test class for CompProperty.
 * Generated by PHPUnit on 2008-02-22 at 12:54:05.
 */
class CompPropertyTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var    CompProperty
     * @access protected
     */
    protected $object;

    /**
     * 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('CompPropertyTest');
        $result = PHPUnit_TextUI_TestRunner::run($suite);
    }

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     *
     * @access protected
     */
    protected function setUp()
    {
        $conf = new Conf();
        $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
        mysql_select_db($conf->dbname);

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


    }

    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     *
     * @access protected
     */
    protected function tearDown()
    {
        mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);
        mysql_close($this->connection);
    }

    /**
     * @todo Implement testAddProperty().
     */
    public function testAddProperty() {

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

        $prop = new CompProperty();
        $prop->setPropName('new Item');
        $prop->addProperty();

        $res=mysql_query("SELECT * FROM `hs_hr_comp_property`", $this->connection);

        $row=mysql_fetch_array($res);

        $this->assertEquals($row['prop_name'],'new Item');
        $this->assertEquals($row['prop_id'],'1');
    }

    /**
     * @todo Implement testEditProperty().
     */
    public function testEditProperty() {
        mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);

        mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item','1')", $this->connection);

        $prop = new CompProperty();
        $prop->setPropName('new Item Edited');
        $prop->editProperty(1);



        $res=mysql_query("SELECT * FROM `hs_hr_comp_property`", $this->connection);

        $row=mysql_fetch_array($res);

        $this->assertEquals($row['prop_name'],'new Item Edited');
        $this->assertEquals($row['emp_id'],'1');
        $this->assertEquals($row['prop_id'],'1');
    }

    /**
     * @todo Implement testGetPropertyList().
     */
    public function testGetPropertyList() {
        mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);

        mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item','1')", $this->connection);
        mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item 2','10')", $this->connection);

        $prop = new CompProperty();
        $prop->setPropName('new Item Edited');
        $rows=$prop->getPropertyList();


        $this->assertEquals($rows[0]['prop_name'],'new Item');
        $this->assertEquals($rows[0]['emp_id'],'1');
        $this->assertEquals($rows[0]['prop_id'],'1');


        $this->assertEquals($rows[1]['prop_name'],'new Item 2');
        $this->assertEquals($rows[1]['emp_id'],'10');
        $this->assertEquals($rows[1]['prop_id'],'2');
    }

    /**
     * @todo Implement testEditPropertyList().
     */
    public function testEditPropertyList() {
        mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);

        mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item','1')", $this->connection);
        mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item 2','10')", $this->connection);

        $prop = new CompProperty();
        $prop->setEditPropIds(array('1','2'));
        $prop->setEditEmpIds(array('5','6'));
        $prop->editPropertyList();

        $res=mysql_query("SELECT * FROM `hs_hr_comp_property`", $this->connection);

        $row=mysql_fetch_array($res);

        $this->assertEquals($row['prop_name'],'new Item');
        $this->assertEquals($row['emp_id'],'5');
        $this->assertEquals($row['prop_id'],'1');

        $row=mysql_fetch_array($res);

        $this->assertEquals($row['prop_name'],'new Item 2');
        $this->assertEquals($row['emp_id'],'6');
        $this->assertEquals($row['prop_id'],'2');
    }

    /**
     * @todo Implement testDeleteProperties().
     */
    public function testDeleteProperties() {
        mysql_query("TRUNCATE TABLE `hs_hr_comp_property`", $this->connection);

        mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item','1')", $this->connection);
        mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item 2','10')", $this->connection);
        mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item 3','11')", $this->connection);
        mysql_query("INSERT INTO `hs_hr_comp_property` (`prop_name`,`emp_id`) VALUES ('new Item 5','20')", $this->connection);

        $prop = new CompProperty();
        $prop->setDeleteList(array('2','3'));
        $prop->deleteProperties();

        $res=mysql_query("SELECT * FROM `hs_hr_comp_property`", $this->connection);

        $numRows= mysql_num_rows($res);
        $this->assertEquals($numRows,2,'Number of rows invalid');

        $row=mysql_fetch_array($res);

        $this->assertEquals($row['prop_name'],'new Item');
        $this->assertEquals($row['emp_id'],'1');
        $this->assertEquals($row['prop_id'],'1');

        $row=mysql_fetch_array($res);

        $this->assertEquals($row['prop_name'],'new Item 5');
        $this->assertEquals($row['emp_id'],'20');
        $this->assertEquals($row['prop_id'],'4');
    }
}

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