1<?php 2 3/** 4 * Class ilObjChatroomAdminAccessTest 5 * @author Thomas Joußen <tjoussen@gmx.de> 6 */ 7class ilObjChatroomAdminAccessTest extends PHPUnit_Framework_TestCase 8{ 9 10 /** 11 * @var ilObjChatroomAdminAccess 12 */ 13 protected $adminAccess; 14 15 /** 16 * @var PHPUnit_Framework_MockObject_MockObject 17 */ 18 protected $ilAccessMock; 19 20 protected function setUp() 21 { 22 if (defined('ILIAS_PHPUNIT_CONTEXT')) { 23 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php"); 24 ilUnitUtil::performInitialisation(); 25 } else { 26 chdir(dirname(__FILE__)); 27 chdir('../../../'); 28 } 29 30 require_once './Services/AccessControl/classes/class.ilAccessHandler.php'; 31 $this->ilAccessMock = $this->createMock('ilAccessHandler'); 32 global $ilAccess; 33 $ilAccess = $this->ilAccessMock; 34 35 require_once './Modules/Chatroom/classes/class.ilObjChatroomAdminAccess.php'; 36 $this->adminAccess = new ilObjChatroomAdminAccess(); 37 } 38 39 public function testInstanceOf() 40 { 41 $this->assertInstanceOf('ilObjectAccess', $this->adminAccess); 42 } 43 44 public function test_getCommands() 45 { 46 $expected = array( 47 array("permission" => "read", "cmd" => "view", "lang_var" => "enter", "default" => true), 48 array("permission" => "write", "cmd" => "edit", "lang_var" => "edit"), 49 array("permission" => "write", "cmd" => "versions", "lang_var" => "versions"), 50 ); 51 52 $commands = $this->adminAccess->_getCommands(); 53 54 $this->assertInternalType("array", $commands); 55 $this->assertEquals($expected, $commands); 56 } 57 58 public function test_checkGotoReturnFalse() 59 { 60 $this->ilAccessMock->expects($this->any())->method('checkAccess')->with($this->equalTo('visible'), $this->equalTo(''), $this->equalTo('1'))->will($this->returnValue(false)); 61 62 $this->assertFalse($this->adminAccess->_checkGoto('')); 63 $this->assertFalse($this->adminAccess->_checkGoto('chtr')); 64 $this->assertFalse($this->adminAccess->_checkGoto('chtr_')); 65 $this->assertFalse($this->adminAccess->_checkGoto('chtr_')); 66 $this->assertFalse($this->adminAccess->_checkGoto('chtr_test')); 67 $this->assertFalse($this->adminAccess->_checkGoto('chtr_1')); 68 } 69 70 public function test_checkGotoReturnTrue() 71 { 72 $this->ilAccessMock->expects($this->once())->method('checkAccess')->with($this->equalTo('visible'), $this->equalTo(''), $this->equalTo('5'))->will($this->returnValue(true)); 73 $this->assertTrue($this->adminAccess->_checkGoto('chtr_5')); 74 } 75 76 public function test_checkGotoIssueWithTargetNotAString() 77 { 78 $this->assertFalse($this->adminAccess->_checkGoto(array('chtr', '5'))); 79 $this->assertFalse($this->adminAccess->_checkGoto(5)); 80 } 81} 82