summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Elastic/QueryEngine/DescriptionInterpreters/NamespaceDescriptionInterpreterTest.php
blob: 9671b96e6a212085bac00019b359288d7d0290d2 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php

namespace SMW\Tests\Elastic\QueryEngine\DescriptionInterpreters;

use SMW\Elastic\QueryEngine\DescriptionInterpreters\NamespaceDescriptionInterpreter;
use SMW\DIWikiPage;
use SMW\Query\DescriptionFactory;

/**
 * @covers \SMW\Elastic\QueryEngine\DescriptionInterpreters\NamespaceDescriptionInterpreter
 * @group semantic-mediawiki
 *
 * @license GNU GPL v2+
 * @since 3.0
 *
 * @author mwjames
 */
class NamespaceDescriptionInterpreterTest extends \PHPUnit_Framework_TestCase {

	private $conditionBuilder;

	public function setUp() {

		$this->descriptionFactory = new DescriptionFactory();

		$this->conditionBuilder = $this->getMockBuilder( '\SMW\Elastic\QueryEngine\ConditionBuilder' )
			->disableOriginalConstructor()
			->setMethods( null )
			->getMock();
	}

	public function testCanConstruct() {

		$this->assertInstanceOf(
			NamespaceDescriptionInterpreter::class,
			new NamespaceDescriptionInterpreter( $this->conditionBuilder )
		);
	}

	public function testInterpretDescription_NotPartOfAConjunction() {

		$instance = new NamespaceDescriptionInterpreter(
			$this->conditionBuilder
		);

		$condition = $instance->interpretDescription(
			$this->descriptionFactory->newNamespaceDescription( NS_MAIN ),
			false
		);

		$this->assertEquals(
			'{"bool":{"filter":{"term":{"subject.namespace":0}}}}',
			$condition
		);
	}

	public function testInterpretDescription_IsPartOfAConjunction() {

		$instance = new NamespaceDescriptionInterpreter(
			$this->conditionBuilder
		);

		$condition = $instance->interpretDescription(
			$this->descriptionFactory->newNamespaceDescription( NS_MAIN ),
			true
		);

		$this->assertEquals(
			'{"term":{"subject.namespace":0}}',
			$condition
		);
	}

}