|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wikibase\EntityStore\Internal; |
|
4
|
|
|
|
|
5
|
|
|
use Ask\Language\Description\AnyValue; |
|
6
|
|
|
use Ask\Language\Option\QueryOptions; |
|
7
|
|
|
use Wikibase\DataModel\Entity\Item; |
|
8
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
|
9
|
|
|
use Wikibase\DataModel\Entity\Property; |
|
10
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @covers Wikibase\EntityStore\Internal\DispatchingEntityIdForQueryLookup |
|
14
|
|
|
* |
|
15
|
|
|
* @licence GPLv2+ |
|
16
|
|
|
* @author Thomas Pellissier Tanon |
|
17
|
|
|
*/ |
|
18
|
|
|
class DispatchingEntityIdForQueryLookupTest extends \PHPUnit_Framework_TestCase { |
|
19
|
|
|
|
|
20
|
|
|
public function testGetEntityIdsForQuery() { |
|
21
|
|
|
$entityIdForQueryLookupMock = $this->getMockBuilder( 'Wikibase\EntityStore\Internal\EntityIdForQueryLookup' ) |
|
22
|
|
|
->disableOriginalConstructor() |
|
23
|
|
|
->getMock(); |
|
24
|
|
|
$entityIdForQueryLookupMock->expects( $this->once() ) |
|
25
|
|
|
->method( 'getEntityIdsForQuery' ) |
|
26
|
|
|
->with( $this->equalTo( new AnyValue() ), $this->equalTo( new QueryOptions( 10, 0 ) ) ) |
|
27
|
|
|
->willReturn( [ new ItemId( 'Q1' ) ] ); |
|
28
|
|
|
|
|
29
|
|
|
$entityIdForQueryLookup = new DispatchingEntityIdForQueryLookup( $entityIdForQueryLookupMock ); |
|
30
|
|
|
$this->assertEquals( |
|
31
|
|
|
[ new ItemId( 'Q1' ) ], |
|
32
|
|
|
$entityIdForQueryLookup->getEntityIdsForQuery( new AnyValue(), new QueryOptions( 10, 0 ) ) |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testGetItemsForQuery() { |
|
37
|
|
|
$entityIdForQueryLookupMock = $this->getMockBuilder( 'Wikibase\EntityStore\Internal\EntityIdForQueryLookup' ) |
|
38
|
|
|
->disableOriginalConstructor() |
|
39
|
|
|
->getMock(); |
|
40
|
|
|
$entityIdForQueryLookupMock->expects( $this->once() ) |
|
41
|
|
|
->method( 'getEntityIdsForQuery' ) |
|
42
|
|
|
->with( |
|
43
|
|
|
$this->equalTo( new AnyValue() ), |
|
44
|
|
|
$this->equalTo( new QueryOptions( 10, 0 ) ), |
|
45
|
|
|
$this->equalTo( Item::ENTITY_TYPE ) |
|
46
|
|
|
) |
|
47
|
|
|
->willReturn( [ new ItemId( 'Q1' ) ] ); |
|
48
|
|
|
|
|
49
|
|
|
$entityIdForQueryLookup = new DispatchingEntityIdForQueryLookup( $entityIdForQueryLookupMock ); |
|
50
|
|
|
$this->assertEquals( |
|
51
|
|
|
[ new ItemId( 'Q1' ) ], |
|
52
|
|
|
$entityIdForQueryLookup->getItemIdsForQuery( new AnyValue(), new QueryOptions( 10, 0 ) ) |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testGetPropertiesForQuery() { |
|
57
|
|
|
$entityIdForQueryLookupMock = $this->getMockBuilder( 'Wikibase\EntityStore\Internal\EntityIdForQueryLookup' ) |
|
58
|
|
|
->disableOriginalConstructor() |
|
59
|
|
|
->getMock(); |
|
60
|
|
|
$entityIdForQueryLookupMock->expects( $this->once() ) |
|
61
|
|
|
->method( 'getEntityIdsForQuery' ) |
|
62
|
|
|
->with( |
|
63
|
|
|
$this->equalTo( new AnyValue() ), |
|
64
|
|
|
$this->equalTo( new QueryOptions( 10, 0 ) ), |
|
65
|
|
|
$this->equalTo( Property::ENTITY_TYPE ) |
|
66
|
|
|
) |
|
67
|
|
|
->willReturn( [ new PropertyId( 'P1' ) ] ); |
|
68
|
|
|
|
|
69
|
|
|
$entityIdForQueryLookup = new DispatchingEntityIdForQueryLookup( $entityIdForQueryLookupMock ); |
|
70
|
|
|
$this->assertEquals( |
|
71
|
|
|
[ new PropertyId( 'P1' ) ], |
|
72
|
|
|
$entityIdForQueryLookup->getPropertyIdsForQuery( new AnyValue(), new QueryOptions( 10, 0 ) ) |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|