1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\EntityStore\Api; |
4
|
|
|
|
5
|
|
|
use Ask\Language\Description\AnyValue; |
6
|
|
|
use Ask\Language\Description\Conjunction; |
7
|
|
|
use Ask\Language\Description\Description; |
8
|
|
|
use Ask\Language\Description\Disjunction; |
9
|
|
|
use Ask\Language\Description\SomeProperty; |
10
|
|
|
use Ask\Language\Description\ValueDescription; |
11
|
|
|
use DataValues\MonolingualTextValue; |
12
|
|
|
use DataValues\StringValue; |
13
|
|
|
use DataValues\TimeValue; |
14
|
|
|
use Wikibase\DataModel\Entity\EntityIdValue; |
15
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
16
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
17
|
|
|
use WikidataQueryApi\Query\AbstractQuery; |
18
|
|
|
use WikidataQueryApi\Query\AndQuery; |
19
|
|
|
use WikidataQueryApi\Query\BetweenQuery; |
20
|
|
|
use WikidataQueryApi\Query\ClaimQuery; |
21
|
|
|
use WikidataQueryApi\Query\OrQuery; |
22
|
|
|
use WikidataQueryApi\Query\StringQuery; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @covers Wikibase\EntityStore\Api\WikidataQueryItemIdForQueryLookup |
26
|
|
|
* |
27
|
|
|
* @licence GPLv2+ |
28
|
|
|
* @author Thomas Pellissier Tanon |
29
|
|
|
*/ |
30
|
|
|
class WikidataQueryItemIdForQueryLookupTest extends \PHPUnit_Framework_TestCase { |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @dataProvider getEntityIdsForQueryProvider |
34
|
|
|
*/ |
35
|
|
|
public function testGetEntityIdsForQuery( Description $queryDescription, AbstractQuery $wikidataQueryQuery ) { |
36
|
|
|
$queryServiceMock = $this->getMockBuilder( 'WikidataQueryApi\Services\SimpleQueryService' ) |
37
|
|
|
->disableOriginalConstructor() |
38
|
|
|
->getMock(); |
39
|
|
|
$queryServiceMock->expects( $this->once() ) |
40
|
|
|
->method( 'doQuery' ) |
41
|
|
|
->with( $this->equalTo( $wikidataQueryQuery ) ) |
42
|
|
|
->willReturn( [ new ItemId( 'Q1' ) ] ); |
43
|
|
|
$lookup = new WikidataQueryItemIdForQueryLookup( $queryServiceMock ); |
44
|
|
|
|
45
|
|
|
$this->assertEquals( |
46
|
|
|
[ new ItemId( 'Q1' ) ], |
47
|
|
|
$lookup->getItemIdsForQuery( $queryDescription ) |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getEntityIdsForQueryProvider() { |
52
|
|
|
return [ |
53
|
|
|
[ |
54
|
|
|
new SomeProperty( |
55
|
|
|
new EntityIdValue( new PropertyId( 'P1' ) ), |
56
|
|
|
new AnyValue() |
57
|
|
|
), |
58
|
|
|
new ClaimQuery( new PropertyId( 'P1' ) ) |
59
|
|
|
], |
60
|
|
|
[ |
61
|
|
|
new SomeProperty( |
62
|
|
|
new EntityIdValue( new PropertyId( 'P1' ) ), |
63
|
|
|
new ValueDescription( new EntityIdValue( new ItemId( 'Q1' ) ) ) |
64
|
|
|
), |
65
|
|
|
new ClaimQuery( new PropertyId( 'P1' ), new ItemId( 'Q1' ) ) |
66
|
|
|
], |
67
|
|
|
[ |
68
|
|
|
new Conjunction( [ |
69
|
|
|
new SomeProperty( |
70
|
|
|
new EntityIdValue( new PropertyId( 'P42' ) ), |
71
|
|
|
new ValueDescription( new StringValue( 'foo' ) ) |
72
|
|
|
), |
73
|
|
|
new SomeProperty( |
74
|
|
|
new EntityIdValue( new PropertyId( 'P1' ) ), |
75
|
|
|
new ValueDescription( new EntityIdValue( new ItemId( 'Q42' ) ) ) |
76
|
|
|
) |
77
|
|
|
] ), |
78
|
|
|
new AndQuery( [ |
79
|
|
|
new StringQuery( new PropertyId( 'P42' ), new StringValue( 'foo' ) ), |
80
|
|
|
new ClaimQuery( new PropertyId( 'P1' ), new ItemId( 'Q42' ) ) |
81
|
|
|
] ) |
82
|
|
|
], |
83
|
|
|
[ |
84
|
|
|
new Disjunction( [ |
85
|
|
|
new SomeProperty( |
86
|
|
|
new EntityIdValue( new PropertyId( 'P42' ) ), |
87
|
|
|
new ValueDescription( new StringValue( 'foo' ) ) |
88
|
|
|
), |
89
|
|
|
new SomeProperty( |
90
|
|
|
new EntityIdValue( new PropertyId( 'P1' ) ), |
91
|
|
|
new ValueDescription( new EntityIdValue( new ItemId( 'Q42' ) ) ) |
92
|
|
|
) |
93
|
|
|
] ), |
94
|
|
|
new OrQuery( [ |
95
|
|
|
new StringQuery( new PropertyId( 'P42' ), new StringValue( 'foo' ) ), |
96
|
|
|
new ClaimQuery( new PropertyId( 'P1' ), new ItemId( 'Q42' ) ) |
97
|
|
|
] ) |
98
|
|
|
], |
99
|
|
|
[ |
100
|
|
|
new SomeProperty( |
101
|
|
|
new EntityIdValue( new PropertyId( 'P42' ) ), |
102
|
|
|
new Conjunction( [ |
103
|
|
|
new Disjunction( [ |
104
|
|
|
new ValueDescription( new StringValue( 'foo' ) ) |
105
|
|
|
] ), |
106
|
|
|
new AnyValue(), |
107
|
|
|
new ValueDescription( new EntityIdValue( new ItemId( 'Q42' ) ) ) |
108
|
|
|
] ) |
109
|
|
|
), |
110
|
|
|
new AndQuery( [ |
111
|
|
|
new OrQuery( [ |
112
|
|
|
new StringQuery( new PropertyId( 'P42' ), new StringValue( 'foo' ) ) |
113
|
|
|
] ), |
114
|
|
|
new ClaimQuery( new PropertyId( 'P42' ) ), |
115
|
|
|
new ClaimQuery( new PropertyId( 'P42' ), new ItemId( 'Q42' ) ) |
116
|
|
|
] ) |
117
|
|
|
], |
118
|
|
|
[ |
119
|
|
|
new SomeProperty( |
120
|
|
|
new EntityIdValue( new PropertyId( 'P42' ) ), |
121
|
|
|
new ValueDescription( |
122
|
|
|
new TimeValue( '+00000001952-03-11T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, 'foo' ) |
123
|
|
|
) |
124
|
|
|
), |
125
|
|
|
new BetweenQuery( |
126
|
|
|
new PropertyId( 'P42' ), |
127
|
|
|
new TimeValue( '+00000001952-03-11T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, 'foo' ), |
128
|
|
|
new TimeValue( '+00000001952-03-11T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, 'foo' ) |
129
|
|
|
) |
130
|
|
|
], |
131
|
|
|
]; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @dataProvider getEntityIdsForQueryWithFeatureNotSupportedExceptionProvider |
137
|
|
|
*/ |
138
|
|
|
public function testGetEntityIdsForQueryWithFeatureNotSupportedException( Description $queryDescription ) { |
139
|
|
|
$queryServiceMock = $this->getMockBuilder( 'WikidataQueryApi\Services\SimpleQueryService' ) |
140
|
|
|
->disableOriginalConstructor() |
141
|
|
|
->getMock(); |
142
|
|
|
$lookup = new WikidataQueryItemIdForQueryLookup( $queryServiceMock ); |
143
|
|
|
|
144
|
|
|
$this->setExpectedException( 'Wikibase\EntityStore\FeatureNotSupportedException'); |
145
|
|
|
$lookup->getItemIdsForQuery( $queryDescription ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getEntityIdsForQueryWithFeatureNotSupportedExceptionProvider() { |
149
|
|
|
return [ |
150
|
|
|
[ |
151
|
|
|
new AnyValue() |
152
|
|
|
], |
153
|
|
|
[ |
154
|
|
|
$this->getMockForAbstractClass( 'Ask\Language\Description\Description' ) |
155
|
|
|
], |
156
|
|
|
[ |
157
|
|
|
new ValueDescription( new EntityIdValue( new ItemId( 'Q1' ) ) ), |
158
|
|
|
], |
159
|
|
|
[ |
160
|
|
|
new SomeProperty( |
161
|
|
|
new StringValue( 'foo' ), |
162
|
|
|
new ValueDescription( new EntityIdValue( new ItemId( 'Q1' ) ) ) |
163
|
|
|
) |
164
|
|
|
], |
165
|
|
|
[ |
166
|
|
|
new SomeProperty( |
167
|
|
|
new EntityIdValue( new PropertyId( 'P42' ) ), |
168
|
|
|
new SomeProperty( |
169
|
|
|
new EntityIdValue( new PropertyId( 'P42' ) ), |
170
|
|
|
new ValueDescription( new EntityIdValue( new ItemId( 'Q1' ) ) ), |
171
|
|
|
true |
172
|
|
|
) |
173
|
|
|
) |
174
|
|
|
], |
175
|
|
|
[ |
176
|
|
|
new SomeProperty( |
177
|
|
|
new EntityIdValue( new PropertyId( 'P42' ) ), |
178
|
|
|
new ValueDescription( new EntityIdValue( new ItemId( 'Q1' ) ), ValueDescription::COMP_GREATER ) |
179
|
|
|
) |
180
|
|
|
], |
181
|
|
|
[ |
182
|
|
|
new SomeProperty( |
183
|
|
|
new EntityIdValue( new PropertyId( 'P42' ) ), |
184
|
|
|
new ValueDescription( new MonolingualTextValue( 'en', 'Foo' ) ) |
185
|
|
|
), |
186
|
|
|
], |
187
|
|
|
[ |
188
|
|
|
new SomeProperty( |
189
|
|
|
new EntityIdValue( new PropertyId( 'P42' ) ), |
190
|
|
|
new ValueDescription( new EntityIdValue( |
191
|
|
|
$this->getMockForAbstractClass( 'Wikibase\DataModel\Entity\EntityId' ) |
192
|
|
|
) ) |
193
|
|
|
) |
194
|
|
|
], |
195
|
|
|
]; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|