@@ -630,11 +630,13 @@ public function testSetGetForcedVariation()
630
630
$ userId = 'test_user ' ;
631
631
$ invalidUserId = 'invalid_user ' ;
632
632
$ experimentKey = 'test_experiment ' ;
633
+ $ experimentKey2 = 'group_experiment_1 ' ;
633
634
$ invalidExperimentKey = 'invalid_experiment ' ;
634
635
$ variationKey = 'control ' ;
636
+ $ variationKey2 = 'group_exp_1_var_1 ' ;
635
637
$ invalidVariationKey = 'invalid_variation ' ;
636
-
637
- $ optlyObject = new Optimizely (DATAFILE , new ValidEventDispatcher (), $ this ->loggerMock );
638
+
639
+ $ optlyObject = new Optimizely (DATAFILE , new ValidEventDispatcher (), $ this ->loggerMock );
638
640
$ userAttributes = [
639
641
'device_type ' => 'iPhone ' ,
640
642
'location ' => 'San Francisco '
@@ -661,6 +663,19 @@ public function testSetGetForcedVariation()
661
663
$ forcedVariation = $ this ->config ->getForcedVariation ($ experimentKey , $ userId );
662
664
$ this ->assertEquals ($ variationKey , $ forcedVariation ->getKey ());
663
665
666
+ // check multiple sets
667
+ $ this ->assertTrue ($ this ->config ->setForcedVariation ($ experimentKey2 , $ userId , $ variationKey2 ));
668
+ $ forcedVariation2 = $ this ->config ->getForcedVariation ($ experimentKey2 , $ userId );
669
+ $ this ->assertEquals ($ variationKey2 , $ forcedVariation2 ->getKey ());
670
+ // make sure the second set does not overwrite the first set
671
+ $ forcedVariation = $ this ->config ->getForcedVariation ($ experimentKey , $ userId );
672
+ $ this ->assertEquals ($ variationKey , $ forcedVariation ->getKey ());
673
+ // make sure unsetting the second experiment-to-variation mapping does not unset the
674
+ // first experiment-to-variation mapping
675
+ $ this ->assertTrue ($ this ->config ->setForcedVariation ($ experimentKey2 , $ userId , null ));
676
+ $ forcedVariation = $ this ->config ->getForcedVariation ($ experimentKey , $ userId );
677
+ $ this ->assertEquals ($ variationKey , $ forcedVariation ->getKey ());
678
+
664
679
// an invalid user ID should return a null variation
665
680
$ this ->assertNull ($ this ->config ->getForcedVariation ($ experimentKey , $ invalidUserId ));
666
681
}
0 commit comments