1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\SQLStore\QueryDependency; |
4
|
|
|
|
5
|
|
|
use SMW\DIWikiPage; |
6
|
|
|
use SMW\SQLStore\QueryDependency\QueryDependencyLinksStore; |
7
|
|
|
use SMW\SQLStore\SQLStore; |
8
|
|
|
use SMW\Tests\TestEnvironment; |
9
|
|
|
use SMW\RequestOptions; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \SMW\SQLStore\QueryDependency\QueryDependencyLinksStore |
13
|
|
|
* @group semantic-mediawiki |
14
|
|
|
* |
15
|
|
|
* @license GNU GPL v2+ |
16
|
|
|
* @since 2.3 |
17
|
|
|
* |
18
|
|
|
* @author mwjames |
19
|
|
|
*/ |
20
|
|
|
class QueryDependencyLinksStoreTest extends \PHPUnit_Framework_TestCase { |
21
|
|
|
|
22
|
|
|
private $store; |
23
|
|
|
private $testEnvironment; |
24
|
|
|
|
25
|
|
|
protected function setUp() { |
26
|
|
|
parent::setUp(); |
27
|
|
|
|
28
|
|
|
$this->testEnvironment = new TestEnvironment(); |
29
|
|
|
|
30
|
|
|
$this->store = $this->getMockBuilder( '\SMW\Store' ) |
31
|
|
|
->disableOriginalConstructor() |
32
|
|
|
->getMockForAbstractClass(); |
33
|
|
|
|
34
|
|
|
$this->testEnvironment->registerObject( 'Store', $this->store ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function tearDown() { |
38
|
|
|
$this->testEnvironment->tearDown(); |
39
|
|
|
$this->testEnvironment->clearPendingDeferredUpdates(); |
40
|
|
|
|
41
|
|
|
parent::tearDown(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testCanConstruct() { |
45
|
|
|
|
46
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
47
|
|
|
->disableOriginalConstructor() |
48
|
|
|
->getMock(); |
49
|
|
|
|
50
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
51
|
|
|
->method( 'getStore' ) |
52
|
|
|
->will( $this->returnValue( $this->store ) ); |
53
|
|
|
|
54
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
55
|
|
|
->disableOriginalConstructor() |
56
|
|
|
->getMock(); |
57
|
|
|
|
58
|
|
|
$this->assertInstanceOf( |
59
|
|
|
'\SMW\SQLStore\QueryDependency\QueryDependencyLinksStore', |
60
|
|
|
new QueryDependencyLinksStore( $queryResultDependencyListResolver, $dependencyLinksTableUpdater ) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testPruneOutdatedTargetLinks() { |
65
|
|
|
|
66
|
|
|
$subject = DIWikiPage::newFromText( __METHOD__ ); |
67
|
|
|
|
68
|
|
|
$propertyTableInfoFetcher = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableInfoFetcher' ) |
69
|
|
|
->disableOriginalConstructor() |
70
|
|
|
->getMock(); |
71
|
|
|
|
72
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
73
|
|
|
->disableOriginalConstructor() |
74
|
|
|
->getMock(); |
75
|
|
|
|
76
|
|
|
$store->expects( $this->any() ) |
77
|
|
|
->method( 'getPropertyTableInfoFetcher' ) |
78
|
|
|
->will( $this->returnValue( $propertyTableInfoFetcher ) ); |
79
|
|
|
|
80
|
|
|
$compositePropertyTableDiffIterator = $this->getMockBuilder( '\SMW\SQLStore\CompositePropertyTableDiffIterator' ) |
81
|
|
|
->disableOriginalConstructor() |
82
|
|
|
->getMock(); |
83
|
|
|
|
84
|
|
|
$compositePropertyTableDiffIterator->expects( $this->once() ) |
85
|
|
|
->method( 'getTableChangeOps' ) |
86
|
|
|
->will( $this->returnValue( array() ) ); |
87
|
|
|
|
88
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
89
|
|
|
->disableOriginalConstructor() |
90
|
|
|
->getMock(); |
91
|
|
|
|
92
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
93
|
|
|
->method( 'getStore' ) |
94
|
|
|
->will( $this->returnValue( $store ) ); |
95
|
|
|
|
96
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
97
|
|
|
->disableOriginalConstructor() |
98
|
|
|
->getMock(); |
99
|
|
|
|
100
|
|
|
$instance = new QueryDependencyLinksStore( |
101
|
|
|
$queryResultDependencyListResolver, |
102
|
|
|
$dependencyLinksTableUpdater |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$this->assertTrue( |
106
|
|
|
$instance->pruneOutdatedTargetLinks( $subject, $compositePropertyTableDiffIterator ) |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testPruneOutdatedTargetLinksBeingDisabled() { |
111
|
|
|
|
112
|
|
|
$subject = DIWikiPage::newFromText( __METHOD__ ); |
113
|
|
|
|
114
|
|
|
$propertyTableInfoFetcher = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableInfoFetcher' ) |
115
|
|
|
->disableOriginalConstructor() |
116
|
|
|
->getMock(); |
117
|
|
|
|
118
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
119
|
|
|
->disableOriginalConstructor() |
120
|
|
|
->getMock(); |
121
|
|
|
|
122
|
|
|
$store->expects( $this->any() ) |
123
|
|
|
->method( 'getPropertyTableInfoFetcher' ) |
124
|
|
|
->will( $this->returnValue( $propertyTableInfoFetcher ) ); |
125
|
|
|
|
126
|
|
|
$compositePropertyTableDiffIterator = $this->getMockBuilder( '\SMW\SQLStore\CompositePropertyTableDiffIterator' ) |
127
|
|
|
->disableOriginalConstructor() |
128
|
|
|
->getMock(); |
129
|
|
|
|
130
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
131
|
|
|
->disableOriginalConstructor() |
132
|
|
|
->getMock(); |
133
|
|
|
|
134
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
135
|
|
|
->method( 'getStore' ) |
136
|
|
|
->will( $this->returnValue( $store ) ); |
137
|
|
|
|
138
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
139
|
|
|
->disableOriginalConstructor() |
140
|
|
|
->getMock(); |
141
|
|
|
|
142
|
|
|
$instance = new QueryDependencyLinksStore( |
143
|
|
|
$queryResultDependencyListResolver, |
144
|
|
|
$dependencyLinksTableUpdater |
145
|
|
|
); |
146
|
|
|
|
147
|
|
|
$instance->setEnabled( false ); |
148
|
|
|
|
149
|
|
|
$this->assertNull( |
150
|
|
|
$instance->pruneOutdatedTargetLinks( $subject, $compositePropertyTableDiffIterator ) |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testBuildParserCachePurgeJobParametersOnBlacklistedProperty() { |
155
|
|
|
|
156
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
157
|
|
|
->disableOriginalConstructor() |
158
|
|
|
->getMockForAbstractClass(); |
159
|
|
|
|
160
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
161
|
|
|
->disableOriginalConstructor() |
162
|
|
|
->getMock(); |
163
|
|
|
|
164
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
165
|
|
|
->method( 'getStore' ) |
166
|
|
|
->will( $this->returnValue( $store ) ); |
167
|
|
|
|
168
|
|
|
$entityIdListRelevanceDetectionFilter = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\EntityIdListRelevanceDetectionFilter' ) |
169
|
|
|
->disableOriginalConstructor() |
170
|
|
|
->getMock(); |
171
|
|
|
|
172
|
|
|
$entityIdListRelevanceDetectionFilter->expects( $this->once() ) |
173
|
|
|
->method( 'getFilteredIdList' ) |
174
|
|
|
->will( $this->returnValue( array( 1 ) ) ); |
175
|
|
|
|
176
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
177
|
|
|
->disableOriginalConstructor() |
178
|
|
|
->getMock(); |
179
|
|
|
|
180
|
|
|
$instance = new QueryDependencyLinksStore( |
181
|
|
|
$queryResultDependencyListResolver, |
182
|
|
|
$dependencyLinksTableUpdater |
183
|
|
|
); |
184
|
|
|
|
185
|
|
|
$this->assertEquals( |
186
|
|
|
array( 'idlist' => array( 1 ) ), |
187
|
|
|
$instance->buildParserCachePurgeJobParametersFrom( $entityIdListRelevanceDetectionFilter ) |
188
|
|
|
); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function testBuildParserCachePurgeJobParametersBeingDisabled() { |
192
|
|
|
|
193
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
194
|
|
|
->disableOriginalConstructor() |
195
|
|
|
->getMock(); |
196
|
|
|
|
197
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
198
|
|
|
->disableOriginalConstructor() |
199
|
|
|
->getMock(); |
200
|
|
|
|
201
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
202
|
|
|
->method( 'getStore' ) |
203
|
|
|
->will( $this->returnValue( $store ) ); |
204
|
|
|
|
205
|
|
|
$entityIdListRelevanceDetectionFilter = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\EntityIdListRelevanceDetectionFilter' ) |
206
|
|
|
->disableOriginalConstructor() |
207
|
|
|
->getMock(); |
208
|
|
|
|
209
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
210
|
|
|
->disableOriginalConstructor() |
211
|
|
|
->getMock(); |
212
|
|
|
|
213
|
|
|
$instance = new QueryDependencyLinksStore( |
214
|
|
|
$queryResultDependencyListResolver, |
215
|
|
|
$dependencyLinksTableUpdater |
216
|
|
|
); |
217
|
|
|
|
218
|
|
|
$instance->setEnabled( false ); |
219
|
|
|
|
220
|
|
|
$this->assertEmpty( |
221
|
|
|
$instance->buildParserCachePurgeJobParametersFrom( $entityIdListRelevanceDetectionFilter ) |
222
|
|
|
); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
public function testBuildParserCachePurgeJobParametersOnEmptyList() { |
226
|
|
|
|
227
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
228
|
|
|
->disableOriginalConstructor() |
229
|
|
|
->getMock(); |
230
|
|
|
|
231
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
232
|
|
|
->disableOriginalConstructor() |
233
|
|
|
->getMock(); |
234
|
|
|
|
235
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
236
|
|
|
->method( 'getStore' ) |
237
|
|
|
->will( $this->returnValue( $store ) ); |
238
|
|
|
|
239
|
|
|
$entityIdListRelevanceDetectionFilter = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\EntityIdListRelevanceDetectionFilter' ) |
240
|
|
|
->disableOriginalConstructor() |
241
|
|
|
->getMock(); |
242
|
|
|
|
243
|
|
|
$entityIdListRelevanceDetectionFilter->expects( $this->once() ) |
244
|
|
|
->method( 'getFilteredIdList' ) |
245
|
|
|
->will( $this->returnValue( array() ) ); |
246
|
|
|
|
247
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
248
|
|
|
->disableOriginalConstructor() |
249
|
|
|
->getMock(); |
250
|
|
|
|
251
|
|
|
$instance = new QueryDependencyLinksStore( |
252
|
|
|
$queryResultDependencyListResolver, |
253
|
|
|
$dependencyLinksTableUpdater |
254
|
|
|
); |
255
|
|
|
|
256
|
|
|
$instance->setEnabled( true ); |
257
|
|
|
|
258
|
|
|
$this->assertEmpty( |
259
|
|
|
$instance->buildParserCachePurgeJobParametersFrom( $entityIdListRelevanceDetectionFilter ) |
260
|
|
|
); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
public function testFindEmbeddedQueryTargetLinksHashListFrom() { |
264
|
|
|
|
265
|
|
|
$row = new \stdClass; |
266
|
|
|
$row->s_id = 1001; |
267
|
|
|
|
268
|
|
|
$idTable = $this->getMockBuilder( '\stdClass' ) |
269
|
|
|
->setMethods( array( 'getDataItemPoolHashListFor' ) ) |
270
|
|
|
->getMock(); |
271
|
|
|
|
272
|
|
|
$idTable->expects( $this->once() ) |
273
|
|
|
->method( 'getDataItemPoolHashListFor' ); |
274
|
|
|
|
275
|
|
|
$connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) |
276
|
|
|
->disableOriginalConstructor() |
277
|
|
|
->getMock(); |
278
|
|
|
|
279
|
|
|
$connection->expects( $this->once() ) |
280
|
|
|
->method( 'select' ) |
281
|
|
|
->with( |
282
|
|
|
$this->equalTo( \SMWSQLStore3::QUERY_LINKS_TABLE ), |
283
|
|
|
$this->anything(), |
284
|
|
|
$this->equalTo( array( 'o_id' => array( 42 ) ) ) ) |
285
|
|
|
->will( $this->returnValue( array( $row ) ) ); |
286
|
|
|
|
287
|
|
|
$connectionManager = $this->getMockBuilder( '\SMW\ConnectionManager' ) |
288
|
|
|
->disableOriginalConstructor() |
289
|
|
|
->getMock(); |
290
|
|
|
|
291
|
|
|
$connectionManager->expects( $this->any() ) |
292
|
|
|
->method( 'getConnection' ) |
293
|
|
|
->will( $this->returnValue( $connection ) ); |
294
|
|
|
|
295
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
296
|
|
|
->disableOriginalConstructor() |
297
|
|
|
->setMethods( array( 'getObjectIds' ) ) |
298
|
|
|
->getMockForAbstractClass(); |
299
|
|
|
|
300
|
|
|
$store->setConnectionManager( $connectionManager ); |
301
|
|
|
|
302
|
|
|
$store->expects( $this->any() ) |
303
|
|
|
->method( 'getObjectIds' ) |
304
|
|
|
->will( $this->returnValue( $idTable ) ); |
305
|
|
|
|
306
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
307
|
|
|
->disableOriginalConstructor() |
308
|
|
|
->getMock(); |
309
|
|
|
|
310
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
311
|
|
|
->method( 'getStore' ) |
312
|
|
|
->will( $this->returnValue( $store ) ); |
313
|
|
|
|
314
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
315
|
|
|
->disableOriginalConstructor() |
316
|
|
|
->getMock(); |
317
|
|
|
|
318
|
|
|
$instance = new QueryDependencyLinksStore( |
319
|
|
|
$queryResultDependencyListResolver, |
320
|
|
|
$dependencyLinksTableUpdater |
321
|
|
|
); |
322
|
|
|
|
323
|
|
|
$requestOptions = new RequestOptions(); |
324
|
|
|
$requestOptions->setLimit( 1 ); |
325
|
|
|
$requestOptions->setOffset( 200 ); |
326
|
|
|
|
327
|
|
|
$instance->findEmbeddedQueryTargetLinksHashListFrom( array( 42 ), $requestOptions ); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
public function testFindEmbeddedQueryTargetLinksHashListBySubject() { |
331
|
|
|
|
332
|
|
|
$row = new \stdClass; |
333
|
|
|
$row->s_id = 1001; |
334
|
|
|
|
335
|
|
|
$idTable = $this->getMockBuilder( '\stdClass' ) |
336
|
|
|
->setMethods( array( 'getDataItemPoolHashListFor' ) ) |
337
|
|
|
->getMock(); |
338
|
|
|
|
339
|
|
|
$idTable->expects( $this->once() ) |
340
|
|
|
->method( 'getDataItemPoolHashListFor' ); |
341
|
|
|
|
342
|
|
|
$connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) |
343
|
|
|
->disableOriginalConstructor() |
344
|
|
|
->getMock(); |
345
|
|
|
|
346
|
|
|
$connection->expects( $this->once() ) |
347
|
|
|
->method( 'select' ) |
348
|
|
|
->with( |
349
|
|
|
$this->equalTo( \SMWSQLStore3::QUERY_LINKS_TABLE ), |
350
|
|
|
$this->anything(), |
351
|
|
|
$this->equalTo( array( 'o_id' => array( 42 ) ) ) ) |
352
|
|
|
->will( $this->returnValue( array( $row ) ) ); |
353
|
|
|
|
354
|
|
|
$connectionManager = $this->getMockBuilder( '\SMW\ConnectionManager' ) |
355
|
|
|
->disableOriginalConstructor() |
356
|
|
|
->getMock(); |
357
|
|
|
|
358
|
|
|
$connectionManager->expects( $this->any() ) |
359
|
|
|
->method( 'getConnection' ) |
360
|
|
|
->will( $this->returnValue( $connection ) ); |
361
|
|
|
|
362
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
363
|
|
|
->disableOriginalConstructor() |
364
|
|
|
->setMethods( array( 'getObjectIds' ) ) |
365
|
|
|
->getMockForAbstractClass(); |
366
|
|
|
|
367
|
|
|
$store->setConnectionManager( $connectionManager ); |
368
|
|
|
|
369
|
|
|
$store->expects( $this->any() ) |
370
|
|
|
->method( 'getObjectIds' ) |
371
|
|
|
->will( $this->returnValue( $idTable ) ); |
372
|
|
|
|
373
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
374
|
|
|
->disableOriginalConstructor() |
375
|
|
|
->getMock(); |
376
|
|
|
|
377
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
378
|
|
|
->disableOriginalConstructor() |
379
|
|
|
->getMock(); |
380
|
|
|
|
381
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
382
|
|
|
->method( 'getStore' ) |
383
|
|
|
->will( $this->returnValue( $store ) ); |
384
|
|
|
|
385
|
|
|
$dependencyLinksTableUpdater->expects( $this->once() ) |
386
|
|
|
->method( 'getId' ) |
387
|
|
|
->will( $this->returnValue( 42 ) ); |
388
|
|
|
|
389
|
|
|
$instance = new QueryDependencyLinksStore( |
390
|
|
|
$queryResultDependencyListResolver, |
391
|
|
|
$dependencyLinksTableUpdater |
392
|
|
|
); |
393
|
|
|
|
394
|
|
|
$requestOptions = new RequestOptions(); |
395
|
|
|
$requestOptions->setLimit( 1 ); |
396
|
|
|
$requestOptions->setOffset( 200 ); |
397
|
|
|
|
398
|
|
|
$instance->findEmbeddedQueryTargetLinksHashListBySubject( DIWikiPage::newFromText( 'Foo' ), $requestOptions ); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
public function testTryDoUpdateDependenciesByWhileBeingDisabled() { |
402
|
|
|
|
403
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
404
|
|
|
->disableOriginalConstructor() |
405
|
|
|
->getMockForAbstractClass(); |
406
|
|
|
|
407
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
408
|
|
|
->disableOriginalConstructor() |
409
|
|
|
->getMock(); |
410
|
|
|
|
411
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
412
|
|
|
->method( 'getStore' ) |
413
|
|
|
->will( $this->returnValue( $store ) ); |
414
|
|
|
|
415
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
416
|
|
|
->disableOriginalConstructor() |
417
|
|
|
->getMock(); |
418
|
|
|
|
419
|
|
|
$queryResultDependencyListResolver->expects( $this->never() ) |
420
|
|
|
->method( 'getDependencyListByLateRetrieval' ) |
421
|
|
|
->will( $this->returnValue( array() ) ); |
422
|
|
|
|
423
|
|
|
$queryResultDependencyListResolver->expects( $this->never() ) |
424
|
|
|
->method( 'getDependencyList' ) |
425
|
|
|
->will( $this->returnValue( array() ) ); |
426
|
|
|
|
427
|
|
|
$instance = new QueryDependencyLinksStore( |
428
|
|
|
$queryResultDependencyListResolver, |
429
|
|
|
$dependencyLinksTableUpdater |
430
|
|
|
); |
431
|
|
|
|
432
|
|
|
$instance->setEnabled( false ); |
433
|
|
|
$queryResult = ''; |
434
|
|
|
|
435
|
|
|
$instance->doUpdateDependenciesFrom( $queryResult ); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
public function testTryDoUpdateDependenciesByForWhenDependencyListReturnsEmpty() { |
439
|
|
|
|
440
|
|
|
$idTable = $this->getMockBuilder( '\stdClass' ) |
441
|
|
|
->setMethods( array( 'getIDFor' ) ) |
442
|
|
|
->getMock(); |
443
|
|
|
|
444
|
|
|
$idTable->expects( $this->any() ) |
445
|
|
|
->method( 'getIDFor' ) |
446
|
|
|
->will( $this->onConsecutiveCalls( 42, 1001 ) ); |
447
|
|
|
|
448
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
449
|
|
|
->disableOriginalConstructor() |
450
|
|
|
->setMethods( array( 'getObjectIds' ) ) |
451
|
|
|
->getMockForAbstractClass(); |
452
|
|
|
|
453
|
|
|
$store->expects( $this->any() ) |
454
|
|
|
->method( 'getObjectIds' ) |
455
|
|
|
->will( $this->returnValue( $idTable ) ); |
456
|
|
|
|
457
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
458
|
|
|
->disableOriginalConstructor() |
459
|
|
|
->getMock(); |
460
|
|
|
|
461
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
462
|
|
|
->method( 'getStore' ) |
463
|
|
|
->will( $this->returnValue( $store ) ); |
464
|
|
|
|
465
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
466
|
|
|
->disableOriginalConstructor() |
467
|
|
|
->getMock(); |
468
|
|
|
|
469
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
470
|
|
|
->method( 'getDependencyListByLateRetrievalFrom' ) |
471
|
|
|
->will( $this->returnValue( array() ) ); |
472
|
|
|
|
473
|
|
|
$queryResultDependencyListResolver->expects( $this->once() ) |
474
|
|
|
->method( 'getDependencyListFrom' ) |
475
|
|
|
->will( $this->returnValue( array() ) ); |
476
|
|
|
|
477
|
|
|
$instance = new QueryDependencyLinksStore( |
478
|
|
|
$queryResultDependencyListResolver, |
479
|
|
|
$dependencyLinksTableUpdater |
480
|
|
|
); |
481
|
|
|
|
482
|
|
|
$instance->setEnabled( true ); |
483
|
|
|
|
484
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
485
|
|
|
->disableOriginalConstructor() |
486
|
|
|
->getMock(); |
487
|
|
|
|
488
|
|
|
$query->expects( $this->any() ) |
489
|
|
|
->method( 'getContextPage' ) |
490
|
|
|
->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) ); |
491
|
|
|
|
492
|
|
|
$query->expects( $this->any() ) |
493
|
|
|
->method( 'getLimit' ) |
494
|
|
|
->will( $this->returnValue( 1 ) ); |
495
|
|
|
|
496
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
497
|
|
|
->disableOriginalConstructor() |
498
|
|
|
->getMock(); |
499
|
|
|
|
500
|
|
|
$queryResult->expects( $this->any() ) |
501
|
|
|
->method( 'getQuery' ) |
502
|
|
|
->will( $this->returnValue( $query ) ); |
503
|
|
|
|
504
|
|
|
$instance->doUpdateDependenciesFrom( $queryResult ); |
505
|
|
|
|
506
|
|
|
$this->testEnvironment->executePendingDeferredUpdates(); |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
public function testdoUpdateDependenciesByFromQueryResult() { |
510
|
|
|
|
511
|
|
|
$connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) |
512
|
|
|
->disableOriginalConstructor() |
513
|
|
|
->getMock(); |
514
|
|
|
|
515
|
|
|
$connectionManager = $this->getMockBuilder( '\SMW\ConnectionManager' ) |
516
|
|
|
->disableOriginalConstructor() |
517
|
|
|
->getMock(); |
518
|
|
|
|
519
|
|
|
$connectionManager->expects( $this->any() ) |
520
|
|
|
->method( 'getConnection' ) |
521
|
|
|
->will( $this->returnValue( $connection ) ); |
522
|
|
|
|
523
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
524
|
|
|
->disableOriginalConstructor() |
525
|
|
|
->setMethods( array( 'getPropertyValues' ) ) |
526
|
|
|
->getMock(); |
527
|
|
|
|
528
|
|
|
$store->setConnectionManager( $connectionManager ); |
529
|
|
|
|
530
|
|
|
$store->expects( $this->any() ) |
531
|
|
|
->method( 'getPropertyValues' ) |
532
|
|
|
->will( $this->returnValue( array() ) ); |
533
|
|
|
|
534
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
535
|
|
|
->disableOriginalConstructor() |
536
|
|
|
->getMock(); |
537
|
|
|
|
538
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
539
|
|
|
->method( 'getDependencyListByLateRetrievalFrom' ) |
540
|
|
|
->will( $this->returnValue( array() ) ); |
541
|
|
|
|
542
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
543
|
|
|
->method( 'getDependencyListFrom' ) |
544
|
|
|
->will( $this->returnValue( array( null, DIWikiPage::newFromText( 'Foo' ) ) ) ); |
545
|
|
|
|
546
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
547
|
|
|
->disableOriginalConstructor() |
548
|
|
|
->getMock(); |
549
|
|
|
|
550
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
551
|
|
|
->method( 'getId' ) |
552
|
|
|
->will( $this->onConsecutiveCalls( 42, 1001 ) ); |
553
|
|
|
|
554
|
|
|
$dependencyLinksTableUpdater->expects( $this->atLeastOnce() ) |
555
|
|
|
->method( 'addToUpdateList' ) |
556
|
|
|
->with( |
557
|
|
|
$this->equalTo( 1001 ), |
558
|
|
|
$this->anything() ); |
559
|
|
|
|
560
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
561
|
|
|
->method( 'getStore' ) |
562
|
|
|
->will( $this->returnValue( $store ) ); |
563
|
|
|
|
564
|
|
|
$instance = new QueryDependencyLinksStore( |
565
|
|
|
$queryResultDependencyListResolver, |
566
|
|
|
$dependencyLinksTableUpdater |
567
|
|
|
); |
568
|
|
|
|
569
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
570
|
|
|
->disableOriginalConstructor() |
571
|
|
|
->getMock(); |
572
|
|
|
|
573
|
|
|
$query->expects( $this->any() ) |
574
|
|
|
->method( 'getContextPage' ) |
575
|
|
|
->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) ); |
576
|
|
|
|
577
|
|
|
$query->expects( $this->any() ) |
578
|
|
|
->method( 'getLimit' ) |
579
|
|
|
->will( $this->returnValue( 1 ) ); |
580
|
|
|
|
581
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
582
|
|
|
->disableOriginalConstructor() |
583
|
|
|
->getMock(); |
584
|
|
|
|
585
|
|
|
$queryResult->expects( $this->any() ) |
586
|
|
|
->method( 'getQuery' ) |
587
|
|
|
->will( $this->returnValue( $query ) ); |
588
|
|
|
|
589
|
|
|
$instance->doUpdateDependenciesFrom( $queryResult ); |
590
|
|
|
|
591
|
|
|
$this->testEnvironment->executePendingDeferredUpdates(); |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
public function testdoUpdateDependenciesByFromQueryResultWhereObjectIdIsYetUnknownWhichRequiresToCreateTheIdOnTheFly() { |
595
|
|
|
|
596
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
597
|
|
|
->disableOriginalConstructor() |
598
|
|
|
->getMock(); |
599
|
|
|
|
600
|
|
|
$store->expects( $this->any() ) |
601
|
|
|
->method( 'getPropertyValues' ) |
602
|
|
|
->will( $this->returnValue( array() ) ); |
603
|
|
|
|
604
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
605
|
|
|
->disableOriginalConstructor() |
606
|
|
|
->getMock(); |
607
|
|
|
|
608
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
609
|
|
|
->method( 'getDependencyListByLateRetrievalFrom' ) |
610
|
|
|
->will( $this->returnValue( array() ) ); |
611
|
|
|
|
612
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
613
|
|
|
->method( 'getDependencyListFrom' ) |
614
|
|
|
->will( $this->returnValue( array( DIWikiPage::newFromText( 'Foo', NS_CATEGORY ) ) ) ); |
615
|
|
|
|
616
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
617
|
|
|
->disableOriginalConstructor() |
618
|
|
|
->getMock(); |
619
|
|
|
|
620
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
621
|
|
|
->method( 'getId' ) |
622
|
|
|
->will( $this->onConsecutiveCalls( 0, 0 ) ); |
623
|
|
|
|
624
|
|
|
$dependencyLinksTableUpdater->expects( $this->once() ) |
625
|
|
|
->method( 'createId' ) |
626
|
|
|
->will( $this->returnValue( 1001 ) ); |
627
|
|
|
|
628
|
|
|
$dependencyLinksTableUpdater->expects( $this->atLeastOnce() ) |
629
|
|
|
->method( 'addToUpdateList' ) |
630
|
|
|
->with( |
631
|
|
|
$this->equalTo( 1001 ), |
632
|
|
|
$this->anything() ); |
633
|
|
|
|
634
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
635
|
|
|
->method( 'getStore' ) |
636
|
|
|
->will( $this->returnValue( $store ) ); |
637
|
|
|
|
638
|
|
|
$instance = new QueryDependencyLinksStore( |
639
|
|
|
$queryResultDependencyListResolver, |
640
|
|
|
$dependencyLinksTableUpdater |
641
|
|
|
); |
642
|
|
|
|
643
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
644
|
|
|
->disableOriginalConstructor() |
645
|
|
|
->getMock(); |
646
|
|
|
|
647
|
|
|
$query->expects( $this->any() ) |
648
|
|
|
->method( 'getContextPage' ) |
649
|
|
|
->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) ); |
650
|
|
|
|
651
|
|
|
$query->expects( $this->any() ) |
652
|
|
|
->method( 'getLimit' ) |
653
|
|
|
->will( $this->returnValue( 1 ) ); |
654
|
|
|
|
655
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
656
|
|
|
->disableOriginalConstructor() |
657
|
|
|
->getMock(); |
658
|
|
|
|
659
|
|
|
$queryResult->expects( $this->any() ) |
660
|
|
|
->method( 'getQuery' ) |
661
|
|
|
->will( $this->returnValue( $query ) ); |
662
|
|
|
|
663
|
|
|
$instance->doUpdateDependenciesFrom( $queryResult ); |
664
|
|
|
|
665
|
|
|
$this->testEnvironment->executePendingDeferredUpdates(); |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* @dataProvider titleProvider |
670
|
|
|
*/ |
671
|
|
|
public function testTryDoUpdateDependenciesByWithinSkewedTime( $title ) { |
672
|
|
|
|
673
|
|
|
$subject = $this->getMockBuilder( '\SMW\DIWikiPage' ) |
674
|
|
|
->disableOriginalConstructor() |
675
|
|
|
->getMock(); |
676
|
|
|
|
677
|
|
|
$subject->expects( $this->once() ) |
678
|
|
|
->method( 'getHash' ) |
679
|
|
|
->will( $this->returnValue( 'Foo###' ) ); |
680
|
|
|
|
681
|
|
|
$subject->expects( $this->once() ) |
682
|
|
|
->method( 'getTitle' ) |
683
|
|
|
->will( $this->returnValue( $title ) ); |
684
|
|
|
|
685
|
|
|
$connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) |
686
|
|
|
->disableOriginalConstructor() |
687
|
|
|
->getMock(); |
688
|
|
|
|
689
|
|
|
$connectionManager = $this->getMockBuilder( '\SMW\ConnectionManager' ) |
690
|
|
|
->disableOriginalConstructor() |
691
|
|
|
->getMock(); |
692
|
|
|
|
693
|
|
|
$connectionManager->expects( $this->any() ) |
694
|
|
|
->method( 'getConnection' ) |
695
|
|
|
->will( $this->returnValue( $connection ) ); |
696
|
|
|
|
697
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
698
|
|
|
->disableOriginalConstructor() |
699
|
|
|
->getMockForAbstractClass(); |
700
|
|
|
|
701
|
|
|
$store->setConnectionManager( $connectionManager ); |
702
|
|
|
|
703
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
704
|
|
|
->disableOriginalConstructor() |
705
|
|
|
->getMock(); |
706
|
|
|
|
707
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
708
|
|
|
->method( 'getDependencyListByLateRetrievalFrom' ) |
709
|
|
|
->will( $this->returnValue( array() ) ); |
710
|
|
|
|
711
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
712
|
|
|
->disableOriginalConstructor() |
713
|
|
|
->getMock(); |
714
|
|
|
|
715
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
716
|
|
|
->method( 'getId' ) |
717
|
|
|
->will( $this->returnValue( 4 ) ); |
718
|
|
|
|
719
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
720
|
|
|
->method( 'getStore' ) |
721
|
|
|
->will( $this->returnValue( $store ) ); |
722
|
|
|
|
723
|
|
|
$instance = new QueryDependencyLinksStore( |
724
|
|
|
$queryResultDependencyListResolver, |
725
|
|
|
$dependencyLinksTableUpdater |
726
|
|
|
); |
727
|
|
|
|
728
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
729
|
|
|
->disableOriginalConstructor() |
730
|
|
|
->getMock(); |
731
|
|
|
|
732
|
|
|
$query->expects( $this->any() ) |
733
|
|
|
->method( 'getContextPage' ) |
734
|
|
|
->will( $this->returnValue( $subject ) ); |
735
|
|
|
|
736
|
|
|
$query->expects( $this->any() ) |
737
|
|
|
->method( 'getLimit' ) |
738
|
|
|
->will( $this->returnValue( 1 ) ); |
739
|
|
|
|
740
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
741
|
|
|
->disableOriginalConstructor() |
742
|
|
|
->getMock(); |
743
|
|
|
|
744
|
|
|
$queryResult->expects( $this->any() ) |
745
|
|
|
->method( 'getQuery' ) |
746
|
|
|
->will( $this->returnValue( $query ) ); |
747
|
|
|
|
748
|
|
|
$instance->doUpdateDependenciesFrom( $queryResult ); |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
public function titleProvider() { |
752
|
|
|
|
753
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
754
|
|
|
->disableOriginalConstructor() |
755
|
|
|
->getMock(); |
756
|
|
|
|
757
|
|
|
$title->expects( $this->once() ) |
758
|
|
|
->method( 'getTouched' ) |
759
|
|
|
->will( $this->returnValue( wfTimestamp( TS_MW ) + 60 ) ); |
760
|
|
|
|
761
|
|
|
$provider[] = array( |
|
|
|
|
762
|
|
|
$title |
763
|
|
|
); |
764
|
|
|
|
765
|
|
|
$provider[] = array( |
766
|
|
|
null |
767
|
|
|
); |
768
|
|
|
|
769
|
|
|
return $provider; |
770
|
|
|
} |
771
|
|
|
|
772
|
|
|
} |
773
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.