1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SCI\Tests; |
4
|
|
|
|
5
|
|
|
use SCI\ReferenceBacklinksLookup; |
6
|
|
|
use SCI\PropertyRegistry; |
7
|
|
|
use SMW\DIWikiPage; |
8
|
|
|
use SMW\DIProperty; |
9
|
|
|
use SMWDIBlob as DIBlob; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \SCI\ReferenceBacklinksLookup |
13
|
|
|
* @group semantic-cite |
14
|
|
|
* |
15
|
|
|
* @license GNU GPL v2+ |
16
|
|
|
* @since 1.0 |
17
|
|
|
* |
18
|
|
|
* @author mwjames |
19
|
|
|
*/ |
20
|
|
|
class ReferenceBacklinksLookupTest extends \PHPUnit_Framework_TestCase { |
21
|
|
|
|
22
|
|
|
public function testCanConstruct() { |
23
|
|
|
|
24
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
25
|
|
|
->disableOriginalConstructor() |
26
|
|
|
->getMockForAbstractClass(); |
27
|
|
|
|
28
|
|
|
$this->assertInstanceOf( |
29
|
|
|
'\SCI\ReferenceBacklinksLookup', |
30
|
|
|
new ReferenceBacklinksLookup( $store ) |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testtryToFindCitationKeyFor() { |
35
|
|
|
|
36
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
37
|
|
|
->disableOriginalConstructor() |
38
|
|
|
->getMock(); |
39
|
|
|
|
40
|
|
|
$semanticData->expects( $this->once() ) |
41
|
|
|
->method( 'getPropertyValues' ) |
42
|
|
|
->with( $this->equalTo( new DIProperty( PropertyRegistry::SCI_CITE_KEY ) ) ) |
43
|
|
|
->will( $this->returnValue( [ 'Foo', 'Bar' ] ) ); |
44
|
|
|
|
45
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
46
|
|
|
->disableOriginalConstructor() |
47
|
|
|
->getMockForAbstractClass(); |
48
|
|
|
|
49
|
|
|
$store->expects( $this->once() ) |
50
|
|
|
->method( 'getSemanticData' ) |
51
|
|
|
->will( $this->returnValue( $semanticData ) ); |
52
|
|
|
|
53
|
|
|
$instance = new ReferenceBacklinksLookup( $store ); |
54
|
|
|
$instance->setStore( $store ); |
55
|
|
|
|
56
|
|
|
$this->assertEquals( |
57
|
|
|
'Bar', |
58
|
|
|
$instance->tryToFindCitationKeyFor( DIWikiPage::newFromText( __METHOD__ ) ) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testTryToAddReferenceBacklinksForNoKeys() { |
63
|
|
|
|
64
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
65
|
|
|
->disableOriginalConstructor() |
66
|
|
|
->getMock(); |
67
|
|
|
|
68
|
|
|
$semanticData->expects( $this->once() ) |
69
|
|
|
->method( 'getSubject' ) |
70
|
|
|
->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) ); |
71
|
|
|
|
72
|
|
|
$semanticData->expects( $this->once() ) |
73
|
|
|
->method( 'getPropertyValues' ) |
74
|
|
|
->with( $this->equalTo( new DIProperty( PropertyRegistry::SCI_CITE_KEY ) ) ) |
75
|
|
|
->will( $this->returnValue( [] ) ); |
76
|
|
|
|
77
|
|
|
$semanticData->expects( $this->never() ) |
78
|
|
|
->method( 'addPropertyObjectValue' ); |
79
|
|
|
|
80
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
81
|
|
|
->disableOriginalConstructor() |
82
|
|
|
->getMockForAbstractClass(); |
83
|
|
|
|
84
|
|
|
$store->expects( $this->once() ) |
85
|
|
|
->method( 'getSemanticData' ) |
86
|
|
|
->will( $this->returnValue( $semanticData ) ); |
87
|
|
|
|
88
|
|
|
$requestOptions = new \stdClass; |
89
|
|
|
$requestOptions->limit = 5; |
90
|
|
|
$requestOptions->offset = 0; |
91
|
|
|
|
92
|
|
|
$instance = new ReferenceBacklinksLookup( $store ); |
93
|
|
|
$instance->setRequestOptions( $requestOptions ); |
94
|
|
|
|
95
|
|
|
$instance->addReferenceBacklinksTo( |
96
|
|
|
$semanticData |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testAddReferenceBacklinks() { |
101
|
|
|
|
102
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
103
|
|
|
->disableOriginalConstructor() |
104
|
|
|
->getMock(); |
105
|
|
|
|
106
|
|
|
$semanticData->expects( $this->once() ) |
107
|
|
|
->method( 'getSubject' ) |
108
|
|
|
->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) ); |
109
|
|
|
|
110
|
|
|
$semanticData->expects( $this->once() ) |
111
|
|
|
->method( 'getPropertyValues' ) |
112
|
|
|
->will( $this->returnValue( [ DIWikiPage::newFromText( 'Bar' ) ] ) ); |
113
|
|
|
|
114
|
|
|
$semanticData->expects( $this->atLeastOnce() ) |
115
|
|
|
->method( 'addPropertyObjectValue' ) |
116
|
|
|
->with( |
117
|
|
|
$this->equalTo( new DIProperty( PropertyRegistry::SCI_CITE_REFERENCE ) ), |
118
|
|
|
$this->anything() ); |
119
|
|
|
|
120
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
121
|
|
|
->disableOriginalConstructor() |
122
|
|
|
->getMock(); |
123
|
|
|
|
124
|
|
|
$queryResult->expects( $this->once() ) |
125
|
|
|
->method( 'getResults' ) |
126
|
|
|
->will( $this->returnValue( [ DIWikiPage::newFromText( 'Foo' ) ] ) ); |
127
|
|
|
|
128
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
129
|
|
|
->disableOriginalConstructor() |
130
|
|
|
->getMockForAbstractClass(); |
131
|
|
|
|
132
|
|
|
$store->expects( $this->once() ) |
133
|
|
|
->method( 'getQueryResult' ) |
134
|
|
|
->will( $this->returnValue( $queryResult ) ); |
135
|
|
|
|
136
|
|
|
$store->expects( $this->once() ) |
137
|
|
|
->method( 'getSemanticData' ) |
138
|
|
|
->will( $this->returnValue( $semanticData ) ); |
139
|
|
|
|
140
|
|
|
$instance = new ReferenceBacklinksLookup( $store ); |
141
|
|
|
|
142
|
|
|
$instance->addReferenceBacklinksTo( |
143
|
|
|
$semanticData |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testGetSpecialPropertySearchFurtherLink() { |
148
|
|
|
|
149
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
150
|
|
|
->disableOriginalConstructor() |
151
|
|
|
->getMock(); |
152
|
|
|
|
153
|
|
|
$semanticData->expects( $this->once() ) |
154
|
|
|
->method( 'getPropertyValues' ) |
155
|
|
|
->will( $this->returnValue( [ new DIBlob( 'Bar' ) ] ) ); |
156
|
|
|
|
157
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
158
|
|
|
->disableOriginalConstructor() |
159
|
|
|
->getMockForAbstractClass(); |
160
|
|
|
|
161
|
|
|
$store->expects( $this->once() ) |
162
|
|
|
->method( 'getSemanticData' ) |
163
|
|
|
->will( $this->returnValue( $semanticData ) ); |
164
|
|
|
|
165
|
|
|
$property = new DIProperty( PropertyRegistry::SCI_CITE_REFERENCE ); |
166
|
|
|
$subject = DIWikiPage::newFromText( __METHOD__ ); |
167
|
|
|
|
168
|
|
|
$instance = new ReferenceBacklinksLookup( $store ); |
169
|
|
|
|
170
|
|
|
$result = $instance->getSpecialPropertySearchFurtherLink( |
171
|
|
|
$property, |
172
|
|
|
$subject, |
173
|
|
|
$html |
174
|
|
|
); |
175
|
|
|
|
176
|
|
|
$this->assertFalse( |
177
|
|
|
$result |
178
|
|
|
); |
179
|
|
|
|
180
|
|
|
$this->assertContains( |
181
|
|
|
'SearchByProperty', |
182
|
|
|
$html |
183
|
|
|
); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
} |
187
|
|
|
|