1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* To change this license header, choose License Headers in Project Properties. |
5
|
|
|
* To change this template file, choose Tools | Templates |
6
|
|
|
* and open the template in the editor. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace SFS\Tests; |
10
|
|
|
|
11
|
|
|
use SFS\SelectField; |
|
|
|
|
12
|
|
|
|
13
|
|
|
use Parser; |
14
|
|
|
use ParserOptions; |
15
|
|
|
use ParserOutput; |
16
|
|
|
use Title; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @covers \SFS\SelectField |
20
|
|
|
* @group semantic-forms-select |
21
|
|
|
* @author FelixAba |
22
|
|
|
*/ |
23
|
|
|
class SelectFieldTest extends \PHPUnit_Framework_TestCase { |
24
|
|
|
private $SelectField; |
25
|
|
|
private $parser; |
26
|
|
|
// Defined variables |
27
|
|
|
private $other_args_query_parametrized = [ 'query' => '((Category:Building Complex))((Part Of Site::@@@@));?Display Title;format~list;sort~Display Title;sep~,;link~none;headers~hide;limit~500' ]; |
28
|
|
|
private $expected_result_parametrized_setQuery = "[[Category:Building Complex]][[Part Of Site::@@@@]];?Display Title;format=list;sort=Display Title;sep=,;link=none;headers=hide;limit=500"; |
29
|
|
|
private $other_args_query_unparametrized = [ 'query' => '((Category:Building Complex));?Display Title;format~list;sort~Display Title;sep~,;link~none;headers~hide;limit~500' ]; |
30
|
|
|
private $other_args_function_parametrized = [ 'function' => '((Category:Building Complex))((Part Of Site::@@@@));?Display Title;format~list;sort~Display Title;sep~,;link~none;headers~hide;limit~500' ]; |
31
|
|
|
private $expected_result_parametrized_seFunction = '{{#[[Category:Building Complex]][[Part Of Site::@@@@]];?Display Title;format=list;sort=Display Title;sep=,;link=none;headers=hide;limit=500}}'; |
32
|
|
|
private $other_args_function_unparametrized = [ 'function' => 'ask:((Category:Building Complex));?Display Title;format~list;sort~Display Title;sep~@@;link~none;headers~hide;limit~500' ]; |
33
|
|
|
private $expected_result_unparametrized_seFunction = "Building Complex:86543eab-4112-4616-be50-17dcdc24c346 (OFD.AEXH)@@Building Complex:5b9e26f8-6c57-48ff-a6b8-42a4e50fe472 (OFD.AEXH)@@Building Complex:93b076aa-cbe9-4371-8b61-c17c26f1872f (OFD.AMEXH)@@Building Complex:59577450-1582-4d6e-9621-3ac0531a728e (OFD.EEXH)@@Building Complex:1a9bed0b-67de-4e71-8528-f2b6a8907814 (RContiAve.Sport Complex)@@Building Complex:6a2242ea-7536-4a6d-85d2-f2ba4398ef44 (TB.BC)@@Building Complex:2db51fb1-10b6-4d4c-a152-f512914781ff (TB.BD)"; |
|
|
|
|
34
|
|
|
|
35
|
|
|
public function testCanConstruct() { |
36
|
|
|
|
37
|
|
|
$this->assertInstanceOf( '\SFS\SelectField', $this->SelectField ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testProcessParameters_Query() { |
41
|
|
|
|
42
|
|
|
$this->SelectField->processParameters( |
43
|
|
|
"", $this->other_args_query_parametrized |
44
|
|
|
); |
45
|
|
|
$this->assertTrue( |
46
|
|
|
array_key_exists( "query", $this->other_args_query_parametrized ) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testProcessParameters_Function() { |
51
|
|
|
|
52
|
|
|
$this->SelectField->processParameters( |
53
|
|
|
"", $this->other_args_function_parametrized |
54
|
|
|
); |
55
|
|
|
$this->assertArrayHasKey( |
56
|
|
|
"function", $this->other_args_function_parametrized |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testParametrized_setQuery() { |
61
|
|
|
|
62
|
|
|
$this->SelectField->setQuery( $this->other_args_query_parametrized ); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( |
65
|
|
|
$this->expected_result_parametrized_setQuery, |
66
|
|
|
$this->SelectField->getData()['selectquery'] |
67
|
|
|
); |
68
|
|
|
/* |
69
|
|
|
* Optional Test. |
70
|
|
|
*/ |
71
|
|
|
preg_match_all( |
72
|
|
|
"/[~(\(\()(\)\))]+/", $this->SelectField->getData()['selectquery'], |
73
|
|
|
$was_remove |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
preg_match_all( |
77
|
|
|
"/[=(\[\[)(\]\])]+/", $this->SelectField->getData()['selectquery'], |
78
|
|
|
$was_replaced |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$this->assertTrue( count( $was_remove[0] ) == 0 ); |
82
|
|
|
$this->assertTrue( count( $was_replaced[0] ) > 0 ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testUnparametrized_setQuery() { |
86
|
|
|
|
87
|
|
|
$this->SelectField->setQuery( $this->other_args_query_unparametrized ); |
88
|
|
|
|
89
|
|
|
$this->assertTrue( $this->SelectField->getValues() !== null ); |
90
|
|
|
$this->assertTrue( $this->SelectField->hasStaticValues() ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testParametrized_setFunction() { |
94
|
|
|
|
95
|
|
|
$this->SelectField->setFunction( |
96
|
|
|
$this->other_args_function_parametrized |
97
|
|
|
); |
98
|
|
|
$this->assertTrue( |
99
|
|
|
strcmp( |
100
|
|
|
$this->expected_result_parametrized_seFunction, |
101
|
|
|
$this->SelectField->getData()['selectfunction'] |
102
|
|
|
) == 0 |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function testUnparametrized_setFunction() { |
107
|
|
|
|
108
|
|
|
$this->SelectField->setFunction( |
109
|
|
|
$this->other_args_function_unparametrized |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$this->assertTrue( $this->SelectField->hasStaticValues() ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testSetSelectIsMultiple_keyExistTrue() { |
116
|
|
|
$other_args = [ "part_of_multiple" => "bla bla bla" ]; |
117
|
|
|
$this->SelectField->setSelectIsMultiple( $other_args ); |
118
|
|
|
$this->assertTrue( $this->SelectField->getData()["selectismultiple"] ); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testSetSelectIsMultiple_keyExistFalse() { |
122
|
|
|
|
123
|
|
|
$other_args = [ "Not_part_of_multiple" => "blas blas blas" ]; |
124
|
|
|
$this->SelectField->setSelectIsMultiple( $other_args ); |
125
|
|
|
$this->assertFalse( $this->SelectField->getData()["selectismultiple"] ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function testSetSelectTemplate_correctData() { |
129
|
|
|
$input_name = "{{#[[Category:Building Complex]][[Part Of Site::@@@@]]"; |
130
|
|
|
$result = "{{#"; |
131
|
|
|
$this->SelectField->setSelectTemplate( $input_name ); |
132
|
|
|
|
133
|
|
|
$this->assertEquals( |
134
|
|
|
$this->SelectField->getData()['selecttemplate'], $result |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function testSetSelectTemplate_wrongData() { |
139
|
|
|
$input_name = "Category:Building Complex"; |
140
|
|
|
$result = ""; |
141
|
|
|
$this->SelectField->setSelectTemplate( $input_name ); |
142
|
|
|
|
143
|
|
|
$this->assertEquals( |
144
|
|
|
$this->SelectField->getData()['selecttemplate'], $result |
145
|
|
|
); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function testSetSelectField_correctData() { |
149
|
|
|
$input_name = "{{#[[Category:Building Complex]][[Part Of Site::@@@@]]"; |
150
|
|
|
$result = "Part Of Site::@@@@]"; |
151
|
|
|
|
152
|
|
|
$this->SelectField->setSelectField( $input_name ); |
153
|
|
|
|
154
|
|
|
$this->assertEquals( |
155
|
|
|
$this->SelectField->getData()['selectfield'], $result |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testSetSelectField_wrongData() { |
160
|
|
|
$input_name = "Category:Building Complex"; |
161
|
|
|
$result = ""; |
162
|
|
|
$this->SelectField->setSelectField( $input_name ); |
163
|
|
|
|
164
|
|
|
$this->assertNotEquals( |
165
|
|
|
$this->SelectField->getData()['selectfield'], $result |
166
|
|
|
); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function testSetValueTemplate_containsMselectTemplate() { |
170
|
|
|
$input_name = "{{#[[Category:Building Complex]][[Part Of Site::@@@@]]"; |
171
|
|
|
$other_args = [ "sametemplate" => "test values" ]; |
172
|
|
|
$result = "{{#"; |
173
|
|
|
$this->SelectField->setSelectTemplate( $input_name ); |
174
|
|
|
$this->SelectField->setValueTemplate( $other_args ); |
175
|
|
|
|
176
|
|
|
$this->assertEquals( |
177
|
|
|
$this->SelectField->getData()["valuetemplate"], $result |
178
|
|
|
); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function testSetValueTemplate_containsOtherArgsTemplate() { |
182
|
|
|
|
183
|
|
|
$other_args = [ "template" => "test values" ]; |
184
|
|
|
|
185
|
|
|
$this->SelectField->setValueTemplate( $other_args ); |
186
|
|
|
|
187
|
|
|
$this->assertEquals( |
188
|
|
|
$this->SelectField->getData()["valuetemplate"], |
189
|
|
|
$other_args["template"] |
190
|
|
|
); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function testSetValueField() { |
194
|
|
|
$other_args = [ "field" => "test values Field" ]; |
195
|
|
|
|
196
|
|
|
$this->SelectField->setValueField( $other_args ); |
197
|
|
|
|
198
|
|
|
$this->assertEquals( |
199
|
|
|
$this->SelectField->getData()["valuefield"], $other_args["field"] |
200
|
|
|
); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function testSetSelectRemove_keyExistTrue() { |
204
|
|
|
$other_args = [ 'rmdiv' => "Test data" ]; |
205
|
|
|
$this->SelectField->setSelectRemove( $other_args ); |
206
|
|
|
$this->assertTrue( $this->SelectField->getData()["selectrm"] ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function testSetSelectRemove_keyExistFalse() { |
210
|
|
|
|
211
|
|
|
$other_args = [ "no_rmdiv" => "test data" ]; |
212
|
|
|
$this->SelectField->setSelectRemove( $other_args ); |
213
|
|
|
$this->assertFalse( $this->SelectField->getData()["selectrm"] ); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function testSetLabel_keyExistTrue() { |
217
|
|
|
$other_args = [ 'label' => "Test data" ]; |
218
|
|
|
$this->SelectField->setLabel( $other_args ); |
219
|
|
|
$this->assertTrue( $this->SelectField->getData()["label"] ); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
public function testSetLabel_keyExistFalse() { |
223
|
|
|
|
224
|
|
|
$other_args = [ "no_label" => "test data" ]; |
225
|
|
|
$this->SelectField->setLabel( $other_args ); |
226
|
|
|
$this->assertArrayHasKey( "label", $this->SelectField->getData() ); |
227
|
|
|
$this->assertFalse( $this->SelectField->getData()["label"] ); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
public function testSetDelimiter_keyExistTrue() { |
231
|
|
|
$other_args = [ "delimiter" => ":" ]; |
232
|
|
|
$this->SelectField->setDelimiter( $other_args ); |
233
|
|
|
$this->assertEquals( |
234
|
|
|
$this->SelectField->getDelimiter(), $other_args["delimiter"] |
235
|
|
|
); |
236
|
|
|
$this->assertEquals( |
237
|
|
|
$this->SelectField->getData()["sep"], $other_args["delimiter"] |
238
|
|
|
); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
public function testSetWgPageFormsListSeparator_keyExistTrue() { |
242
|
|
|
|
243
|
|
|
$g_args = [ "Global_delimiter" => ";" ]; |
244
|
|
|
$this->SelectField->setDelimiter( $g_args ); |
245
|
|
|
$this->assertEquals( |
246
|
|
|
$this->SelectField->getDelimiter(), $g_args["Global_delimiter"] |
247
|
|
|
); |
248
|
|
|
$this->assertEquals( |
249
|
|
|
$this->SelectField->getData()["sep"], $g_args["Global_delimiter"] |
250
|
|
|
); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
protected function setUp() { |
|
|
|
|
254
|
|
|
parent::setUp(); |
255
|
|
|
$this->parser = $GLOBALS['wgParser']; |
256
|
|
|
$this->parser->setTitle( Title::newFromText( 'NO TITLE' ) ); |
257
|
|
|
$this->parser->mOptions = new ParserOptions(); |
258
|
|
|
$this->parser->mOutput = new ParserOutput( |
259
|
|
|
); // Stored result thats passed back to Parser Object |
260
|
|
|
$this->parser->clearState(); |
261
|
|
|
$this->SelectField = new SelectField( $this->parser ); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
protected function tearDown() { |
265
|
|
|
unset( $this->SelectField ); |
266
|
|
|
parent::tearDown(); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
} |
271
|
|
|
|