blob: ce1b4fa43cd0ff734b6a9b13647b8c307ee105f4 (
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
75
76
77
78
79
80
81
82
83
84
|
<?php
namespace SMW\Tests\Elastic\QueryEngine\DescriptionInterpreters;
use SMW\Elastic\QueryEngine\DescriptionInterpreters\ConjunctionInterpreter;
use SMW\DIWikiPage;
use SMW\Query\DescriptionFactory;
/**
* @covers \SMW\Elastic\QueryEngine\DescriptionInterpreters\ConjunctionInterpreter
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 3.0
*
* @author mwjames
*/
class ConjunctionInterpreterTest extends \PHPUnit_Framework_TestCase {
private $conditionBuilder;
public function setUp() {
$this->descriptionFactory = new DescriptionFactory();
$this->conditionBuilder = $this->getMockBuilder( '\SMW\Elastic\QueryEngine\ConditionBuilder' )
->disableOriginalConstructor()
->setMethods( [ 'interpretDescription' ] )
->getMock();
}
public function testCanConstruct() {
$this->assertInstanceOf(
ConjunctionInterpreter::class,
new ConjunctionInterpreter( $this->conditionBuilder )
);
}
public function testInterpretDescription_Empty() {
$instance = new ConjunctionInterpreter(
$this->conditionBuilder
);
$condition = $instance->interpretDescription(
$this->descriptionFactory->newConjunction( [] )
);
$this->assertEquals(
[],
$condition
);
}
public function testInterpretDescription_NotEmpty() {
$this->conditionBuilder->expects( $this->any() )
->method( 'interpretDescription' )
->will( $this->returnValue( $this->conditionBuilder->newCondition( [ 'Foo' ] ) ) );
$description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
->disableOriginalConstructor()
->getMock();
$description->expects( $this->any() )
->method( 'getPrintRequests' )
->will( $this->returnValue( [] ) );
$instance = new ConjunctionInterpreter(
$this->conditionBuilder
);
$condition = $instance->interpretDescription(
$this->descriptionFactory->newConjunction( [ $description ] )
);
$this->assertEquals(
'{"bool":{"must":[{"bool":{"must":["Foo"]}}]}}',
$condition
);
}
}
|