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 testFindPartialEmbeddedQueryTargetLinksHashListFor() { |
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->findEmbeddedQueryTargetLinksHashListFor( array( 42 ), $requestOptions ); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
public function testTryDoUpdateDependenciesByWhileBeingDisabled() { |
331
|
|
|
|
332
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
333
|
|
|
->disableOriginalConstructor() |
334
|
|
|
->getMockForAbstractClass(); |
335
|
|
|
|
336
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
337
|
|
|
->disableOriginalConstructor() |
338
|
|
|
->getMock(); |
339
|
|
|
|
340
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
341
|
|
|
->method( 'getStore' ) |
342
|
|
|
->will( $this->returnValue( $store ) ); |
343
|
|
|
|
344
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
345
|
|
|
->disableOriginalConstructor() |
346
|
|
|
->getMock(); |
347
|
|
|
|
348
|
|
|
$queryResultDependencyListResolver->expects( $this->never() ) |
349
|
|
|
->method( 'getDependencyListByLateRetrieval' ) |
350
|
|
|
->will( $this->returnValue( array() ) ); |
351
|
|
|
|
352
|
|
|
$queryResultDependencyListResolver->expects( $this->never() ) |
353
|
|
|
->method( 'getDependencyList' ) |
354
|
|
|
->will( $this->returnValue( array() ) ); |
355
|
|
|
|
356
|
|
|
$instance = new QueryDependencyLinksStore( |
357
|
|
|
$queryResultDependencyListResolver, |
358
|
|
|
$dependencyLinksTableUpdater |
359
|
|
|
); |
360
|
|
|
|
361
|
|
|
$instance->setEnabled( false ); |
362
|
|
|
$queryResult = ''; |
363
|
|
|
|
364
|
|
|
$instance->doUpdateDependenciesFrom( $queryResult ); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
public function testTryDoUpdateDependenciesByForWhenDependencyListReturnsEmpty() { |
368
|
|
|
|
369
|
|
|
$idTable = $this->getMockBuilder( '\stdClass' ) |
370
|
|
|
->setMethods( array( 'getIDFor' ) ) |
371
|
|
|
->getMock(); |
372
|
|
|
|
373
|
|
|
$idTable->expects( $this->any() ) |
374
|
|
|
->method( 'getIDFor' ) |
375
|
|
|
->will( $this->onConsecutiveCalls( 42, 1001 ) ); |
376
|
|
|
|
377
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
378
|
|
|
->disableOriginalConstructor() |
379
|
|
|
->setMethods( array( 'getObjectIds' ) ) |
380
|
|
|
->getMockForAbstractClass(); |
381
|
|
|
|
382
|
|
|
$store->expects( $this->any() ) |
383
|
|
|
->method( 'getObjectIds' ) |
384
|
|
|
->will( $this->returnValue( $idTable ) ); |
385
|
|
|
|
386
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
387
|
|
|
->disableOriginalConstructor() |
388
|
|
|
->getMock(); |
389
|
|
|
|
390
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
391
|
|
|
->method( 'getStore' ) |
392
|
|
|
->will( $this->returnValue( $store ) ); |
393
|
|
|
|
394
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
395
|
|
|
->disableOriginalConstructor() |
396
|
|
|
->getMock(); |
397
|
|
|
|
398
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
399
|
|
|
->method( 'getDependencyListByLateRetrievalFrom' ) |
400
|
|
|
->will( $this->returnValue( array() ) ); |
401
|
|
|
|
402
|
|
|
$queryResultDependencyListResolver->expects( $this->once() ) |
403
|
|
|
->method( 'getDependencyListFrom' ) |
404
|
|
|
->will( $this->returnValue( array() ) ); |
405
|
|
|
|
406
|
|
|
$instance = new QueryDependencyLinksStore( |
407
|
|
|
$queryResultDependencyListResolver, |
408
|
|
|
$dependencyLinksTableUpdater |
409
|
|
|
); |
410
|
|
|
|
411
|
|
|
$instance->setEnabled( true ); |
412
|
|
|
|
413
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
414
|
|
|
->disableOriginalConstructor() |
415
|
|
|
->getMock(); |
416
|
|
|
|
417
|
|
|
$query->expects( $this->any() ) |
418
|
|
|
->method( 'getContextPage' ) |
419
|
|
|
->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) ); |
420
|
|
|
|
421
|
|
|
$query->expects( $this->any() ) |
422
|
|
|
->method( 'getLimit' ) |
423
|
|
|
->will( $this->returnValue( 1 ) ); |
424
|
|
|
|
425
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
426
|
|
|
->disableOriginalConstructor() |
427
|
|
|
->getMock(); |
428
|
|
|
|
429
|
|
|
$queryResult->expects( $this->any() ) |
430
|
|
|
->method( 'getQuery' ) |
431
|
|
|
->will( $this->returnValue( $query ) ); |
432
|
|
|
|
433
|
|
|
$instance->doUpdateDependenciesFrom( $queryResult ); |
434
|
|
|
|
435
|
|
|
$this->testEnvironment->executePendingDeferredUpdates(); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
public function testdoUpdateDependenciesByFromQueryResult() { |
439
|
|
|
|
440
|
|
|
$connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) |
441
|
|
|
->disableOriginalConstructor() |
442
|
|
|
->getMock(); |
443
|
|
|
|
444
|
|
|
$connectionManager = $this->getMockBuilder( '\SMW\ConnectionManager' ) |
445
|
|
|
->disableOriginalConstructor() |
446
|
|
|
->getMock(); |
447
|
|
|
|
448
|
|
|
$connectionManager->expects( $this->any() ) |
449
|
|
|
->method( 'getConnection' ) |
450
|
|
|
->will( $this->returnValue( $connection ) ); |
451
|
|
|
|
452
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
453
|
|
|
->disableOriginalConstructor() |
454
|
|
|
->setMethods( array( 'getPropertyValues' ) ) |
455
|
|
|
->getMock(); |
456
|
|
|
|
457
|
|
|
$store->setConnectionManager( $connectionManager ); |
458
|
|
|
|
459
|
|
|
$store->expects( $this->any() ) |
460
|
|
|
->method( 'getPropertyValues' ) |
461
|
|
|
->will( $this->returnValue( array() ) ); |
462
|
|
|
|
463
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
464
|
|
|
->disableOriginalConstructor() |
465
|
|
|
->getMock(); |
466
|
|
|
|
467
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
468
|
|
|
->method( 'getDependencyListByLateRetrievalFrom' ) |
469
|
|
|
->will( $this->returnValue( array() ) ); |
470
|
|
|
|
471
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
472
|
|
|
->method( 'getDependencyListFrom' ) |
473
|
|
|
->will( $this->returnValue( array( null, DIWikiPage::newFromText( 'Foo' ) ) ) ); |
474
|
|
|
|
475
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
476
|
|
|
->disableOriginalConstructor() |
477
|
|
|
->getMock(); |
478
|
|
|
|
479
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
480
|
|
|
->method( 'getId' ) |
481
|
|
|
->will( $this->onConsecutiveCalls( 42, 1001 ) ); |
482
|
|
|
|
483
|
|
|
$dependencyLinksTableUpdater->expects( $this->atLeastOnce() ) |
484
|
|
|
->method( 'addToUpdateList' ) |
485
|
|
|
->with( |
486
|
|
|
$this->equalTo( 1001 ), |
487
|
|
|
$this->anything() ); |
488
|
|
|
|
489
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
490
|
|
|
->method( 'getStore' ) |
491
|
|
|
->will( $this->returnValue( $store ) ); |
492
|
|
|
|
493
|
|
|
$instance = new QueryDependencyLinksStore( |
494
|
|
|
$queryResultDependencyListResolver, |
495
|
|
|
$dependencyLinksTableUpdater |
496
|
|
|
); |
497
|
|
|
|
498
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
499
|
|
|
->disableOriginalConstructor() |
500
|
|
|
->getMock(); |
501
|
|
|
|
502
|
|
|
$query->expects( $this->any() ) |
503
|
|
|
->method( 'getContextPage' ) |
504
|
|
|
->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) ); |
505
|
|
|
|
506
|
|
|
$query->expects( $this->any() ) |
507
|
|
|
->method( 'getLimit' ) |
508
|
|
|
->will( $this->returnValue( 1 ) ); |
509
|
|
|
|
510
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
511
|
|
|
->disableOriginalConstructor() |
512
|
|
|
->getMock(); |
513
|
|
|
|
514
|
|
|
$queryResult->expects( $this->any() ) |
515
|
|
|
->method( 'getQuery' ) |
516
|
|
|
->will( $this->returnValue( $query ) ); |
517
|
|
|
|
518
|
|
|
$instance->doUpdateDependenciesFrom( $queryResult ); |
519
|
|
|
|
520
|
|
|
$this->testEnvironment->executePendingDeferredUpdates(); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
public function testdoUpdateDependenciesByFromQueryResultWhereObjectIdIsYetUnknownWhichRequiresToCreateTheIdOnTheFly() { |
524
|
|
|
|
525
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
526
|
|
|
->disableOriginalConstructor() |
527
|
|
|
->getMock(); |
528
|
|
|
|
529
|
|
|
$store->expects( $this->any() ) |
530
|
|
|
->method( 'getPropertyValues' ) |
531
|
|
|
->will( $this->returnValue( array() ) ); |
532
|
|
|
|
533
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
534
|
|
|
->disableOriginalConstructor() |
535
|
|
|
->getMock(); |
536
|
|
|
|
537
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
538
|
|
|
->method( 'getDependencyListByLateRetrievalFrom' ) |
539
|
|
|
->will( $this->returnValue( array() ) ); |
540
|
|
|
|
541
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
542
|
|
|
->method( 'getDependencyListFrom' ) |
543
|
|
|
->will( $this->returnValue( array( DIWikiPage::newFromText( 'Foo', NS_CATEGORY ) ) ) ); |
544
|
|
|
|
545
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
546
|
|
|
->disableOriginalConstructor() |
547
|
|
|
->getMock(); |
548
|
|
|
|
549
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
550
|
|
|
->method( 'getId' ) |
551
|
|
|
->will( $this->onConsecutiveCalls( 0, 0 ) ); |
552
|
|
|
|
553
|
|
|
$dependencyLinksTableUpdater->expects( $this->once() ) |
554
|
|
|
->method( 'createId' ) |
555
|
|
|
->will( $this->returnValue( 1001 ) ); |
556
|
|
|
|
557
|
|
|
$dependencyLinksTableUpdater->expects( $this->atLeastOnce() ) |
558
|
|
|
->method( 'addToUpdateList' ) |
559
|
|
|
->with( |
560
|
|
|
$this->equalTo( 1001 ), |
561
|
|
|
$this->anything() ); |
562
|
|
|
|
563
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
564
|
|
|
->method( 'getStore' ) |
565
|
|
|
->will( $this->returnValue( $store ) ); |
566
|
|
|
|
567
|
|
|
$instance = new QueryDependencyLinksStore( |
568
|
|
|
$queryResultDependencyListResolver, |
569
|
|
|
$dependencyLinksTableUpdater |
570
|
|
|
); |
571
|
|
|
|
572
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
573
|
|
|
->disableOriginalConstructor() |
574
|
|
|
->getMock(); |
575
|
|
|
|
576
|
|
|
$query->expects( $this->any() ) |
577
|
|
|
->method( 'getContextPage' ) |
578
|
|
|
->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) ); |
579
|
|
|
|
580
|
|
|
$query->expects( $this->any() ) |
581
|
|
|
->method( 'getLimit' ) |
582
|
|
|
->will( $this->returnValue( 1 ) ); |
583
|
|
|
|
584
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
585
|
|
|
->disableOriginalConstructor() |
586
|
|
|
->getMock(); |
587
|
|
|
|
588
|
|
|
$queryResult->expects( $this->any() ) |
589
|
|
|
->method( 'getQuery' ) |
590
|
|
|
->will( $this->returnValue( $query ) ); |
591
|
|
|
|
592
|
|
|
$instance->doUpdateDependenciesFrom( $queryResult ); |
593
|
|
|
|
594
|
|
|
$this->testEnvironment->executePendingDeferredUpdates(); |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
/** |
598
|
|
|
* @dataProvider titleProvider |
599
|
|
|
*/ |
600
|
|
|
public function testTryDoUpdateDependenciesByWithinSkewedTime( $title ) { |
601
|
|
|
|
602
|
|
|
$subject = $this->getMockBuilder( '\SMW\DIWikiPage' ) |
603
|
|
|
->disableOriginalConstructor() |
604
|
|
|
->getMock(); |
605
|
|
|
|
606
|
|
|
$subject->expects( $this->once() ) |
607
|
|
|
->method( 'getHash' ) |
608
|
|
|
->will( $this->returnValue( 'Foo###' ) ); |
609
|
|
|
|
610
|
|
|
$subject->expects( $this->once() ) |
611
|
|
|
->method( 'getTitle' ) |
612
|
|
|
->will( $this->returnValue( $title ) ); |
613
|
|
|
|
614
|
|
|
$connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) |
615
|
|
|
->disableOriginalConstructor() |
616
|
|
|
->getMock(); |
617
|
|
|
|
618
|
|
|
$connectionManager = $this->getMockBuilder( '\SMW\ConnectionManager' ) |
619
|
|
|
->disableOriginalConstructor() |
620
|
|
|
->getMock(); |
621
|
|
|
|
622
|
|
|
$connectionManager->expects( $this->any() ) |
623
|
|
|
->method( 'getConnection' ) |
624
|
|
|
->will( $this->returnValue( $connection ) ); |
625
|
|
|
|
626
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
627
|
|
|
->disableOriginalConstructor() |
628
|
|
|
->getMockForAbstractClass(); |
629
|
|
|
|
630
|
|
|
$store->setConnectionManager( $connectionManager ); |
631
|
|
|
|
632
|
|
|
$queryResultDependencyListResolver = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryResultDependencyListResolver' ) |
633
|
|
|
->disableOriginalConstructor() |
634
|
|
|
->getMock(); |
635
|
|
|
|
636
|
|
|
$queryResultDependencyListResolver->expects( $this->any() ) |
637
|
|
|
->method( 'getDependencyListByLateRetrievalFrom' ) |
638
|
|
|
->will( $this->returnValue( array() ) ); |
639
|
|
|
|
640
|
|
|
$dependencyLinksTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\DependencyLinksTableUpdater' ) |
641
|
|
|
->disableOriginalConstructor() |
642
|
|
|
->getMock(); |
643
|
|
|
|
644
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
645
|
|
|
->method( 'getId' ) |
646
|
|
|
->will( $this->returnValue( 4 ) ); |
647
|
|
|
|
648
|
|
|
$dependencyLinksTableUpdater->expects( $this->any() ) |
649
|
|
|
->method( 'getStore' ) |
650
|
|
|
->will( $this->returnValue( $store ) ); |
651
|
|
|
|
652
|
|
|
$instance = new QueryDependencyLinksStore( |
653
|
|
|
$queryResultDependencyListResolver, |
654
|
|
|
$dependencyLinksTableUpdater |
655
|
|
|
); |
656
|
|
|
|
657
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
658
|
|
|
->disableOriginalConstructor() |
659
|
|
|
->getMock(); |
660
|
|
|
|
661
|
|
|
$query->expects( $this->any() ) |
662
|
|
|
->method( 'getContextPage' ) |
663
|
|
|
->will( $this->returnValue( $subject ) ); |
664
|
|
|
|
665
|
|
|
$query->expects( $this->any() ) |
666
|
|
|
->method( 'getLimit' ) |
667
|
|
|
->will( $this->returnValue( 1 ) ); |
668
|
|
|
|
669
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
670
|
|
|
->disableOriginalConstructor() |
671
|
|
|
->getMock(); |
672
|
|
|
|
673
|
|
|
$queryResult->expects( $this->any() ) |
674
|
|
|
->method( 'getQuery' ) |
675
|
|
|
->will( $this->returnValue( $query ) ); |
676
|
|
|
|
677
|
|
|
$instance->doUpdateDependenciesFrom( $queryResult ); |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
public function titleProvider() { |
681
|
|
|
|
682
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
683
|
|
|
->disableOriginalConstructor() |
684
|
|
|
->getMock(); |
685
|
|
|
|
686
|
|
|
$title->expects( $this->once() ) |
687
|
|
|
->method( 'getTouched' ) |
688
|
|
|
->will( $this->returnValue( wfTimestamp( TS_MW ) + 60 ) ); |
689
|
|
|
|
690
|
|
|
$provider[] = array( |
|
|
|
|
691
|
|
|
$title |
692
|
|
|
); |
693
|
|
|
|
694
|
|
|
$provider[] = array( |
695
|
|
|
null |
696
|
|
|
); |
697
|
|
|
|
698
|
|
|
return $provider; |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
} |
702
|
|
|
|
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.