1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\Query\Parser; |
4
|
|
|
|
5
|
|
|
use SMW\DataItemFactory; |
6
|
|
|
use SMW\Query\DescriptionFactory; |
7
|
|
|
use SMW\Tests\TestEnvironment; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers SMW\Query\DescriptionFactory |
11
|
|
|
* @group semantic-mediawiki |
12
|
|
|
* |
13
|
|
|
* @license GNU GPL v2+ |
14
|
|
|
* @since 2.4 |
15
|
|
|
* |
16
|
|
|
* @author mwjames |
17
|
|
|
*/ |
18
|
|
|
class DescriptionFactoryTest extends \PHPUnit_Framework_TestCase { |
19
|
|
|
|
20
|
|
|
private $testEnvironment; |
21
|
|
|
private $dataItemFactory; |
22
|
|
|
|
23
|
|
|
protected function setUp() { |
24
|
|
|
$this->testEnvironment = new TestEnvironment(); |
25
|
|
|
$this->dataItemFactory = new DataItemFactory(); |
26
|
|
|
|
27
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
28
|
|
|
->disableOriginalConstructor() |
29
|
|
|
->getMockForAbstractClass(); |
30
|
|
|
|
31
|
|
|
$this->testEnvironment->registerObject( 'Store', $store ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function tearDown() { |
35
|
|
|
$this->testEnvironment->tearDown(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testCanConstruct() { |
39
|
|
|
|
40
|
|
|
$this->assertInstanceOf( |
41
|
|
|
'SMW\Query\DescriptionFactory', |
42
|
|
|
new DescriptionFactory() |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testCanConstructValueDescription() { |
47
|
|
|
|
48
|
|
|
$dataItem = $this->getMockBuilder( '\SMWDataItem' ) |
49
|
|
|
->disableOriginalConstructor() |
50
|
|
|
->getMock(); |
51
|
|
|
|
52
|
|
|
$instance = new DescriptionFactory(); |
53
|
|
|
|
54
|
|
|
$this->assertInstanceOf( |
55
|
|
|
'SMW\Query\Language\ValueDescription', |
56
|
|
|
$instance->newValueDescription( $dataItem ) |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testCanConstructSomeProperty() { |
61
|
|
|
|
62
|
|
|
$property = $this->getMockBuilder( '\SMW\DIProperty' ) |
63
|
|
|
->disableOriginalConstructor() |
64
|
|
|
->getMock(); |
65
|
|
|
|
66
|
|
|
$description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) |
67
|
|
|
->disableOriginalConstructor() |
68
|
|
|
->getMockForAbstractClass(); |
69
|
|
|
|
70
|
|
|
$instance = new DescriptionFactory(); |
71
|
|
|
|
72
|
|
|
$this->assertInstanceOf( |
73
|
|
|
'SMW\Query\Language\SomeProperty', |
74
|
|
|
$instance->newSomeProperty( $property, $description ) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testCanConstructThingDescription() { |
79
|
|
|
|
80
|
|
|
$instance = new DescriptionFactory(); |
81
|
|
|
|
82
|
|
|
$this->assertInstanceOf( |
83
|
|
|
'SMW\Query\Language\ThingDescription', |
84
|
|
|
$instance->newThingDescription() |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testCanConstructDisjunction() { |
89
|
|
|
|
90
|
|
|
$descriptions = array(); |
91
|
|
|
|
92
|
|
|
$description = $this->getMockBuilder( '\SMW\Query\Language\SomeProperty' ) |
93
|
|
|
->disableOriginalConstructor() |
94
|
|
|
->getMock(); |
95
|
|
|
|
96
|
|
|
$description->expects( $this->once() ) |
97
|
|
|
->method( 'getPrintRequests' ) |
98
|
|
|
->will( $this->returnValue( array() ) ); |
99
|
|
|
|
100
|
|
|
$descriptions[] = $description; |
101
|
|
|
|
102
|
|
|
$description = $this->getMockBuilder( '\SMW\Query\Language\ValueDescription' ) |
103
|
|
|
->disableOriginalConstructor() |
104
|
|
|
->getMock(); |
105
|
|
|
|
106
|
|
|
$description->expects( $this->once() ) |
107
|
|
|
->method( 'getPrintRequests' ) |
108
|
|
|
->will( $this->returnValue( array() ) ); |
109
|
|
|
|
110
|
|
|
$descriptions[] = $description; |
111
|
|
|
|
112
|
|
|
$instance = new DescriptionFactory(); |
113
|
|
|
|
114
|
|
|
$this->assertInstanceOf( |
115
|
|
|
'SMW\Query\Language\Disjunction', |
116
|
|
|
$instance->newDisjunction( $descriptions ) |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testCanConstructConjunction() { |
121
|
|
|
|
122
|
|
|
$descriptions = array(); |
123
|
|
|
|
124
|
|
|
$description = $this->getMockBuilder( '\SMW\Query\Language\SomeProperty' ) |
125
|
|
|
->disableOriginalConstructor() |
126
|
|
|
->getMock(); |
127
|
|
|
|
128
|
|
|
$descriptions[] = $description; |
129
|
|
|
|
130
|
|
|
$description = $this->getMockBuilder( '\SMW\Query\Language\ValueDescription' ) |
131
|
|
|
->disableOriginalConstructor() |
132
|
|
|
->getMock(); |
133
|
|
|
|
134
|
|
|
$descriptions[] = $description; |
135
|
|
|
|
136
|
|
|
$instance = new DescriptionFactory(); |
137
|
|
|
|
138
|
|
|
$this->assertInstanceOf( |
139
|
|
|
'SMW\Query\Language\Conjunction', |
140
|
|
|
$instance->newConjunction( $descriptions ) |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testCanConstructNamespaceDescription() { |
145
|
|
|
|
146
|
|
|
$instance = new DescriptionFactory(); |
147
|
|
|
|
148
|
|
|
$this->assertInstanceOf( |
149
|
|
|
'SMW\Query\Language\NamespaceDescription', |
150
|
|
|
$instance->newNamespaceDescription( SMW_NS_PROPERTY ) |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testCanConstructClassDescription() { |
155
|
|
|
|
156
|
|
|
$category = $this->getMockBuilder( '\SMW\DIWikiPage' ) |
157
|
|
|
->disableOriginalConstructor() |
158
|
|
|
->getMock(); |
159
|
|
|
|
160
|
|
|
$instance = new DescriptionFactory(); |
161
|
|
|
|
162
|
|
|
$this->assertInstanceOf( |
163
|
|
|
'SMW\Query\Language\ClassDescription', |
164
|
|
|
$instance->newClassDescription( $category ) |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function testCanConstructConceptDescription() { |
169
|
|
|
|
170
|
|
|
$concept = $this->getMockBuilder( '\SMW\DIWikiPage' ) |
171
|
|
|
->disableOriginalConstructor() |
172
|
|
|
->getMock(); |
173
|
|
|
|
174
|
|
|
$instance = new DescriptionFactory(); |
175
|
|
|
|
176
|
|
|
$this->assertInstanceOf( |
177
|
|
|
'SMW\Query\Language\ConceptDescription', |
178
|
|
|
$instance->newConceptDescription( $concept ) |
179
|
|
|
); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function testCanConstructDescriptionFromInvalidDataValue() { |
183
|
|
|
|
184
|
|
|
$dataValue = $this->getMockBuilder( '\SMWDataValue' ) |
185
|
|
|
->disableOriginalConstructor() |
186
|
|
|
->setMethods( array( 'isValid' ) ) |
187
|
|
|
->getMockForAbstractClass(); |
188
|
|
|
|
189
|
|
|
$dataValue->expects( $this->atLeastOnce() ) |
190
|
|
|
->method( 'isValid' ) |
191
|
|
|
->will( $this->returnValue( false ) ); |
192
|
|
|
|
193
|
|
|
$instance = new DescriptionFactory(); |
194
|
|
|
|
195
|
|
|
$this->assertInstanceOf( |
196
|
|
|
'SMW\Query\Language\ThingDescription', |
197
|
|
|
$instance->newFromDataValue( $dataValue ) |
198
|
|
|
); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function testCanConstructDescriptionFromValidDataValue() { |
202
|
|
|
|
203
|
|
|
$dataValue = $this->getMockBuilder( '\SMWDataValue' ) |
204
|
|
|
->disableOriginalConstructor() |
205
|
|
|
->setMethods( array( 'isValid', 'getProperty', 'getDataItem' ) ) |
206
|
|
|
->getMockForAbstractClass(); |
207
|
|
|
|
208
|
|
|
$dataValue->expects( $this->atLeastOnce() ) |
209
|
|
|
->method( 'isValid' ) |
210
|
|
|
->will( $this->returnValue( true ) ); |
211
|
|
|
|
212
|
|
|
$dataValue->expects( $this->atLeastOnce() ) |
213
|
|
|
->method( 'getProperty' ) |
214
|
|
|
->will( $this->returnValue( $this->dataItemFactory->newDIProperty( 'Foo' ) ) ); |
215
|
|
|
|
216
|
|
|
$dataValue->expects( $this->atLeastOnce() ) |
217
|
|
|
->method( 'getDataItem' ) |
218
|
|
|
->will( $this->returnValue( $this->dataItemFactory->newDIBlob( 'Bar' ) ) ); |
219
|
|
|
|
220
|
|
|
$instance = new DescriptionFactory(); |
221
|
|
|
|
222
|
|
|
$this->assertInstanceOf( |
223
|
|
|
'SMW\Query\Language\SomeProperty', |
224
|
|
|
$instance->newFromDataValue( $dataValue ) |
225
|
|
|
); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function testCanConstructDescriptionFromMonolingualTextValue() { |
229
|
|
|
|
230
|
|
|
$containerSemanticData = $this->getMockBuilder( '\SMWContainerSemanticData' ) |
231
|
|
|
->disableOriginalConstructor() |
232
|
|
|
->getMock(); |
233
|
|
|
|
234
|
|
|
$containerSemanticData->expects( $this->atLeastOnce() ) |
235
|
|
|
->method( 'getPropertyValues' ) |
236
|
|
|
->will( $this->returnValue( array( $this->dataItemFactory->newDIBlob( 'Bar' ) ) ) ); |
237
|
|
|
|
238
|
|
|
$dataValue = $this->getMockBuilder( '\SMW\DataValues\MonolingualTextValue' ) |
239
|
|
|
->disableOriginalConstructor() |
240
|
|
|
->setMethods( array( 'isValid', 'getProperty', 'getDataItem' ) ) |
241
|
|
|
->getMock(); |
242
|
|
|
|
243
|
|
|
$dataValue->expects( $this->atLeastOnce() ) |
244
|
|
|
->method( 'isValid' ) |
245
|
|
|
->will( $this->returnValue( true ) ); |
246
|
|
|
|
247
|
|
|
$dataValue->expects( $this->atLeastOnce() ) |
248
|
|
|
->method( 'getDataItem' ) |
249
|
|
|
->will( $this->returnValue( $this->dataItemFactory->newDIContainer( $containerSemanticData ) ) ); |
250
|
|
|
|
251
|
|
|
$instance = new DescriptionFactory(); |
252
|
|
|
|
253
|
|
|
$this->assertInstanceOf( |
254
|
|
|
'SMW\Query\Language\Conjunction', |
255
|
|
|
$instance->newFromDataValue( $dataValue ) |
256
|
|
|
); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
} |
260
|
|
|
|