MixedTest.php 1.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
<?php

class Perms_MixedTest extends TikiTestCase
{
	function testFilterMixed() {
		$perms = new Perms;
		$perms->setResolverFactories( array(
			$resolver = $this->getMock( 'Perms_ResolverFactory' ),
			new Perms_ResolverFactory_StaticFactory( 'global', new Perms_Resolver_Default( true ) ),
		) );
		Perms::set( $perms );

		$resolver->expects( $this->any() )
			->method( 'getResolver' )
			->will( $this->returnValue( null ) );
		$resolver->expects( $this->exactly( 3 ) )
			->method( 'bulk' )
			->will( $this->returnValue( array() ) );
		$resolver->expects( $this->at( 0 ) )
			->method( 'bulk' )
			->will( $this->returnValue( array() ) )
			->with(
				$this->equalTo( array( 'type' => 'wiki page' ) ),
				$this->equalTo( 'object' ),
				$this->equalTo( array( 'A', 'B' ) )
			);
		$resolver->expects( $this->at( 1 ) )
			->method( 'bulk' )
			->will( $this->returnValue( array() ) )
			->with(
				$this->equalTo( array( 'type' => 'category' ) ),
				$this->equalTo( 'object' ),
				$this->equalTo( array( 10 ) )
			);

		$data = array(
			array( 'type' => 'wiki page', 'object' => 'A', 'creator' => 'abc' ),
			array( 'type' => 'wiki page', 'object' => 'B', 'creator' => 'abc' ),
			array( 'type' => 'category', 'object' => 10 ),
			array( 'type' => 'forumPost', 'object' => 12, 'author' => 'author' ),
		);

		$out = Perms::mixedFilter( array(), 'type', 'object', $data, array(
			'wiki page' => array( 'object' => 'object', 'type' => 'type', 'creator' => 'creator' ),
			'category' => array( 'object' => 'object', 'type' => 'type' ),
			'forumPost' => array( 'object' => 'object', 'type' => 'type', 'creator' => 'author' ),
		),
		array(
			'wiki page' => 'view',
			'category' => 'view_categories',
			'forumPost' => 'forum_post',
		) );

		$this->assertEquals( $data, $out );
	}
}