1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\EntityStore; |
4
|
|
|
|
5
|
|
|
use Ask\Language\Description\SomeProperty; |
6
|
|
|
use Ask\Language\Description\ValueDescription; |
7
|
|
|
use DataValues\StringValue; |
8
|
|
|
use Wikibase\DataModel\Entity\EntityIdValue; |
9
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
10
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
11
|
|
|
use Wikibase\DataModel\Term\Term; |
12
|
|
|
use Wikibase\EntityStore\Config\EntityStoreFromConfigurationBuilder; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @licence GNU GPL v2+ |
16
|
|
|
* @author Thomas Pellissier Tanon |
17
|
|
|
*/ |
18
|
|
|
class ApiTest extends \PHPUnit_Framework_TestCase { |
19
|
|
|
|
20
|
|
|
public function testApiStore() { |
21
|
|
|
date_default_timezone_set( 'UTC' ); |
22
|
|
|
$store = $this->getEntityStoreFromConfiguration(); |
23
|
|
|
|
24
|
|
|
$this->assertEquals( |
25
|
|
|
new ItemId( 'Q1' ), |
26
|
|
|
$store->getItemLookup()->getItemForId( new ItemId( 'Q1' ) )->getId() |
27
|
|
|
); |
28
|
|
|
|
29
|
|
|
$results = $store->getEntityDocumentLookup()->getEntityDocumentsForIds( |
30
|
|
|
[ new ItemId( 'Q1' ), new PropertyId( 'P18' ) ] |
31
|
|
|
); |
32
|
|
|
$this->assertEquals( 2, count( $results ) ); |
33
|
|
|
|
34
|
|
|
$this->assertEquals( |
35
|
|
|
[ new ItemId( 'Q260' ) ], |
36
|
|
|
$store->getItemIdForTermLookup()->getItemIdsForTerm( new Term( 'fr', 'Jean-François Champollion' ) ) |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$this->assertEquals( |
40
|
|
|
[ new PropertyId( 'P16' ) ], |
41
|
|
|
$store->getPropertyIdForTermLookup()->getPropertyIdsForTerm( new Term( 'en', 'highway system' ) ) |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$this->assertEquals( |
45
|
|
|
[ new ItemId( 'Q1' ) ], |
46
|
|
|
$store->getItemIdForQueryLookup()->getItemIdsForQuery( new SomeProperty( |
47
|
|
|
new EntityIdValue( new PropertyId( 'P18' ) ), |
48
|
|
|
new ValueDescription( new StringValue( 'Hubble ultra deep field.jpg' ) ) |
49
|
|
|
) ) |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function getEntityStoreFromConfiguration() { |
54
|
|
|
$configBuilder = new EntityStoreFromConfigurationBuilder(); |
55
|
|
|
return $configBuilder->buildEntityStore( __DIR__ . '/../data/valid-config-api.json' ); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|