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_ArrayBuilderTest extends PHPUnit_Framework_TestCase
9{
10	private $builder;
11
12	function setUp()
13	{
14		$this->builder = new Search_Formatter_ArrayBuilder;
15	}
16
17	function testEmpty()
18	{
19		$this->assertEquals([], $this->builder->getData(''));
20	}
21
22	function testSingleValue()
23	{
24		$string = <<<STR
25{hello foo=bar}
26STR;
27
28		$this->assertEquals(['hello' => ['foo' => 'bar']], $this->builder->getData($string));
29	}
30
31	function testDifferentKeys()
32	{
33		$string = <<<STR
34{hello foo=bar bar=test}
35{test foo=bar}
36STR;
37
38		$this->assertEquals(
39			[
40				'hello' => ['foo' => 'bar', 'bar' => 'test'],
41				'test' => ['foo' => 'bar'],
42			],
43			$this->builder->getData($string)
44		);
45	}
46
47	function testGenerateList()
48	{
49		$string = <<<STR
50{test foo=bar}
51{test bar=baz}
52STR;
53
54		$this->assertEquals(
55			[
56				'test' => [
57					['foo' => 'bar'],
58					['bar' => 'baz'],
59				],
60			],
61			$this->builder->getData($string)
62		);
63	}
64}
65