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 AdminUserRoleTest
23 * @group Core
24 */
25class AdminUserRoleTest extends PHPUnit_Framework_TestCase {
26
27    /** @property AdminUserRole $adminUserRole */
28    private $adminUserRole;
29
30    /**
31     * Set up method
32     */
33    protected function setUp() {
34//        $this->fixture = sfConfig::get('sf_plugins_dir') . '/orangehrmCorePlugin/test/fixtures/UserRole.yml';
35//        TestDataService::truncateSpecificTables(array('SystemUser'));
36//        TestDataService::populate($this->fixture);
37
38        $this->adminUserRole = new AdminUserRole('Admin', new BasicUserRoleManager());
39    }
40
41    public function testGetSetEmployeeService() {
42        $mockService = $this->getMockBuilder('EmployeeService')->getMock();
43
44        $this->adminUserRole->setEmployeeService($mockService);
45        $this->assertEquals($mockService, $this->adminUserRole->getEmployeeService());
46    }
47
48    public function testGetSetSystemUserService() {
49        $mockService = $this->getMockBuilder('SystemUserService')->getMock();
50
51        $this->adminUserRole->setSystemUserService($mockService);
52        $this->assertEquals($mockService, $this->adminUserRole->getSystemUserService());
53    }
54
55    public function testGetSetLocationService() {
56        $mockService = $this->getMockBuilder('LocationService')->getMock();
57
58        $this->adminUserRole->setLocationService($mockService);
59        $this->assertEquals($mockService, $this->adminUserRole->getLocationService());
60    }
61
62    public function testGetSetOperationalCountryService() {
63        $mockService = $this->getMockBuilder('OperationalCountryService')->getMock();
64
65        $this->adminUserRole->setOperationalCountryService($mockService);
66        $this->assertEquals($mockService, $this->adminUserRole->getOperationalCountryService());
67    }
68
69    public function testGetAccessibleEmployeeIds() {
70        $mockService = $this->getMockBuilder('EmployeeService')->getMock();
71        $mockService->expects($this->once())
72                ->method('getEmployeeIdList')
73                ->with(false)
74                ->will($this->returnValue(array(1, 2, 3)));
75
76        $this->adminUserRole->setEmployeeService($mockService);
77        $empIds = $this->adminUserRole->getAccessibleEmployeeIds();
78        $this->assertEquals($empIds, array(1, 2, 3));
79    }
80
81    public function testGetAccessibleEmployeePropertyList() {
82        $mockService = $this->getMockBuilder('EmployeeService')->getMock();
83        $properties = array("empNumber", "firstName", "middleName", "lastName", "termination_id");
84        $propertyList = new Doctrine_Collection('Employee');
85        for ($i = 0; $i < 2; $i++) {
86            $employee = new Employee();
87            $employee->setEmployeeId($i + 1);
88            $employee->setFirstName("test name" . ($i + 1));
89            $propertyList->add($employee);
90        }
91
92        $mockService->expects($this->once())
93                ->method('getEmployeePropertyList')
94                ->with($properties, 'lastName', 'ASC', false)
95                ->will($this->returnValue($propertyList));
96
97        $this->adminUserRole->setEmployeeService($mockService);
98        $empProperties = $this->adminUserRole->getAccessibleEmployeePropertyList($properties, 'lastName', 'ASC');
99        $this->assertEquals($empProperties, $propertyList);
100    }
101
102    public function testGetAccessibleEmployees() {
103        $mockService = $this->getMockBuilder('EmployeeService')->getMock();
104        $employeeList = new Doctrine_Collection('Employee');
105        for ($i = 0; $i < 2; $i++) {
106            $employee = new Employee();
107            $employee->setEmployeeId($i + 1);
108            $employee->setEmpNumber($i + 1);
109            $employee->setFirstName("test name" . ($i + 1));
110            $employeeList->add($employee);
111        }
112
113        $mockService->expects($this->once())
114                ->method('getEmployeeList')
115                ->with('empNumber', 'ASC', true)
116                ->will($this->returnValue($employeeList));
117
118        $this->adminUserRole->setEmployeeService($mockService);
119        $employees = $this->adminUserRole->getAccessibleEmployees();
120        $this->assertEquals(2, count($employees));
121        for ($i = 0; $i < 2; $i++) {
122            $this->assertEquals($employees[$i + 1], $employeeList[$i]);
123        }
124    }
125
126    public function testGetAccessibleLocationIds() {
127        $mockService = $this->getMockBuilder('LocationService')->getMock();
128        $locationList = new Doctrine_Collection('Location');
129        for ($i = 0; $i < 3; $i++) {
130            $location = new Location();
131            $location->setId($i + 1);
132            $location->setName("test name" . ($i + 1));
133            $locationList->add($location);
134        }
135        $mockService->expects($this->once())
136                ->method('getLocationList')
137                ->will($this->returnValue($locationList));
138
139        $this->adminUserRole->setLocationService($mockService);
140        $locationIds = $this->adminUserRole->getAccessibleLocationIds(null, null);
141        $this->assertEquals($locationIds, array(1, 2, 3));
142    }
143
144    public function testGetAccessibleOperationalCountryIds() {
145        $mockService = $this->getMockBuilder('OperationalCountryService')->getMock();
146        $opCountryList = new Doctrine_Collection('OperationalCountry');
147        for ($i = 0; $i < 3; $i++) {
148            $operationalCountry = new OperationalCountry();
149            $operationalCountry->setId($i + 1);
150            $opCountryList->add($operationalCountry);
151        }
152
153        $mockService->expects($this->once())
154                ->method('getOperationalCountryList')
155                ->will($this->returnValue($opCountryList));
156
157        $this->adminUserRole->setOperationalCountryService($mockService);
158        $opCountryIds = $this->adminUserRole->getAccessibleOperationalCountryIds(null, null);
159        $this->assertEquals($opCountryIds, array(1, 2, 3));
160    }
161
162    public function testGetAccessibleSystemUserIds() {
163        $mockService = $this->getMockBuilder('SystemUserService')->getMock();
164
165        $mockService->expects($this->once())
166                ->method('getSystemUserIdList')
167                ->will($this->returnValue(array(1, 2, 3)));
168
169        $this->adminUserRole->setSystemUserService($mockService);
170        $userIds = $this->adminUserRole->getAccessibleSystemUserIds(null, null);
171        $this->assertEquals($userIds, array(1, 2, 3));
172    }
173
174    public function testGetAccessibleUserRoleIds() {
175        $mockService = $this->getMockBuilder('SystemUserService')->getMock();
176        $roleList = new Doctrine_Collection('SystemUser');
177        for ($i = 0; $i < 3; $i++) {
178            $userRole = new UserRole();
179            $userRole->setId($i + 1);
180            $userRole->setName('test'.($i + 1));
181            $roleList->add($userRole);
182        }
183
184        $mockService->expects($this->once())
185                ->method('getAssignableUserRoles')
186                ->will($this->returnValue($roleList));
187
188        $this->adminUserRole->setSystemUserService($mockService);
189        $roleIds = $this->adminUserRole->getAccessibleUserRoleIds(null, null);
190        $this->assertEquals($roleIds, array(1, 2, 3));
191    }
192
193}