1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SBL\Tests; |
4
|
|
|
|
5
|
|
|
use SBL\ByPropertyHierarchicalLinksFinder; |
6
|
|
|
use SMW\DIWikiPage; |
7
|
|
|
use SMW\DIProperty; |
8
|
|
|
use SMW\ApplicationFactory; |
9
|
|
|
use Title; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \SBL\ByPropertyHierarchicalLinksFinder |
13
|
|
|
* @group semantic-breadcrumb-links |
14
|
|
|
* |
15
|
|
|
* @license GNU GPL v2+ |
16
|
|
|
* @since 1.0 |
17
|
|
|
* |
18
|
|
|
* @author mwjames |
19
|
|
|
*/ |
20
|
|
|
class ByPropertyHierarchicalLinksFinderTest 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
|
|
|
'\SBL\ByPropertyHierarchicalLinksFinder', |
30
|
|
|
new ByPropertyHierarchicalLinksFinder( $store ) |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testNoValidConfigurationForAnyNamespace() { |
35
|
|
|
|
36
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
37
|
|
|
->disableOriginalConstructor() |
38
|
|
|
->getMockForAbstractClass(); |
39
|
|
|
|
40
|
|
|
$instance = new ByPropertyHierarchicalLinksFinder( $store ); |
41
|
|
|
|
42
|
|
|
$instance->findLinksBySubject( new DIWikiPage( 'Foo', NS_MAIN ) ); |
43
|
|
|
|
44
|
|
|
$this->assertEmpty( |
45
|
|
|
$instance->getParents() |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->assertEmpty( |
49
|
|
|
$instance->getChildren() |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testEmptyResultByTryingToFindAntecedent() { |
54
|
|
|
|
55
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
56
|
|
|
$property = DIProperty::newFromUserLabel( 'Bar' ); |
57
|
|
|
|
58
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
59
|
|
|
->disableOriginalConstructor() |
60
|
|
|
->getMockForAbstractClass(); |
61
|
|
|
|
62
|
|
|
$store->expects( $this->once() ) |
63
|
|
|
->method( 'getPropertyValues' ) |
64
|
|
|
->with( |
65
|
|
|
$this->equalTo( $subject ), |
66
|
|
|
$this->equalTo( $property ) ) |
67
|
|
|
->will( $this->returnValue( [] ) ); |
68
|
|
|
|
69
|
|
|
$instance = new ByPropertyHierarchicalLinksFinder( $store ); |
70
|
|
|
|
71
|
|
|
$instance->setFindClosestDescendantState( false ); |
72
|
|
|
$instance->setPropertySearchPatternByNamespace( |
73
|
|
|
[ NS_MAIN => [ 'Bar' ] ] |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$instance->findLinksBySubject( $subject ); |
77
|
|
|
|
78
|
|
|
$this->assertEmpty( |
79
|
|
|
$instance->getParents() |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$this->assertEmpty( |
83
|
|
|
$instance->getChildren() |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testFindAntecedentForMultiplePropertySearchPattern() { |
88
|
|
|
|
89
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
90
|
|
|
|
91
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
92
|
|
|
->disableOriginalConstructor() |
93
|
|
|
->setMethods( [ 'getRedirectTarget' ] ) |
94
|
|
|
->getMockForAbstractClass(); |
95
|
|
|
|
96
|
|
|
$store->expects( $this->at( 0 ) ) |
97
|
|
|
->method( 'getPropertyValues' ) |
98
|
|
|
->with( |
99
|
|
|
$this->equalTo( $subject ), |
100
|
|
|
$this->equalTo( DIProperty::newFromUserLabel( 'Bar' ) ) ) |
101
|
|
|
->will( $this->returnValue( [ new DIWikiPage( 'Ichi', NS_MAIN ) ] ) ); |
102
|
|
|
|
103
|
|
|
$store->expects( $this->at( 1 ) ) |
104
|
|
|
->method( 'getRedirectTarget' ) |
105
|
|
|
->with( |
106
|
|
|
$this->equalTo( new DIWikiPage( 'Ichi', NS_MAIN ) ) ) |
107
|
|
|
->will( $this->returnValue( new DIWikiPage( 'Ichi', NS_MAIN ) ) ); |
108
|
|
|
|
109
|
|
|
$store->expects( $this->at( 2 ) ) |
110
|
|
|
->method( 'getPropertyValues' ) |
111
|
|
|
->with( |
112
|
|
|
$this->equalTo( new DIWikiPage( 'Ichi', NS_MAIN ) ), |
113
|
|
|
$this->equalTo( DIProperty::newFromUserLabel( 'Yin' )) ) |
114
|
|
|
->will( $this->returnValue( [ new DIWikiPage( 'Ni', NS_MAIN ) ] ) ); |
115
|
|
|
|
116
|
|
|
$store->expects( $this->at( 3 ) ) |
117
|
|
|
->method( 'getRedirectTarget' ) |
118
|
|
|
->with( |
119
|
|
|
$this->equalTo( new DIWikiPage( 'Ni', NS_MAIN ) ) ) |
120
|
|
|
->will( $this->returnValue( new DIWikiPage( 'San', NS_MAIN ) ) ); |
121
|
|
|
|
122
|
|
|
$instance = new ByPropertyHierarchicalLinksFinder( $store ); |
123
|
|
|
|
124
|
|
|
$instance->setFindClosestDescendantState( false ); |
125
|
|
|
|
126
|
|
|
$instance->setPropertySearchPatternByNamespace( |
127
|
|
|
[ NS_MAIN => [ 'Bar', 'Yin' ] ] |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$instance->findLinksBySubject( $subject ); |
131
|
|
|
|
132
|
|
|
$this->assertEquals( |
133
|
|
|
[ |
134
|
|
|
new DIWikiPage( 'Ichi', NS_MAIN ), |
135
|
|
|
new DIWikiPage( 'San', NS_MAIN ) ], |
136
|
|
|
$instance->getParents() |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
$this->assertEmpty( |
140
|
|
|
$instance->getChildren() |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testCheckCircularReferenceForSomeSubject() { |
145
|
|
|
|
146
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
147
|
|
|
|
148
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
149
|
|
|
->disableOriginalConstructor() |
150
|
|
|
->getMockForAbstractClass(); |
151
|
|
|
|
152
|
|
|
$store->expects( $this->at( 0 ) ) |
153
|
|
|
->method( 'getPropertyValues' ) |
154
|
|
|
->with( |
155
|
|
|
$this->equalTo( $subject ), |
156
|
|
|
$this->equalTo( DIProperty::newFromUserLabel( 'Bar' ) ) ) |
157
|
|
|
->will( $this->returnValue( [ $subject ] ) ); |
158
|
|
|
|
159
|
|
|
$instance = new ByPropertyHierarchicalLinksFinder( $store ); |
160
|
|
|
|
161
|
|
|
$instance->setFindClosestDescendantState( false ); |
162
|
|
|
|
163
|
|
|
$instance->setPropertySearchPatternByNamespace( |
164
|
|
|
[ NS_MAIN => [ 'Bar', 'Yin' ] ] |
165
|
|
|
); |
166
|
|
|
|
167
|
|
|
$instance->findLinksBySubject( $subject ); |
168
|
|
|
|
169
|
|
|
$this->assertEmpty( |
170
|
|
|
$instance->getParents() |
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
$this->assertEmpty( |
174
|
|
|
$instance->getChildren() |
175
|
|
|
); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function testChildSearchForValidPageTypeProperty() { |
179
|
|
|
|
180
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
181
|
|
|
|
182
|
|
|
$property = DIProperty::newFromUserLabel( 'Bar' ); |
183
|
|
|
$property->setPropertyTypeId( '_wpg' ); |
|
|
|
|
184
|
|
|
|
185
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
186
|
|
|
->disableOriginalConstructor() |
187
|
|
|
->getMockForAbstractClass(); |
188
|
|
|
|
189
|
|
|
$store->expects( $this->atLeastOnce() ) |
190
|
|
|
->method( 'getPropertyValues' ) |
191
|
|
|
->will( $this->returnValue( [] ) ); |
192
|
|
|
|
193
|
|
|
$store->expects( $this->at( 1 ) ) |
194
|
|
|
->method( 'getPropertySubjects' ) |
195
|
|
|
->with( |
196
|
|
|
$this->equalTo( $property ), |
197
|
|
|
$this->equalTo( $subject ) ) |
198
|
|
|
->will( $this->returnValue( [ |
199
|
|
|
new DIWikiPage( 'Foo', NS_MAIN ), |
200
|
|
|
new DIWikiPage( 'NotEqualToFoo', NS_MAIN ), |
201
|
|
|
new DIWikiPage( 'AnotherChild', NS_MAIN ) ] ) ); |
202
|
|
|
|
203
|
|
|
$instance = new ByPropertyHierarchicalLinksFinder( $store ); |
204
|
|
|
|
205
|
|
|
$instance->setFindClosestDescendantState( true ); |
206
|
|
|
|
207
|
|
|
$instance->setPropertySearchPatternByNamespace( |
208
|
|
|
[ NS_MAIN => [ 'Bar' ] ] |
209
|
|
|
); |
210
|
|
|
|
211
|
|
|
$instance->findLinksBySubject( $subject ); |
212
|
|
|
|
213
|
|
|
$this->assertEmpty( |
214
|
|
|
$instance->getParents() |
215
|
|
|
); |
216
|
|
|
|
217
|
|
|
$this->assertEquals( |
218
|
|
|
[ |
219
|
|
|
new DIWikiPage( 'NotEqualToFoo', NS_MAIN ), |
220
|
|
|
new DIWikiPage( 'AnotherChild', NS_MAIN ) ], |
221
|
|
|
$instance->getChildren() |
222
|
|
|
); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
public function testChildSearchForInvalidPropertyType() { |
226
|
|
|
|
227
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
228
|
|
|
|
229
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
230
|
|
|
->disableOriginalConstructor() |
231
|
|
|
->getMockForAbstractClass(); |
232
|
|
|
|
233
|
|
|
$store->expects( $this->atLeastOnce() ) |
234
|
|
|
->method( 'getPropertyValues' ) |
235
|
|
|
->will( $this->returnValue( [] ) ); |
236
|
|
|
|
237
|
|
|
$store->expects( $this->never() ) |
238
|
|
|
->method( 'getPropertySubjects' ); |
239
|
|
|
|
240
|
|
|
$instance = new ByPropertyHierarchicalLinksFinder( $store ); |
241
|
|
|
|
242
|
|
|
$instance->setFindClosestDescendantState( true ); |
243
|
|
|
|
244
|
|
|
$instance->setPropertySearchPatternByNamespace( |
245
|
|
|
[ NS_MAIN => [ '_MDAT' ] ] |
246
|
|
|
); |
247
|
|
|
|
248
|
|
|
$instance->findLinksBySubject( $subject ); |
249
|
|
|
|
250
|
|
|
$this->assertEmpty( |
251
|
|
|
$instance->getParents() |
252
|
|
|
); |
253
|
|
|
|
254
|
|
|
$this->assertEmpty( |
255
|
|
|
$instance->getChildren() |
256
|
|
|
); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
} |
260
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.