@@ -632,21 +632,21 @@ public function testGetRightNameForError($module, $right, $expected)
632
632
$ this ->string (\Session::getRightNameForError ($ module , $ right ))->isEqualTo ($ expected );
633
633
}
634
634
635
- protected function entitiesRestricProvider (): iterable
635
+ protected function entitiesRestrictProvider (): iterable
636
636
{
637
637
// Special case for -1
638
638
foreach ([-1 , "-1 " , [-1 ], ["-1 " ]] as $ value ) {
639
639
yield [
640
640
'entity_restrict ' => $ value ,
641
641
'active_entities ' => [0 , 1 , 2 , 3 ],
642
- 'result ' => is_array ( $ value) ? [- 1 ] : - 1 ,
642
+ 'result ' => $ value ,
643
643
];
644
644
}
645
645
646
646
// Integer input, matching
647
647
yield [
648
648
'entity_restrict ' => 2 ,
649
- 'active_entities ' => [0 , 1 , 2 , 3 ],
649
+ 'active_entities ' => [0 , 1 , ' 2 ' , 3 ],
650
650
'result ' => 2 ,
651
651
];
652
652
@@ -682,7 +682,7 @@ protected function entitiesRestricProvider(): iterable
682
682
yield [
683
683
'entity_restrict ' => [0 , '2 ' , 3 , 12 , 54 , 96 ],
684
684
'active_entities ' => [0 , 1 , 2 , 3 ],
685
- 'result ' => [0 , ' 2 ' , 3 ],
685
+ 'result ' => [0 , 2 , 3 ],
686
686
];
687
687
688
688
// Array input, NONE matching
@@ -712,14 +712,38 @@ protected function entitiesRestricProvider(): iterable
712
712
'active_entities ' => [0 , 1 , 2 , 3 ],
713
713
'result ' => [0 , 3 ],
714
714
];
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
+ }
715
725
}
716
726
717
727
/**
718
- * @dataProvider entitiesRestricProvider
728
+ * @dataProvider entitiesRestrictProvider
719
729
*/
720
730
public function testGetMatchingActiveEntities (/*int|array*/ $ entity_restrict , ?array $ active_entities , /*int|array*/ $ result ): void
721
731
{
722
732
$ _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 ();
724
748
}
725
749
}
0 commit comments