1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8/** 9 * @group unit 10 * 11 */ 12 13class Perms_CheckSequenceTest extends TikiTestCase 14{ 15 private $mockA; 16 private $mockB; 17 18 function setUp() 19 { 20 $perms = new Perms; 21 $perms->setResolverFactories( 22 [ 23 new Perms_ResolverFactory_StaticFactory( 24 'static', 25 new Perms_Resolver_Static( 26 ['Admins' => ['admin_wiki'],] 27 ) 28 ) 29 ] 30 ); 31 32 $perms->setGroups(['Admins']); 33 $perms->setCheckSequence( 34 [ 35 new Perms_Check_Direct, 36 $this->mockA = $this->createMock('Perms_Check'), 37 $this->mockB = $this->createMock('Perms_Check'), 38 ] 39 ); 40 Perms::set($perms); 41 } 42 43 function testOnlyFirstCalledWhenGranted() 44 { 45 $this->mockA->expects($this->never()) 46 ->method('check'); 47 $this->mockB->expects($this->never()) 48 ->method('check'); 49 50 $this->assertTrue(Perms::get()->admin_wiki); 51 } 52 53 function testFirstFallbackHandles() 54 { 55 $this->mockA->expects($this->once()) 56 ->method('check') 57 ->will($this->returnValue(true)); 58 $this->mockB->expects($this->never()) 59 ->method('check'); 60 61 $this->assertTrue(Perms::get()->view); 62 } 63 64 function testNoneCatching() 65 { 66 $this->mockA->expects($this->once()) 67 ->method('check') 68 ->will($this->returnValue(false)); 69 $this->mockB->expects($this->once()) 70 ->method('check') 71 ->will($this->returnValue(false)); 72 73 $this->assertFalse(Perms::get()->view); 74 } 75} 76