1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests; |
4
|
|
|
|
5
|
|
|
use SMW\FileReader; |
6
|
|
|
|
7
|
|
|
use RuntimeException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @license GNU GPL v2+ |
11
|
|
|
* @since 2.2 |
12
|
|
|
* |
13
|
|
|
* @author mwjames |
14
|
|
|
*/ |
15
|
|
|
class JsonTestCaseFileHandler { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var FileReader |
19
|
|
|
*/ |
20
|
|
|
private $fileReader; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $reasonToSkip = ''; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @since 2.2 |
29
|
|
|
* |
30
|
|
|
* @param FileReader $fileReader |
31
|
|
|
*/ |
32
|
|
|
public function __construct( FileReader $fileReader ) { |
33
|
|
|
$this->fileReader = $fileReader; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @since 2.2 |
38
|
|
|
* |
39
|
|
|
* @return boolean |
40
|
|
|
*/ |
41
|
|
|
public function isIncomplete() { |
42
|
|
|
|
43
|
|
|
$meta = $this->getFileContentsFor( 'meta' ); |
44
|
|
|
$isIncomplete = isset( $meta['is-incomplete'] ) ? (bool)$meta['is-incomplete'] : false; |
45
|
|
|
|
46
|
|
|
if ( $isIncomplete ) { |
47
|
|
|
$this->reasonToSkip = '"'. $this->getFileContentsFor( 'description' ) . '" has been marked as incomplete.'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $isIncomplete; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @since 2.2 |
55
|
|
|
* |
56
|
|
|
* @return boolean |
57
|
|
|
*/ |
58
|
|
|
public function getDebugMode() { |
59
|
|
|
|
60
|
|
|
$meta = $this->getFileContentsFor( 'meta' ); |
61
|
|
|
|
62
|
|
|
return isset( $meta['debug'] ) ? (bool)$meta['debug'] : false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @since 2.4 |
67
|
|
|
* |
68
|
|
|
* @param array $case |
69
|
|
|
* @param string $identifier |
70
|
|
|
* |
71
|
|
|
* @return boolean |
72
|
|
|
*/ |
73
|
|
|
public function requiredToSkipFor( array $case, $identifier ) { |
74
|
|
|
|
75
|
|
|
$skipOn = isset( $case['skip-on'] ) ? $case['skip-on'] : array(); |
76
|
|
|
$identifier = strtolower( $identifier ); |
77
|
|
|
|
78
|
|
|
if ( in_array( $identifier, array_keys( $skipOn ) ) ) { |
79
|
|
|
return true; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @since 2.2 |
87
|
|
|
* |
88
|
|
|
* @return boolean |
89
|
|
|
*/ |
90
|
|
|
public function requiredToSkipForConnector( $connectorId ) { |
91
|
|
|
|
92
|
|
|
$connectorId = strtolower( $connectorId ); |
93
|
|
|
$meta = $this->getFileContentsFor( 'meta' ); |
94
|
|
|
|
95
|
|
|
$skipOn = isset( $meta['skip-on'] ) ? $meta['skip-on'] : array(); |
96
|
|
|
|
97
|
|
|
if ( in_array( $connectorId, array_keys( $skipOn ) ) ) { |
98
|
|
|
$this->reasonToSkip = $skipOn[$connectorId]; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $this->reasonToSkip !== ''; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @since 2.2 |
106
|
|
|
* |
107
|
|
|
* @return boolean |
108
|
|
|
*/ |
109
|
|
|
public function requiredToSkipForJsonVersion( $version ) { |
110
|
|
|
|
111
|
|
|
$meta = $this->getFileContentsFor( 'meta' ); |
112
|
|
|
|
113
|
|
|
if ( version_compare( $version, $meta['version'], 'lt' ) ) { |
114
|
|
|
$this->reasonToSkip = $meta['version'] . ' as file version is not supported'; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $this->reasonToSkip !== ''; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @since 2.2 |
122
|
|
|
* |
123
|
|
|
* @return boolean |
124
|
|
|
*/ |
125
|
|
|
public function requiredToSkipForMwVersion( $mwVersion ) { |
126
|
|
|
|
127
|
|
|
$meta = $this->getFileContentsFor( 'meta' ); |
128
|
|
|
$skipOn = isset( $meta['skip-on'] ) ? $meta['skip-on'] : array(); |
129
|
|
|
|
130
|
|
|
foreach ( $skipOn as $id => $reason ) { |
131
|
|
|
|
132
|
|
|
if ( strpos( $id, 'mw-' ) === false ) { |
133
|
|
|
continue; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
list( $mw, $versionToSkip ) = explode( "mw-", $id, 2 ); |
|
|
|
|
137
|
|
|
|
138
|
|
|
if ( version_compare( $mwVersion, $versionToSkip, '=' ) ) { |
139
|
|
|
$this->reasonToSkip = "MediaWiki " . $mwVersion . " version is not supported ({$reason})"; |
140
|
|
|
break; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $this->reasonToSkip !== ''; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @since 2.2 |
149
|
|
|
* |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function getReasonForSkip() { |
153
|
|
|
return $this->reasonToSkip; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @since 2.2 |
158
|
|
|
* |
159
|
|
|
* @return array|integer|string|boolean |
160
|
|
|
* @throws RuntimeException |
161
|
|
|
*/ |
162
|
|
|
public function getSettingsFor( $key ) { |
|
|
|
|
163
|
|
|
|
164
|
|
|
$settings = $this->getFileContentsFor( 'settings' ); |
165
|
|
|
|
166
|
|
|
if ( ( $key === 'wgContLang' || $key === 'wgLang' ) && isset( $settings[$key] ) ) { |
167
|
|
|
\RequestContext::getMain()->setLanguage( $settings[$key] ); |
168
|
|
|
return \Language::factory( $settings[$key] ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
// Needs special attention due to NS constant usage |
172
|
|
|
if ( $key === 'smwgNamespacesWithSemanticLinks' && isset( $settings[$key] ) ) { |
173
|
|
|
$smwgNamespacesWithSemanticLinks = array(); |
174
|
|
|
|
175
|
|
|
foreach ( $settings[$key] as $ns => $value ) { |
176
|
|
|
$smwgNamespacesWithSemanticLinks[constant( $ns )] = (bool)$value; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
return $smwgNamespacesWithSemanticLinks; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
// Needs special attention due to constant usage |
183
|
|
|
if ( $key === 'smwgQConceptCaching' && isset( $settings[$key] ) ) { |
184
|
|
|
return constant( $settings[$key] ); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
if ( isset( $settings[$key] ) ) { |
188
|
|
|
return $settings[$key]; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
// Set default values |
192
|
|
|
if ( isset( $GLOBALS[$key] ) ) { |
193
|
|
|
return $GLOBALS[$key]; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
throw new RuntimeException( "{$key} is unknown" ); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @since 2.2 |
201
|
|
|
* |
202
|
|
|
* @return array |
203
|
|
|
*/ |
204
|
|
|
public function getListOfProperties() { |
205
|
|
|
return $this->getFileContentsFor( 'properties' ); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @since 2.2 |
210
|
|
|
* |
211
|
|
|
* @return array |
212
|
|
|
*/ |
213
|
|
|
public function getListOfSubjects() { |
214
|
|
|
return $this->getFileContentsFor( 'subjects' ); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @since 2.4 |
219
|
|
|
* |
220
|
|
|
* @param string $key |
221
|
|
|
* |
222
|
|
|
* @return array |
223
|
|
|
*/ |
224
|
|
|
public function getContentsFor( $key ) { |
225
|
|
|
|
226
|
|
|
try{ |
227
|
|
|
$contents = $this->getFileContentsFor( $key ); |
228
|
|
|
} catch( \Exception $e ) { |
229
|
|
|
$contents = array(); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
return $contents; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @since 2.2 |
237
|
|
|
* |
238
|
|
|
* @param string $key |
239
|
|
|
* |
240
|
|
|
* @return array |
241
|
|
|
*/ |
242
|
|
|
public function findTestCasesFor( $key ) { |
243
|
|
|
return $this->getContentsFor( $key ); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
private function getFileContentsFor( $index ) { |
247
|
|
|
|
248
|
|
|
$contents = $this->fileReader->read(); |
249
|
|
|
|
250
|
|
|
if ( isset( $contents[$index] ) ) { |
251
|
|
|
return $contents[$index]; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
throw new RuntimeException( "{$index} is unknown" ); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
} |
258
|
|
|
|
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.