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
8class Search_Formatter_DataSourceTest extends PHPUnit_Framework_TestCase
9{
10	private $wikiSource;
11	private $categorySource;
12	private $permissionSource;
13
14	function setUp()
15	{
16		$this->wikiSource = new Search_ContentSource_Static(
17			['Test' => ['description' => 'ABC'],],
18			['description' => 'sortable']
19		);
20
21		$this->categorySource = new Search_GlobalSource_Static(
22			['wiki page:Test' => ['categories' => [1, 2, 3]],],
23			['categories' => 'multivalue']
24		);
25
26		$this->permissionSource = new Search_GlobalSource_Static(
27			[
28				'wiki page:Test' => ['allowed_groups' => ['Editors', 'Admins']],
29			],
30			['allowed_groups' => 'multivalue']
31		);
32	}
33
34	function testObtainInformationFromContentSource()
35	{
36		$source = new Search_Formatter_DataSource_Declarative;
37		$source->addContentSource('wiki page', $this->wikiSource);
38
39		$this->assertEquals(['description' => 'ABC'], $source->getData(['object_type' => 'wiki page', 'object_id' => 'Test'], 'description'));
40	}
41
42	function testRequestedValueNotProvided()
43	{
44		$source = new Search_Formatter_DataSource_Declarative;
45		$source->addContentSource('wiki page', $this->wikiSource);
46
47		$this->assertEquals([], $source->getData(['object_type' => 'wiki page', 'object_id' => 'Test'], 'title'));
48	}
49
50	function testValueFromGlobal()
51	{
52		$source = new Search_Formatter_DataSource_Declarative;
53		$source->addGlobalSource($this->categorySource);
54		$source->addGlobalSource($this->permissionSource);
55
56		$this->assertEquals(['categories' => [1, 2, 3]], $source->getData(['object_type' => 'wiki page', 'object_id' => 'Test'], 'categories'));
57		$this->assertEquals(['allowed_groups' => ['Editors', 'Admins']], $source->getData(['object_type' => 'wiki page', 'object_id' => 'Test'], 'allowed_groups'));
58	}
59
60	function testContentSourceNotAvailable()
61	{
62		$source = new Search_Formatter_DataSource_Declarative;
63		$this->assertEquals([], $source->getData(['object_type' => 'wiki page', 'object_id' => 'Test'], 'title'));
64	}
65}
66