2929 * ---------------------------------------------------------------------
3030 */
3131namespace GlpiPlugin \Formcreator \Field \tests \units ;
32+
3233use GlpiPlugin \Formcreator \Tests \CommonTestCase ;
34+ use Computer ;
35+ use ITILCategory ;
3336use Location ;
3437class DropdownField extends CommonTestCase {
3538 public function beforeTestMethod ($ method ) {
@@ -52,14 +55,14 @@ public function providerPrepareQuestionInputForSave() {
5255 [
5356 'input ' => [
5457 'name ' => $ name ,
55- 'itemtype ' => \ Location::class,
58+ 'itemtype ' => Location::class,
5659 'show_tree_depth ' => '5 ' ,
5760 'show_tree_root ' => '0 ' ,
5861 'selectable_tree_root ' => '0 ' ,
5962 ],
6063 'expected ' => [
6164 'name ' => $ name ,
62- 'itemtype ' => \ Location::class,
65+ 'itemtype ' => Location::class,
6366 'values ' => json_encode ([
6467 'show_tree_depth ' => '5 ' ,
6568 'show_tree_root ' => '0 ' ,
@@ -71,7 +74,7 @@ public function providerPrepareQuestionInputForSave() {
7174 [
7275 'input ' => [
7376 'name ' => $ name ,
74- 'itemtype ' => \ ITILCategory::class,
77+ 'itemtype ' => ITILCategory::class,
7578 'show_ticket_categories ' => '2 ' ,
7679 'show_tree_depth ' => '3 ' ,
7780 'default_values ' => '' ,
@@ -112,7 +115,7 @@ public function testisPublicFormCompatible() {
112115
113116 public function testIsPrerequisites () {
114117 $ instance = $ this ->newTestedInstance ($ this ->getQuestion ([
115- 'itemtype ' => \ Computer::class
118+ 'itemtype ' => Computer::class
116119 ]));
117120 $ output = $ instance ->isPrerequisites ();
118121 $ this ->boolean ($ output )->isEqualTo (true );
@@ -133,12 +136,13 @@ public function testGetValueForDesign() {
133136 }
134137
135138 public function testGetDocumentsForTarget () {
136- $ instance = $ this ->newTestedInstance (new \PluginFormcreatorQuestion ());
139+ $ question = $ this ->getQuestion ();
140+ $ instance = $ question ->getSubField ();
137141 $ this ->array ($ instance ->getDocumentsForTarget ())->hasSize (0 );
138142 }
139143
140144 public function providerIsValid () {
141- $ location = new \ Location ();
145+ $ location = new Location ();
142146 $ locationId = $ location ->import ([
143147 'completename ' => 'foo ' ,
144148 'entities_id ' => $ _SESSION ['glpiactive_entity ' ]
@@ -148,13 +152,13 @@ public function providerIsValid() {
148152 [
149153 'question ' => $ this ->getQuestion ([
150154 'name ' => 'fieldname ' ,
151- 'itemtype ' => \ Location::class,
155+ 'itemtype ' => Location::class,
152156 'values ' => '' ,
153157 'required ' => '0 ' ,
154158 'default_values ' => '0 ' ,
155159 ]),
156160 'input ' => [
157- 'dropdown_values ' => \ Location::class,
161+ 'dropdown_values ' => Location::class,
158162 'dropdown_default_value ' => '0 ' ,
159163 'show_tree_depth ' => '5 ' ,
160164 'show_tree_root ' => '0 ' ,
@@ -164,12 +168,12 @@ public function providerIsValid() {
164168 [
165169 'question ' => $ this ->getQuestion ([
166170 'name ' => 'fieldname ' ,
167- 'itemtype ' => \ Location::class,
171+ 'itemtype ' => Location::class,
168172 'values ' => '' ,
169173 'required ' => '1 ' ,
170174 ]),
171175 'input ' => [
172- 'dropdown_values ' => \ Location::class,
176+ 'dropdown_values ' => Location::class,
173177 'dropdown_default_value ' => '0 ' ,
174178 'show_tree_depth ' => '5 ' ,
175179 'show_tree_root ' => '0 ' ,
@@ -179,13 +183,13 @@ public function providerIsValid() {
179183 [
180184 'question ' => $ this ->getQuestion ([
181185 'name ' => 'fieldname ' ,
182- 'itemtype ' => \ Location::class,
186+ 'itemtype ' => Location::class,
183187 'values ' => '' ,
184188 'required ' => '1 ' ,
185189 'default_values ' => '' ,
186190 ]),
187191 'input ' => [
188- 'dropdown_values ' => \ Location::class,
192+ 'dropdown_values ' => Location::class,
189193 'dropdown_default_value ' => '42 ' ,
190194 'show_tree_depth ' => '5 ' ,
191195 'show_tree_root ' => '0 ' ,
@@ -195,13 +199,13 @@ public function providerIsValid() {
195199 [
196200 'question ' => $ this ->getQuestion ([
197201 'name ' => 'fieldname ' ,
198- 'itemtype ' => \ Location::class,
202+ 'itemtype ' => Location::class,
199203 'values ' => '' ,
200204 'required ' => '1 ' ,
201205 'default_values ' => $ locationId ,
202206 ]),
203207 'input ' => [
204- 'dropdown_values ' => \ Location::class,
208+ 'dropdown_values ' => Location::class,
205209 'dropdown_default_value ' => '42 ' ,
206210 'show_tree_depth ' => '5 ' ,
207211 'show_tree_root ' => '0 ' ,
@@ -222,18 +226,18 @@ public function testIsValid($question, $input, $expectedValidity) {
222226 }
223227
224228 public function providerGetValueForTargetText () {
225- $ location = new \ Location ();
229+ $ location = new Location ();
226230 $ location ->add ([
227231 'name ' => $ this ->getUniqueString (),
228232 ]);
229233 return [
230234 [
231235 'fields ' => $ this ->getQuestion ([
232236 'name ' => 'fieldname ' ,
233- 'itemtype ' => \ Location::class,
237+ 'itemtype ' => Location::class,
234238 'values ' => '' ,
235239 'required ' => '1 ' ,
236- 'dropdown_values ' => \ Location::class,
240+ 'dropdown_values ' => Location::class,
237241 'dropdown_default_value ' => '42 ' ,
238242 ]),
239243 'value ' => "" ,
@@ -242,10 +246,10 @@ public function providerGetValueForTargetText() {
242246 [
243247 'fields ' => $ this ->getQuestion ([
244248 'name ' => 'fieldname ' ,
245- 'itemtype ' =>\ Location::class,
249+ 'itemtype ' =>Location::class,
246250 'values ' =>'' ,
247251 'required ' => '1 ' ,
248- 'dropdown_values ' => \ Location::class,
252+ 'dropdown_values ' => Location::class,
249253 'dropdown_default_value ' => '' ,
250254 ]),
251255 'value ' => $ location ->getID (),
@@ -266,8 +270,8 @@ public function testGetValueForTargetText($fields, $value, $expected) {
266270 }
267271
268272 public function providerEquals () {
269- $ location1 = new \ Location ();
270- $ location2 = new \ Location ();
273+ $ location1 = new Location ();
274+ $ location2 = new Location ();
271275 $ location1Id = $ location1 ->add ([
272276 'name ' => $ this ->getUniqueString ()
273277 ]);
@@ -278,15 +282,15 @@ public function providerEquals() {
278282 return [
279283 [
280284 'fields ' => $ this ->getQuestion ([
281- 'itemtype ' => \ Location::class,
285+ 'itemtype ' => Location::class,
282286 ]),
283287 'value ' => $ location1 ->fields ['completename ' ],
284288 'answer ' => (string ) $ location1Id ,
285289 'expected ' => true ,
286290 ],
287291 [
288292 'fields ' => $ this ->getQuestion ([
289- 'itemtype ' => \ Location::class,
293+ 'itemtype ' => Location::class,
290294 ]),
291295 'value ' => $ location2 ->fields ['completename ' ],
292296 'answer ' => (string ) $ location1Id ,
@@ -305,8 +309,8 @@ public function testEquals($fields, $value, $answer, $expected) {
305309 }
306310
307311 public function providerNotEquals () {
308- $ location1 = new \ Location ();
309- $ location2 = new \ Location ();
312+ $ location1 = new Location ();
313+ $ location2 = new Location ();
310314 $ location1Id = $ location1 ->add ([
311315 'name ' => $ this ->getUniqueString ()
312316 ]);
@@ -317,15 +321,15 @@ public function providerNotEquals() {
317321 return [
318322 [
319323 'fields ' => $ this ->getQuestion ([
320- 'itemtype ' => \ Location::class,
324+ 'itemtype ' => Location::class,
321325 ]),
322326 'value ' => $ location1 ->fields ['completename ' ],
323327 'answer ' => (string ) $ location1Id ,
324328 'expected ' => false ,
325329 ],
326330 [
327331 'fields ' => $ this ->getQuestion ([
328- 'itemtype ' => \ Location::class,
332+ 'itemtype ' => Location::class,
329333 ]),
330334 'value ' => $ location2 ->fields ['completename ' ],
331335 'answer ' => (string ) $ location1Id ,
0 commit comments