1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SEQL\ByHttpRequest\Tests; |
4
|
|
|
|
5
|
|
|
use SEQL\ByHttpRequest\CannedResultArray; |
6
|
|
|
use SMW\DIWikiPage; |
7
|
|
|
use SMW\DIProperty; |
8
|
|
|
use SMWDINumber as DINumber; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \SEQL\ByHttpRequest\CannedResultArray |
12
|
|
|
* @group semantic-external-query-lookup |
13
|
|
|
* |
14
|
|
|
* @license GNU GPL v2+ |
15
|
|
|
* @since 1.0 |
16
|
|
|
* |
17
|
|
|
* @author mwjames |
18
|
|
|
*/ |
19
|
|
|
class CannedResultArrayTest extends \PHPUnit_Framework_TestCase { |
20
|
|
|
|
21
|
|
|
private $jsonResponseParser; |
22
|
|
|
|
23
|
|
|
protected function setUp() { |
24
|
|
|
|
25
|
|
|
$this->jsonResponseParser = $this->getMockBuilder( '\SEQL\ByHttpRequest\JsonResponseParser' ) |
26
|
|
|
->disableOriginalConstructor() |
27
|
|
|
->getMock(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testCanConstruct() { |
31
|
|
|
|
32
|
|
|
$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) |
33
|
|
|
->disableOriginalConstructor() |
34
|
|
|
->getMock(); |
35
|
|
|
|
36
|
|
|
$this->assertInstanceOf( |
37
|
|
|
'\SEQL\ByHttpRequest\CannedResultArray', |
38
|
|
|
new CannedResultArray( new DIWikiPage( 'Foo', NS_MAIN ), $printRequest, $this->jsonResponseParser ) |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testGetResultSubject() { |
43
|
|
|
|
44
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
45
|
|
|
|
46
|
|
|
$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) |
47
|
|
|
->disableOriginalConstructor() |
48
|
|
|
->getMock(); |
49
|
|
|
|
50
|
|
|
$instance = new CannedResultArray( |
51
|
|
|
$subject, |
52
|
|
|
$printRequest, |
53
|
|
|
$this->jsonResponseParser |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$this->assertEquals( |
57
|
|
|
$subject, |
58
|
|
|
$instance->getResultSubject() |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testGetContentForMode_PRINT_THIS() { |
63
|
|
|
|
64
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
65
|
|
|
|
66
|
|
|
$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) |
67
|
|
|
->disableOriginalConstructor() |
68
|
|
|
->getMock(); |
69
|
|
|
|
70
|
|
|
$printRequest->expects( $this->any() ) |
71
|
|
|
->method( 'getMode' ) |
72
|
|
|
->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_THIS ) ); |
73
|
|
|
|
74
|
|
|
$instance = new CannedResultArray( |
75
|
|
|
$subject, |
76
|
|
|
$printRequest, |
77
|
|
|
$this->jsonResponseParser |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$this->assertDataItem( |
81
|
|
|
$subject, |
82
|
|
|
$instance |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testGetContentForMode_PRINT_CCAT() { |
87
|
|
|
|
88
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
89
|
|
|
$category = new DIWikiPage( 'Bar', NS_CATEGORY, 'mw-foo' ); |
90
|
|
|
|
91
|
|
|
$this->jsonResponseParser->expects( $this->any() ) |
92
|
|
|
->method( 'getPropertyValuesFor' ) |
93
|
|
|
->with( |
94
|
|
|
$this->equalTo( $subject ), |
95
|
|
|
$this->equalTo( new DIProperty( '_INST' ) ) ) |
96
|
|
|
->will( $this->returnValue( array( $category ) ) ); |
97
|
|
|
|
98
|
|
|
$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) |
99
|
|
|
->disableOriginalConstructor() |
100
|
|
|
->getMock(); |
101
|
|
|
|
102
|
|
|
$printRequest->expects( $this->any() ) |
103
|
|
|
->method( 'getMode' ) |
104
|
|
|
->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_CCAT ) ); |
105
|
|
|
|
106
|
|
|
$instance = new CannedResultArray( |
107
|
|
|
$subject, |
108
|
|
|
$printRequest, |
109
|
|
|
$this->jsonResponseParser |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$this->assertDataItem( |
113
|
|
|
$category, |
114
|
|
|
$instance |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function testGetContentOnDifferentPropertyLabelForMode_PRINT_PROP() { |
119
|
|
|
|
120
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
121
|
|
|
$dataItem = new DINumber( 1001 ); |
122
|
|
|
|
123
|
|
|
$propertyValue = $this->getMockBuilder( '\SMWPropertyValue' ) |
124
|
|
|
->disableOriginalConstructor() |
125
|
|
|
->getMock(); |
126
|
|
|
|
127
|
|
|
$propertyValue->expects( $this->any() ) |
128
|
|
|
->method( 'isValid' ) |
129
|
|
|
->will( $this->returnValue( true ) ); |
130
|
|
|
|
131
|
|
|
$propertyValue->expects( $this->any() ) |
132
|
|
|
->method( 'getDataItem' ) |
133
|
|
|
->will( $this->returnValue( new DIProperty( 'ABC' ) ) ); |
134
|
|
|
|
135
|
|
|
$dataValue = $this->getMockBuilder( '\SMWDataValue' ) |
136
|
|
|
->disableOriginalConstructor() |
137
|
|
|
->setMethods( array( 'getDataItem' ) ) |
138
|
|
|
->getMockForAbstractClass(); |
139
|
|
|
|
140
|
|
|
$dataValue->expects( $this->any() ) |
141
|
|
|
->method( 'getDataItem' ) |
142
|
|
|
->will( $this->returnValue( $dataItem ) ); |
143
|
|
|
|
144
|
|
|
$this->jsonResponseParser->expects( $this->any() ) |
145
|
|
|
->method( 'getPropertyValuesFor' ) |
146
|
|
|
->with( |
147
|
|
|
$this->equalTo( $subject ), |
148
|
|
|
$this->equalTo( new DIProperty( 'isPropertyFromInMemoryExternalRepositoryCache' ) ) ) |
149
|
|
|
->will( $this->returnValue( array( $dataValue ) ) ); |
150
|
|
|
|
151
|
|
|
$this->jsonResponseParser->expects( $this->any() ) |
152
|
|
|
->method( 'findPropertyFromInMemoryExternalRepositoryCache' ) |
153
|
|
|
->with( |
154
|
|
|
$this->equalTo( new DIProperty( 'withDifferentPropertyLabel' ) ) ) |
155
|
|
|
->will( $this->returnValue( new DIProperty( 'isPropertyFromInMemoryExternalRepositoryCache' ) ) ); |
156
|
|
|
|
157
|
|
|
$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) |
158
|
|
|
->disableOriginalConstructor() |
159
|
|
|
->getMock(); |
160
|
|
|
|
161
|
|
|
$printRequest->expects( $this->any() ) |
162
|
|
|
->method( 'getMode' ) |
163
|
|
|
->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_PROP ) ); |
164
|
|
|
|
165
|
|
|
$printRequest->expects( $this->any() ) |
166
|
|
|
->method( 'getData' ) |
167
|
|
|
->will( $this->returnValue( $propertyValue ) ); |
168
|
|
|
|
169
|
|
|
$printRequest->expects( $this->atLeastOnce() ) |
170
|
|
|
->method( 'getLabel' ) |
171
|
|
|
->will( $this->returnValue( 'withDifferentPropertyLabel' ) ); |
172
|
|
|
|
173
|
|
|
$instance = new CannedResultArray( |
174
|
|
|
$subject, |
175
|
|
|
$printRequest, |
176
|
|
|
$this->jsonResponseParser |
177
|
|
|
); |
178
|
|
|
|
179
|
|
|
$this->assertDataItem( |
180
|
|
|
$dataItem, |
181
|
|
|
$instance |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function testGetContentOnQuantityTypeWithSameLabelForMode_PRINT_PROP() { |
186
|
|
|
|
187
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
188
|
|
|
|
189
|
|
|
$property = new DIProperty( 'QuantityType' ); |
190
|
|
|
$property->setPropertyTypeId( '_qty' ); |
|
|
|
|
191
|
|
|
|
192
|
|
|
$dataItem = new DINumber( 1001 ); |
193
|
|
|
|
194
|
|
|
$propertyValue = $this->getMockBuilder( '\SMWPropertyValue' ) |
195
|
|
|
->disableOriginalConstructor() |
196
|
|
|
->getMock(); |
197
|
|
|
|
198
|
|
|
$propertyValue->expects( $this->any() ) |
199
|
|
|
->method( 'isValid' ) |
200
|
|
|
->will( $this->returnValue( true ) ); |
201
|
|
|
|
202
|
|
|
$propertyValue->expects( $this->any() ) |
203
|
|
|
->method( 'getDataItem' ) |
204
|
|
|
->will( $this->returnValue( new DIProperty( 'ABC' ) ) ); |
205
|
|
|
|
206
|
|
|
$dataValue = $this->getMockBuilder( '\SMWDataValue' ) |
207
|
|
|
->disableOriginalConstructor() |
208
|
|
|
->setMethods( array( 'getDataItem' ) ) |
209
|
|
|
->getMockForAbstractClass(); |
210
|
|
|
|
211
|
|
|
$dataValue->expects( $this->any() ) |
212
|
|
|
->method( 'getDataItem' ) |
213
|
|
|
->will( $this->returnValue( $dataItem ) ); |
214
|
|
|
|
215
|
|
|
$this->jsonResponseParser->expects( $this->any() ) |
216
|
|
|
->method( 'getPropertyValuesFor' ) |
217
|
|
|
->with( |
218
|
|
|
$this->equalTo( $subject ), |
219
|
|
|
$this->equalTo( $property ) ) |
220
|
|
|
->will( $this->returnValue( array( $dataValue ) ) ); |
221
|
|
|
|
222
|
|
|
$this->jsonResponseParser->expects( $this->any() ) |
223
|
|
|
->method( 'findPropertyFromInMemoryExternalRepositoryCache' ) |
224
|
|
|
->with( |
225
|
|
|
$this->equalTo( new DIProperty( 'ABC' ) ) ) |
226
|
|
|
->will( $this->returnValue( $property ) ); |
227
|
|
|
|
228
|
|
|
$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) |
229
|
|
|
->disableOriginalConstructor() |
230
|
|
|
->getMock(); |
231
|
|
|
|
232
|
|
|
$printRequest->expects( $this->any() ) |
233
|
|
|
->method( 'getMode' ) |
234
|
|
|
->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_PROP ) ); |
235
|
|
|
|
236
|
|
|
$printRequest->expects( $this->any() ) |
237
|
|
|
->method( 'getData' ) |
238
|
|
|
->will( $this->returnValue( $propertyValue ) ); |
239
|
|
|
|
240
|
|
|
$printRequest->expects( $this->atLeastOnce() ) |
241
|
|
|
->method( 'getLabel' ) |
242
|
|
|
->will( $this->returnValue( '' ) ); |
243
|
|
|
|
244
|
|
|
$instance = new CannedResultArray( |
245
|
|
|
$subject, |
246
|
|
|
$printRequest, |
247
|
|
|
$this->jsonResponseParser |
248
|
|
|
); |
249
|
|
|
|
250
|
|
|
$this->assertDataItem( |
251
|
|
|
$dataItem, |
252
|
|
|
$instance |
253
|
|
|
); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
public function testOptions() { |
257
|
|
|
|
258
|
|
|
$subject = new DIWikiPage( 'Foo', NS_MAIN ); |
259
|
|
|
|
260
|
|
|
$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) |
261
|
|
|
->disableOriginalConstructor() |
262
|
|
|
->getMock(); |
263
|
|
|
|
264
|
|
|
$printRequest->expects( $this->any() ) |
265
|
|
|
->method( 'getMode' ) |
266
|
|
|
->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_THIS ) ); |
267
|
|
|
|
268
|
|
|
$instance = new CannedResultArray( |
269
|
|
|
$subject, |
270
|
|
|
$printRequest, |
271
|
|
|
$this->jsonResponseParser |
272
|
|
|
); |
273
|
|
|
|
274
|
|
|
$dataValue = $instance->getNextDataValue(); |
275
|
|
|
|
276
|
|
|
$this->assertInternalType( |
277
|
|
|
'string', |
278
|
|
|
$dataValue->getOptionValueFor( 'user.language' ) |
|
|
|
|
279
|
|
|
); |
280
|
|
|
|
281
|
|
|
$this->assertInternalType( |
282
|
|
|
'string', |
283
|
|
|
$dataValue->getOptionValueFor( 'content.language' ) |
|
|
|
|
284
|
|
|
); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
private function assertDataItem( $dataItem, $instance ) { |
288
|
|
|
|
289
|
|
|
$this->assertEquals( |
290
|
|
|
$dataItem, |
291
|
|
|
$instance->getNextDataItem() |
292
|
|
|
); |
293
|
|
|
|
294
|
|
|
$instance->reset(); |
295
|
|
|
|
296
|
|
|
$this->assertInstanceOf( |
297
|
|
|
'\SMWDataValue', |
298
|
|
|
$instance->getNextDataValue() |
299
|
|
|
); |
300
|
|
|
|
301
|
|
|
$this->assertEquals( |
302
|
|
|
array( $dataItem ), |
303
|
|
|
$instance->getContent() |
304
|
|
|
); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
} |
308
|
|
|
|
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.