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/** 23 * Description of DataGroupServiceTest 24 * @group Core 25 */ 26class DataGroupServiceTest extends PHPUnit_Framework_TestCase { 27 28 private $service; 29 30 /** 31 * Set up method 32 */ 33 protected function setUp() { 34 $this->service = new DataGroupService(); 35 } 36 37 public function testGetDataGroupPermission() { 38 $dataGroupPermission = new DataGroupPermission(); 39 $dataGroupPermission->fromArray(array('id' => 2, 'user_role_id' => 1, 'data_group_id' => 1, 40 'can_read' => 1, 'can_create' => 1, 'can_update' => 1, 'can_delete' => 1, 'self' => 1)); 41 42 $dao = $this->getMockBuilder('DataGroupDao') 43 ->setMethods( array('getDataGroupPermission')) 44 ->getMock(); 45 $dao->expects($this->once()) 46 ->method('getDataGroupPermission') 47 ->with('test', 2, true) 48 ->will($this->returnValue($dataGroupPermission)); 49 50 $this->service->setDao($dao); 51 $result = $this->service->getDataGroupPermission('test', 2, true); 52 $this->assertEquals($dataGroupPermission, $result); 53 54 } 55 56 public function testGetDataGroups() { 57 $expected = new Doctrine_Collection('DataGroup'); 58 59 $dao = $this->getMockBuilder('DataGroupDao') 60 ->setMethods( array('getDataGroups')) 61 ->getMock(); 62 $dao->expects($this->once()) 63 ->method('getDataGroups') 64 ->will($this->returnValue($expected)); 65 66 $this->service->setDao($dao); 67 $result = $this->service->getDataGroups(); 68 $this->assertEquals($expected, $result); 69 } 70 71 public function testGetDataGroup() { 72 $expected = new DataGroup(); 73 $expected->fromArray(array('id' => 2, 'can_read' => 1, 'can_create' => 1, 'can_update' => 1, 'can_delete' => 1)); 74 75 $dao = $this->getMockBuilder('DataGroupDao') 76 ->setMethods( array('getDataGroup')) 77 ->getMock(); 78 $dao->expects($this->once()) 79 ->method('getDataGroup') 80 ->with('xyz') 81 ->will($this->returnValue($expected)); 82 83 $this->service->setDao($dao); 84 $result = $this->service->getDataGroup('xyz'); 85 $this->assertEquals($expected, $result); 86 } 87 88} 89