1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\EntityStore\Internal; |
4
|
|
|
|
5
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
6
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
7
|
|
|
use Wikibase\DataModel\Term\Term; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers Wikibase\EntityStore\Internal\DispatchingEntityIdForTermLookup |
11
|
|
|
* |
12
|
|
|
* @licence GPLv2+ |
13
|
|
|
* @author Thomas Pellissier Tanon |
14
|
|
|
*/ |
15
|
|
|
class DispatchingEntityIdForTermLookupTest extends \PHPUnit_Framework_TestCase { |
16
|
|
|
|
17
|
|
|
public function testGetEntityIdsForTerm() { |
18
|
|
|
$entityIdForTermLookupMock = $this->getMockBuilder( 'Wikibase\EntityStore\Internal\EntityIdForTermLookup' ) |
19
|
|
|
->disableOriginalConstructor() |
20
|
|
|
->getMock(); |
21
|
|
|
$entityIdForTermLookupMock->expects( $this->once() ) |
22
|
|
|
->method( 'getEntityIdsForTerm' ) |
23
|
|
|
->with( $this->equalTo( new Term( 'en', 'foo' ) ) ) |
24
|
|
|
->willReturn( [ new ItemId( 'Q1' ) ] ); |
25
|
|
|
|
26
|
|
|
$entityIdForTermLookup = new DispatchingEntityIdForTermLookup( $entityIdForTermLookupMock ); |
27
|
|
|
$this->assertEquals( |
28
|
|
|
[ new ItemId( 'Q1' ) ], |
29
|
|
|
$entityIdForTermLookup->getEntityIdsForTerm( new Term( 'en', 'foo' ) ) |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testGetItemsForTerm() { |
34
|
|
|
$entityIdForTermLookupMock = $this->getMockBuilder( 'Wikibase\EntityStore\Internal\EntityIdForTermLookup' ) |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->getMock(); |
37
|
|
|
$entityIdForTermLookupMock->expects( $this->once() ) |
38
|
|
|
->method( 'getEntityIdsForTerm' ) |
39
|
|
|
->with( $this->equalTo( new Term( 'en', 'foo' ) ) ) |
40
|
|
|
->willReturn( [ new ItemId( 'Q1' ) ] ); |
41
|
|
|
|
42
|
|
|
$entityIdForTermLookup = new DispatchingEntityIdForTermLookup( $entityIdForTermLookupMock ); |
43
|
|
|
$this->assertEquals( |
44
|
|
|
[ new ItemId( 'Q1' ) ], |
45
|
|
|
$entityIdForTermLookup->getItemIdsForTerm( new Term( 'en', 'foo' ) ) |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetPropertiesForTerm() { |
50
|
|
|
$entityIdForTermLookupMock = $this->getMockBuilder( 'Wikibase\EntityStore\Internal\EntityIdForTermLookup' ) |
51
|
|
|
->disableOriginalConstructor() |
52
|
|
|
->getMock(); |
53
|
|
|
$entityIdForTermLookupMock->expects( $this->once() ) |
54
|
|
|
->method( 'getEntityIdsForTerm' ) |
55
|
|
|
->with( $this->equalTo( new Term( 'en', 'foo' ) ) ) |
56
|
|
|
->willReturn( [ new PropertyId( 'P1' ) ] ); |
57
|
|
|
|
58
|
|
|
$entityIdForTermLookup = new DispatchingEntityIdForTermLookup( $entityIdForTermLookupMock ); |
59
|
|
|
$this->assertEquals( |
60
|
|
|
[ new PropertyId( 'P1' ) ], |
61
|
|
|
$entityIdForTermLookup->getPropertyIdsForTerm( new Term( 'en', 'foo' ) ) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|