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 ScreenPermissionDaoTest 23 * @group Core 24 */ 25class ScreenPermissionDaoTest extends PHPUnit_Framework_TestCase { 26 27 /** @property ScreenPermissionDao $dao */ 28 private $dao; 29 30 /** 31 * Set up method 32 */ 33 protected function setUp() { 34 $this->fixture = sfConfig::get('sf_plugins_dir') . '/orangehrmCorePlugin/test/fixtures/ScreenPermissionDao.yml'; 35 TestDataService::truncateSpecificTables(array('SystemUser')); 36 TestDataService::populate($this->fixture); 37 38 $this->dao = new ScreenPermissionDao(); 39 } 40 41 public function testGetScreenPermission() { 42 $permissions = $this->dao->getScreenPermissions('pim', 'viewEmployeeList', array('Admin')); 43 $this->assertNotNull($permissions); 44 $this->assertEquals(1, count($permissions)); 45 $this->verifyPermissions($permissions[0], true, true, true, true); 46 47 48 $permissions = $this->dao->getScreenPermissions('pim', 'viewEmployeeList', array('ESS')); 49 $this->assertNotNull($permissions); 50 $this->assertEquals(1, count($permissions)); 51 $this->verifyPermissions($permissions[0], false, false, false, false); 52 53 $permissions = $this->dao->getScreenPermissions('pim', 'viewEmployeeList', array('Supervisor')); 54 $this->assertNotNull($permissions); 55 $this->assertEquals(1, count($permissions)); 56 $this->verifyPermissions($permissions[0], true, false, true, false); 57 58 $permissions = $this->dao->getScreenPermissions('pim', 'viewEmployeeList', array('Admin', 'Supervisor', 'ESS')); 59 $this->assertNotNull($permissions); 60 $this->assertEquals(3, count($permissions)); 61 62 foreach($permissions as $permission) { 63 $roleId = $permission->getUserRoleId(); 64 if ($roleId == 1) { 65 // Admin 66 $this->verifyPermissions($permission, true, true, true, true); 67 } else if ($roleId == 2) { 68 // Supervisor 69 $this->verifyPermissions($permission, false, false, false, false); 70 } else if ($roleId == 3) { 71 // ESS 72 $this->verifyPermissions($permission, true, false, true, false); 73 } else { 74 $this->fail("Unexpected roleId=" . $roleId); 75 } 76 } 77 78 $permissions = $this->dao->getScreenPermissions('pim', 'viewEmployeeListNoneExisting', array('Admin', 'Supervisor', 'ESS')); 79 $this->assertTrue($permissions instanceof Doctrine_Collection); 80 $this->assertEquals(0, count($permissions)); 81 82 } 83 84 protected function verifyPermissions($permission, $read, $create, $update, $delete) { 85 $this->assertEquals($read, $permission->can_read); 86 $this->assertEquals($create, $permission->can_create); 87 $this->assertEquals($update, $permission->can_update); 88 $this->assertEquals($delete, $permission->can_delete); 89 } 90} 91 92