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_ResolverFactory_TestFactoryTest extends TikiTestCase
14{
15	/**
16	 * @dataProvider hashes
17	 */
18	function testHashCorrect($known, $in, $out)
19	{
20		$factory = new Perms_ResolverFactory_TestFactory($known, []);
21
22		$this->assertEquals($out, $factory->getHash($in));
23	}
24
25	function hashes()
26	{
27		return [
28			'empty' => [[], [], 'test:'],
29			'exact' => [['a'], ['a' => 1], 'test:1'],
30			'miss' => [['b'], ['a' => 1], 'test:'],
31			'multiple' => [['a', 'b'], ['a' => 1, 'b' => 2], 'test:1:2'],
32			'extra' => [['a'], ['a' => 1, 'b' => 2], 'test:1'],
33			'ordering' => [['a', 'b'], ['b' => 1, 'a' => 2], 'test:2:1'],
34		];
35	}
36
37	function testFetchKnown()
38	{
39		$factory = new Perms_ResolverFactory_TestFactory(
40			['a'],
41			['test:1' => $a = new Perms_Resolver_Default(true)]
42		);
43
44		$this->assertSame($a, $factory->getResolver(['a' => 1]));
45	}
46
47	function testFetchUnknown()
48	{
49		$factory = new Perms_ResolverFactory_TestFactory(
50			['a'],
51			['test:1' => $a = new Perms_Resolver_Default(true)]
52		);
53
54		$this->assertNull($factory->getResolver(['a' => 2]));
55	}
56}
57