|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Ask\Language\Description\SomeProperty; |
|
6
|
|
|
use Ask\Language\Description\ValueDescription; |
|
7
|
|
|
use Ask\Language\Option\QueryOptions; |
|
8
|
|
|
use DataValues\NumberValue; |
|
9
|
|
|
use Doctrine\DBAL\DriverManager; |
|
10
|
|
|
use Tests\Queryr\Replicator\Fixtures\StubPropertyDataValueTypeLookup; |
|
11
|
|
|
use Wikibase\DataModel\Entity\BasicEntityIdParser; |
|
12
|
|
|
use Wikibase\DataModel\Entity\EntityIdValue; |
|
13
|
|
|
use Wikibase\DataModel\Entity\Item; |
|
14
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
|
15
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
|
16
|
|
|
use Wikibase\DataModel\Snak\PropertyValueSnak; |
|
17
|
|
|
use Wikibase\DataModel\Statement\Statement; |
|
18
|
|
|
use Wikibase\QueryEngine\DescriptionMatchFinder; |
|
19
|
|
|
use Wikibase\QueryEngine\QueryStoreWriter; |
|
20
|
|
|
use Wikibase\QueryEngine\SQLStore\DataValueHandlersBuilder; |
|
21
|
|
|
use Wikibase\QueryEngine\SQLStore\SQLStore; |
|
22
|
|
|
use Wikibase\QueryEngine\SQLStore\StoreConfig; |
|
23
|
|
|
use Wikibase\QueryEngine\SQLStore\StoreSchema; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @licence GNU GPL v2+ |
|
27
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
28
|
|
|
*/ |
|
29
|
|
|
class QueryEngineTest extends \PHPUnit_Framework_TestCase { |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var QueryStoreWriter |
|
33
|
|
|
*/ |
|
34
|
|
|
private $writer; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var DescriptionMatchFinder |
|
38
|
|
|
*/ |
|
39
|
|
|
private $queryEngine; |
|
40
|
|
|
|
|
41
|
|
|
public function setUp() { |
|
42
|
|
|
if ( !defined( 'WIKIBASE_QUERYENGINE_VERSION' ) ) { |
|
43
|
|
|
$this->markTestSkipped( 'QueryEngine not installed' ); |
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$sqlStore = new SQLStore( $this->newStoreSchema(), $this->newStoreConfig() ); |
|
48
|
|
|
|
|
49
|
|
|
$connection = $this->newConnection(); |
|
50
|
|
|
|
|
51
|
|
|
$sqlStore->newInstaller( $connection->getSchemaManager() )->install(); |
|
52
|
|
|
|
|
53
|
|
|
$this->writer = $sqlStore->newWriter( $connection ); |
|
54
|
|
|
|
|
55
|
|
|
$this->queryEngine = $sqlStore->newDescriptionMatchFinder( |
|
56
|
|
|
$connection, |
|
57
|
|
|
new StubPropertyDataValueTypeLookup(), |
|
58
|
|
|
new BasicEntityIdParser() |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
private function newConnection() { |
|
63
|
|
|
return DriverManager::getConnection( array( |
|
64
|
|
|
'driver' => 'pdo_sqlite', |
|
65
|
|
|
'memory' => true, |
|
66
|
|
|
) ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
private function newStoreSchema() { |
|
70
|
|
|
$handlersBuilder = new DataValueHandlersBuilder(); |
|
71
|
|
|
|
|
72
|
|
|
return new StoreSchema( |
|
73
|
|
|
'qe_', |
|
74
|
|
|
$handlersBuilder->withSimpleMainSnakHandlers()->getHandlers() |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
private function newStoreConfig() { |
|
79
|
|
|
$config = new StoreConfig( |
|
80
|
|
|
'QueryR Replicator QueryEngine' |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
return $config; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testInsertItem() { |
|
87
|
|
|
$item = new Item(); |
|
88
|
|
|
$item->setId( new ItemId( 'Q100' ) ); |
|
89
|
|
|
|
|
90
|
|
|
$statement = new Statement( new PropertyValueSnak( 42, new NumberValue( 1337 ) ) ); |
|
91
|
|
|
$statement->setGuid( 'foo claim' ); |
|
92
|
|
|
$item->getStatements()->addStatement( $statement ); |
|
93
|
|
|
|
|
94
|
|
|
$this->writer->insertEntity( $item ); |
|
95
|
|
|
|
|
96
|
|
|
$propertyDescription = new SomeProperty( |
|
97
|
|
|
new EntityIdValue( new PropertyId( 'P42' ) ), |
|
98
|
|
|
new ValueDescription( new NumberValue( 1337 ) ) |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
$ids = $this->queryEngine->getMatchingEntities( |
|
102
|
|
|
$propertyDescription, |
|
103
|
|
|
new QueryOptions( 2, 0 ) |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
$this->assertEquals( array( 'Q100' ), $ids ); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|