29
29
* ---------------------------------------------------------------------
30
30
*/
31
31
namespace GlpiPlugin \Formcreator \Field \tests \units ;
32
+
32
33
use GlpiPlugin \Formcreator \Tests \CommonTestCase ;
34
+ use Computer ;
35
+ use ITILCategory ;
33
36
use Location ;
34
37
class DropdownField extends CommonTestCase {
35
38
public function beforeTestMethod ($ method ) {
@@ -52,14 +55,14 @@ public function providerPrepareQuestionInputForSave() {
52
55
[
53
56
'input ' => [
54
57
'name ' => $ name ,
55
- 'itemtype ' => \ Location::class,
58
+ 'itemtype ' => Location::class,
56
59
'show_tree_depth ' => '5 ' ,
57
60
'show_tree_root ' => '0 ' ,
58
61
'selectable_tree_root ' => '0 ' ,
59
62
],
60
63
'expected ' => [
61
64
'name ' => $ name ,
62
- 'itemtype ' => \ Location::class,
65
+ 'itemtype ' => Location::class,
63
66
'values ' => json_encode ([
64
67
'show_tree_depth ' => '5 ' ,
65
68
'show_tree_root ' => '0 ' ,
@@ -71,7 +74,7 @@ public function providerPrepareQuestionInputForSave() {
71
74
[
72
75
'input ' => [
73
76
'name ' => $ name ,
74
- 'itemtype ' => \ ITILCategory::class,
77
+ 'itemtype ' => ITILCategory::class,
75
78
'show_ticket_categories ' => '2 ' ,
76
79
'show_tree_depth ' => '3 ' ,
77
80
'default_values ' => '' ,
@@ -112,7 +115,7 @@ public function testisPublicFormCompatible() {
112
115
113
116
public function testIsPrerequisites () {
114
117
$ instance = $ this ->newTestedInstance ($ this ->getQuestion ([
115
- 'itemtype ' => \ Computer::class
118
+ 'itemtype ' => Computer::class
116
119
]));
117
120
$ output = $ instance ->isPrerequisites ();
118
121
$ this ->boolean ($ output )->isEqualTo (true );
@@ -133,12 +136,13 @@ public function testGetValueForDesign() {
133
136
}
134
137
135
138
public function testGetDocumentsForTarget () {
136
- $ instance = $ this ->newTestedInstance (new \PluginFormcreatorQuestion ());
139
+ $ question = $ this ->getQuestion ();
140
+ $ instance = $ question ->getSubField ();
137
141
$ this ->array ($ instance ->getDocumentsForTarget ())->hasSize (0 );
138
142
}
139
143
140
144
public function providerIsValid () {
141
- $ location = new \ Location ();
145
+ $ location = new Location ();
142
146
$ locationId = $ location ->import ([
143
147
'completename ' => 'foo ' ,
144
148
'entities_id ' => $ _SESSION ['glpiactive_entity ' ]
@@ -148,13 +152,13 @@ public function providerIsValid() {
148
152
[
149
153
'question ' => $ this ->getQuestion ([
150
154
'name ' => 'fieldname ' ,
151
- 'itemtype ' => \ Location::class,
155
+ 'itemtype ' => Location::class,
152
156
'values ' => '' ,
153
157
'required ' => '0 ' ,
154
158
'default_values ' => '0 ' ,
155
159
]),
156
160
'input ' => [
157
- 'dropdown_values ' => \ Location::class,
161
+ 'dropdown_values ' => Location::class,
158
162
'dropdown_default_value ' => '0 ' ,
159
163
'show_tree_depth ' => '5 ' ,
160
164
'show_tree_root ' => '0 ' ,
@@ -164,12 +168,12 @@ public function providerIsValid() {
164
168
[
165
169
'question ' => $ this ->getQuestion ([
166
170
'name ' => 'fieldname ' ,
167
- 'itemtype ' => \ Location::class,
171
+ 'itemtype ' => Location::class,
168
172
'values ' => '' ,
169
173
'required ' => '1 ' ,
170
174
]),
171
175
'input ' => [
172
- 'dropdown_values ' => \ Location::class,
176
+ 'dropdown_values ' => Location::class,
173
177
'dropdown_default_value ' => '0 ' ,
174
178
'show_tree_depth ' => '5 ' ,
175
179
'show_tree_root ' => '0 ' ,
@@ -179,13 +183,13 @@ public function providerIsValid() {
179
183
[
180
184
'question ' => $ this ->getQuestion ([
181
185
'name ' => 'fieldname ' ,
182
- 'itemtype ' => \ Location::class,
186
+ 'itemtype ' => Location::class,
183
187
'values ' => '' ,
184
188
'required ' => '1 ' ,
185
189
'default_values ' => '' ,
186
190
]),
187
191
'input ' => [
188
- 'dropdown_values ' => \ Location::class,
192
+ 'dropdown_values ' => Location::class,
189
193
'dropdown_default_value ' => '42 ' ,
190
194
'show_tree_depth ' => '5 ' ,
191
195
'show_tree_root ' => '0 ' ,
@@ -195,13 +199,13 @@ public function providerIsValid() {
195
199
[
196
200
'question ' => $ this ->getQuestion ([
197
201
'name ' => 'fieldname ' ,
198
- 'itemtype ' => \ Location::class,
202
+ 'itemtype ' => Location::class,
199
203
'values ' => '' ,
200
204
'required ' => '1 ' ,
201
205
'default_values ' => $ locationId ,
202
206
]),
203
207
'input ' => [
204
- 'dropdown_values ' => \ Location::class,
208
+ 'dropdown_values ' => Location::class,
205
209
'dropdown_default_value ' => '42 ' ,
206
210
'show_tree_depth ' => '5 ' ,
207
211
'show_tree_root ' => '0 ' ,
@@ -222,18 +226,18 @@ public function testIsValid($question, $input, $expectedValidity) {
222
226
}
223
227
224
228
public function providerGetValueForTargetText () {
225
- $ location = new \ Location ();
229
+ $ location = new Location ();
226
230
$ location ->add ([
227
231
'name ' => $ this ->getUniqueString (),
228
232
]);
229
233
return [
230
234
[
231
235
'fields ' => $ this ->getQuestion ([
232
236
'name ' => 'fieldname ' ,
233
- 'itemtype ' => \ Location::class,
237
+ 'itemtype ' => Location::class,
234
238
'values ' => '' ,
235
239
'required ' => '1 ' ,
236
- 'dropdown_values ' => \ Location::class,
240
+ 'dropdown_values ' => Location::class,
237
241
'dropdown_default_value ' => '42 ' ,
238
242
]),
239
243
'value ' => "" ,
@@ -242,10 +246,10 @@ public function providerGetValueForTargetText() {
242
246
[
243
247
'fields ' => $ this ->getQuestion ([
244
248
'name ' => 'fieldname ' ,
245
- 'itemtype ' =>\ Location::class,
249
+ 'itemtype ' =>Location::class,
246
250
'values ' =>'' ,
247
251
'required ' => '1 ' ,
248
- 'dropdown_values ' => \ Location::class,
252
+ 'dropdown_values ' => Location::class,
249
253
'dropdown_default_value ' => '' ,
250
254
]),
251
255
'value ' => $ location ->getID (),
@@ -266,8 +270,8 @@ public function testGetValueForTargetText($fields, $value, $expected) {
266
270
}
267
271
268
272
public function providerEquals () {
269
- $ location1 = new \ Location ();
270
- $ location2 = new \ Location ();
273
+ $ location1 = new Location ();
274
+ $ location2 = new Location ();
271
275
$ location1Id = $ location1 ->add ([
272
276
'name ' => $ this ->getUniqueString ()
273
277
]);
@@ -278,15 +282,15 @@ public function providerEquals() {
278
282
return [
279
283
[
280
284
'fields ' => $ this ->getQuestion ([
281
- 'itemtype ' => \ Location::class,
285
+ 'itemtype ' => Location::class,
282
286
]),
283
287
'value ' => $ location1 ->fields ['completename ' ],
284
288
'answer ' => (string ) $ location1Id ,
285
289
'expected ' => true ,
286
290
],
287
291
[
288
292
'fields ' => $ this ->getQuestion ([
289
- 'itemtype ' => \ Location::class,
293
+ 'itemtype ' => Location::class,
290
294
]),
291
295
'value ' => $ location2 ->fields ['completename ' ],
292
296
'answer ' => (string ) $ location1Id ,
@@ -305,8 +309,8 @@ public function testEquals($fields, $value, $answer, $expected) {
305
309
}
306
310
307
311
public function providerNotEquals () {
308
- $ location1 = new \ Location ();
309
- $ location2 = new \ Location ();
312
+ $ location1 = new Location ();
313
+ $ location2 = new Location ();
310
314
$ location1Id = $ location1 ->add ([
311
315
'name ' => $ this ->getUniqueString ()
312
316
]);
@@ -317,15 +321,15 @@ public function providerNotEquals() {
317
321
return [
318
322
[
319
323
'fields ' => $ this ->getQuestion ([
320
- 'itemtype ' => \ Location::class,
324
+ 'itemtype ' => Location::class,
321
325
]),
322
326
'value ' => $ location1 ->fields ['completename ' ],
323
327
'answer ' => (string ) $ location1Id ,
324
328
'expected ' => false ,
325
329
],
326
330
[
327
331
'fields ' => $ this ->getQuestion ([
328
- 'itemtype ' => \ Location::class,
332
+ 'itemtype ' => Location::class,
329
333
]),
330
334
'value ' => $ location2 ->fields ['completename ' ],
331
335
'answer ' => (string ) $ location1Id ,
0 commit comments