@@ -632,21 +632,21 @@ public function testGetRightNameForError($module, $right, $expected)
632632 $ this ->string (\Session::getRightNameForError ($ module , $ right ))->isEqualTo ($ expected );
633633 }
634634
635- protected function entitiesRestricProvider (): iterable
635+ protected function entitiesRestrictProvider (): iterable
636636 {
637637 // Special case for -1
638638 foreach ([-1 , "-1 " , [-1 ], ["-1 " ]] as $ value ) {
639639 yield [
640640 'entity_restrict ' => $ value ,
641641 'active_entities ' => [0 , 1 , 2 , 3 ],
642- 'result ' => is_array ( $ value) ? [- 1 ] : - 1 ,
642+ 'result ' => $ value ,
643643 ];
644644 }
645645
646646 // Integer input, matching
647647 yield [
648648 'entity_restrict ' => 2 ,
649- 'active_entities ' => [0 , 1 , 2 , 3 ],
649+ 'active_entities ' => [0 , 1 , ' 2 ' , 3 ],
650650 'result ' => 2 ,
651651 ];
652652
@@ -682,7 +682,7 @@ protected function entitiesRestricProvider(): iterable
682682 yield [
683683 'entity_restrict ' => [0 , '2 ' , 3 , 12 , 54 , 96 ],
684684 'active_entities ' => [0 , 1 , 2 , 3 ],
685- 'result ' => [0 , ' 2 ' , 3 ],
685+ 'result ' => [0 , 2 , 3 ],
686686 ];
687687
688688 // Array input, NONE matching
@@ -712,14 +712,38 @@ protected function entitiesRestricProvider(): iterable
712712 'active_entities ' => [0 , 1 , 2 , 3 ],
713713 'result ' => [0 , 3 ],
714714 ];
715+
716+ // Active entity may contain a string value
717+ // do not know why, but is is the case when only one entity is selected
718+ foreach ([2 , '2 ' , [2 ], ['2 ' ]] as $ entity_restrict ) {
719+ yield [
720+ 'entity_restrict ' => $ entity_restrict ,
721+ 'active_entities ' => [0 , 1 , '2 ' , 3 ],
722+ 'result ' => is_array ($ entity_restrict ) ? [2 ] : 2 ,
723+ ];
724+ }
715725 }
716726
717727 /**
718- * @dataProvider entitiesRestricProvider
728+ * @dataProvider entitiesRestrictProvider
719729 */
720730 public function testGetMatchingActiveEntities (/*int|array*/ $ entity_restrict , ?array $ active_entities , /*int|array*/ $ result ): void
721731 {
722732 $ _SESSION ['glpiactiveentities ' ] = $ active_entities ;
723- $ this ->variable (\Session::getMatchingActiveEntities ($ entity_restrict ))->isEqualTo ($ result );
733+ $ this ->variable (\Session::getMatchingActiveEntities ($ entity_restrict ))->isIdenticalTo ($ result );
734+ }
735+
736+ public function testGetMatchingActiveEntitiesWithUnexpectedValue (): void
737+ {
738+ $ _SESSION ['glpiactiveentities ' ] = [0 , 1 , 2 , 'foo ' , 3 ];
739+
740+ $ this ->when (
741+ function () {
742+ $ this ->variable (\Session::getMatchingActiveEntities ([2 , 3 ]))->isIdenticalTo ([2 , 3 ]);
743+ }
744+ )->error
745+ ->withType (E_USER_WARNING )
746+ ->withMessage ('Unexpected value `foo` found in `$_SESSION[ \'glpiactiveentities \']`. ' )
747+ ->exists ();
724748 }
725749}
0 commit comments