1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SG\Tests\Maintenance; |
4
|
|
|
|
5
|
|
|
use SG\Maintenance\GlossaryCacheRebuilder; |
6
|
|
|
use SG\Cache\GlossaryCache; |
7
|
|
|
|
8
|
|
|
use Title; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @uses \SG\Maintenance\GlossaryCacheRebuilder |
12
|
|
|
* |
13
|
|
|
* @ingroup Test |
14
|
|
|
* |
15
|
|
|
* @group SG |
16
|
|
|
* @group SGExtension |
17
|
|
|
* |
18
|
|
|
* @license GNU GPL v2+ |
19
|
|
|
* @since 1.1 |
20
|
|
|
* |
21
|
|
|
* @author mwjames |
22
|
|
|
*/ |
23
|
|
|
class GlossaryCacheRebuilderTest extends \PHPUnit_Framework_TestCase { |
24
|
|
|
|
25
|
|
|
public function testCanConstruct() { |
26
|
|
|
|
27
|
|
|
$store = $this->getMockForAbstractClass( '\SMW\Store' ); |
28
|
|
|
|
29
|
|
|
$glossaryCache = $this->getMockBuilder( '\SG\Cache\GlossaryCache' ) |
30
|
|
|
->disableOriginalConstructor() |
31
|
|
|
->getMock(); |
32
|
|
|
|
33
|
|
|
$this->assertInstanceOf( |
34
|
|
|
'\SG\Maintenance\GlossaryCacheRebuilder', |
35
|
|
|
new GlossaryCacheRebuilder( $store, $glossaryCache ) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testRebuildPagesThatContainDuplicateEntity() { |
40
|
|
|
|
41
|
|
|
$subject = $this->getMockBuilder( '\SMW\DIWikiPage' ) |
42
|
|
|
->disableOriginalConstructor() |
43
|
|
|
->getMock(); |
44
|
|
|
|
45
|
|
|
$subject->expects( $this->exactly( 2 ) ) |
46
|
|
|
->method( 'getTitle' ) |
47
|
|
|
->will( $this->returnValue( Title::newFromText( __METHOD__ ) ) ); |
48
|
|
|
|
49
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
50
|
|
|
->disableOriginalConstructor() |
51
|
|
|
->getMock(); |
52
|
|
|
|
53
|
|
|
$queryResult->expects( $this->once() ) |
54
|
|
|
->method( 'getResults' ) |
55
|
|
|
->will( $this->returnValue( array( $subject, $subject ) ) ); |
56
|
|
|
|
57
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
58
|
|
|
->disableOriginalConstructor() |
59
|
|
|
->getMockForAbstractClass(); |
60
|
|
|
|
61
|
|
|
$store->expects( $this->at( 1 ) ) |
62
|
|
|
->method( 'getQueryResult' ) |
63
|
|
|
->will( $this->returnValue( $queryResult ) ); |
64
|
|
|
|
65
|
|
|
$bagOStuff = $this->getMockBuilder( 'BagOStuff' ) |
66
|
|
|
->disableOriginalConstructor() |
67
|
|
|
->getMockForAbstractClass(); |
68
|
|
|
|
69
|
|
|
$bagOStuff->expects( $this->at( 0 ) ) |
70
|
|
|
->method( 'delete' ) |
71
|
|
|
->with( $this->stringContains( 'lingotree' ) ); |
72
|
|
|
|
73
|
|
|
$bagOStuff->expects( $this->at( 1 ) ) |
74
|
|
|
->method( 'delete' ) |
75
|
|
|
->with( $this->stringContains( 'semanticglossary' ) ); |
76
|
|
|
|
77
|
|
|
$bagOStuff->expects( $this->at( 2 ) ) |
78
|
|
|
->method( 'delete' ) |
79
|
|
|
->with( $this->stringContains( 'semanticglossary' ) ); |
80
|
|
|
|
81
|
|
|
$instance = new GlossaryCacheRebuilder( |
82
|
|
|
$store, |
83
|
|
|
new GlossaryCache( $bagOStuff ) |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$instance->setParameters( array() ); |
87
|
|
|
|
88
|
|
|
$this->assertTrue( $instance->rebuild() ); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( |
91
|
|
|
1, |
92
|
|
|
$instance->getRebuildCount(), |
93
|
|
|
'Asserts that rebuild is counted only once because the duplicate entity was removed' |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|