1<?php
2
3/**
4 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
5 * all the essential functionalities required for any enterprise.
6 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
7 *
8 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
9 * the GNU General Public License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with this program;
17 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA  02110-1301, USA
19 */
20
21/**
22 * Description of SupervisorUserRoleTest
23 * @group Core
24 */
25class SupervisorUserRoleTest extends PHPUnit_Framework_TestCase {
26
27    /** @property AdminUserRole $supervisorUserRole */
28    private $supervisorUserRole;
29
30    /**
31     * Set up method
32     */
33    protected function setUp() {
34
35        $this->supervisorUserRole = new SupervisorUserRole('Supervisor', new BasicUserRoleManager());
36    }
37
38    public function testGetSetEmployeeService() {
39        $mockService = $this->getMockBuilder('EmployeeService')->getMock();
40
41        $this->supervisorUserRole->setEmployeeService($mockService);
42        $this->assertEquals($mockService, $this->supervisorUserRole->getEmployeeService());
43    }
44
45    public function testGetAccessibleEmployeeIds() {
46
47
48        $mockService = $this->getMockBuilder('EmployeeService')->getMock();
49        $mockService->expects($this->once())
50                ->method('getSubordinateIdListBySupervisorId')
51                ->will($this->returnValue(array(1, 3)));
52
53        $this->supervisorUserRole->setEmployeeNumber(1);
54        $this->supervisorUserRole->setEmployeeService($mockService);
55        $empIds = $this->supervisorUserRole->getAccessibleEmployeeIds();
56        $this->assertEquals($empIds, array(1, 3));
57    }
58
59    public function testGetAccessibleEmployeePropertyList() {
60        $mockService = $this->getMockBuilder('EmployeeService')->getMock();
61        $properties = array("empNumber", "firstName", "middleName", "lastName", "termination_id");
62        $propertyList = new Doctrine_Collection('Employee');
63        for ($i = 0; $i < 2; $i++) {
64            $employee = new Employee();
65            $employee->setEmployeeId($i + 1);
66            $employee->setFirstName("test name" . ($i + 1));
67            $propertyList->add($employee);
68        }
69
70        $mockService->expects($this->once())
71                ->method('getSubordinatePropertyListBySupervisorId')
72                ->with(1, $properties, 'lastName', 'ASC', true)
73                ->will($this->returnValue($propertyList));
74
75        $this->supervisorUserRole->setEmployeeNumber(1);
76        $this->supervisorUserRole->setEmployeeService($mockService);
77        $empProperties = $this->supervisorUserRole->getAccessibleEmployeePropertyList($properties, 'lastName', 'ASC');
78        $this->assertEquals($empProperties, $propertyList);
79    }
80
81    public function testGetAccessibleEmployees() {
82        $mockService = $this->getMockBuilder('EmployeeService')->getMock();
83        $employeeList = new Doctrine_Collection('Employee');
84        for ($i = 0; $i < 2; $i++) {
85            $employee = new Employee();
86            $employee->setEmployeeId($i + 1);
87            $employee->setEmpNumber($i + 1);
88            $employee->setFirstName("test name" . ($i + 1));
89            $employeeList->add($employee);
90        }
91
92        $mockService->expects($this->once())
93                ->method('getSubordinateList')
94                ->with(1, true)
95                ->will($this->returnValue($employeeList));
96
97        $this->supervisorUserRole->setEmployeeNumber(1);
98        $this->supervisorUserRole->setEmployeeService($mockService);
99        $employees = $this->supervisorUserRole->getAccessibleEmployees();
100        $this->assertEquals(2, count($employees));
101        for ($i = 0; $i < 2; $i++) {
102            $this->assertEquals($employees[$i + 1], $employeeList[$i]);
103        }
104    }
105//
106//    public function testGetAccessibleLocationIds() {
107//        $mockService = $this->getMockBuilder('LocationService')->getMock();
108//        $locationList = new Doctrine_Collection('Location');
109//        for ($i = 0; $i < 3; $i++) {
110//            $location = new Location();
111//            $location->setId($i + 1);
112//            $location->setName("test name" . $i + 1);
113//            $locationList->add($location);
114//        }
115//        $mockService->expects($this->once())
116//                ->method('getLocationList')
117//                ->will($this->returnValue($locationList));
118//
119//        $this->supervisorUserRole->setLocationService($mockService);
120//        $locationIds = $this->supervisorUserRole->getAccessibleLocationIds(null, null);
121//        $this->assertEquals($locationIds, array(1, 2, 3));
122//    }
123//
124//    public function testGetAccessibleOperationalCountryIds() {
125//        $mockService = $this->getMockBuilder('OperationalCountryService')->getMock();
126//        $opCountryList = new Doctrine_Collection('OperationalCountry');
127//        for ($i = 0; $i < 3; $i++) {
128//            $operationalCountry = new OperationalCountry();
129//            $operationalCountry->setId($i + 1);
130//            $opCountryList->add($operationalCountry);
131//        }
132//
133//        $mockService->expects($this->once())
134//                ->method('getOperationalCountryList')
135//                ->will($this->returnValue($opCountryList));
136//
137//        $this->supervisorUserRole->setOperationalCountryService($mockService);
138//        $opCountryIds = $this->supervisorUserRole->getAccessibleOperationalCountryIds(null, null);
139//        $this->assertEquals($opCountryIds, array(1, 2, 3));
140//    }
141//
142//    public function testGetAccessibleSystemUserIds() {
143//        $mockService = $this->getMockBuilder('SystemUserService')->getMock();
144//
145//        $mockService->expects($this->once())
146//                ->method('getSystemUserIdList')
147//                ->will($this->returnValue(array(1, 2, 3)));
148//
149//        $this->supervisorUserRole->setSystemUserService($mockService);
150//        $userIds = $this->supervisorUserRole->getAccessibleSystemUserIds(null, null);
151//        $this->assertEquals($userIds, array(1, 2, 3));
152//    }
153//
154//    public function testGetAccessibleUserRoleIds() {
155//        $mockService = $this->getMockBuilder('SystemUserService')->getMock();
156//        $roleList = new Doctrine_Collection('SystemUser');
157//        for ($i = 0; $i < 3; $i++) {
158//            $userRole = new UserRole();
159//            $userRole->setId($i + 1);
160//            $userRole->setName('test'.$i + 1);
161//            $roleList->add($userRole);
162//        }
163//
164//        $mockService->expects($this->once())
165//                ->method('getAssignableUserRoles')
166//                ->will($this->returnValue($roleList));
167//
168//        $this->supervisorUserRole->setSystemUserService($mockService);
169//        $roleIds = $this->supervisorUserRole->getAccessibleUserRoleIds(null, null);
170//        $this->assertEquals($roleIds, array(1, 2, 3));
171//    }
172
173}