1919include ('TestData.php ' );
2020
2121use Optimizely \Entity \Attribute ;
22+ use Optimizely \Entity \Audience ;
2223use Optimizely \Entity \Event ;
2324use Optimizely \Entity \Experiment ;
2425use Optimizely \Entity \Group ;
@@ -36,7 +37,108 @@ protected function setUp()
3637
3738 public function testInit ()
3839 {
39- $ this ->markTestSkipped ('To be implemented. ' );
40+ // Check version
41+ $ version = new \ReflectionProperty (ProjectConfig::class, '_version ' );
42+ $ version ->setAccessible (true );
43+ $ this ->assertEquals ('2 ' , $ version ->getValue ($ this ->config ));
44+
45+ // Check account ID
46+ $ accountId = new \ReflectionProperty (ProjectConfig::class, '_accountId ' );
47+ $ accountId ->setAccessible (true );
48+ $ this ->assertEquals ('1592310167 ' , $ accountId ->getValue ($ this ->config ));
49+
50+ // Check project ID
51+ $ projectId = new \ReflectionProperty (ProjectConfig::class, '_projectId ' );
52+ $ projectId ->setAccessible (true );
53+ $ this ->assertEquals ('7720880029 ' , $ projectId ->getValue ($ this ->config ));
54+
55+ // Check revision
56+ $ revision = new \ReflectionProperty (ProjectConfig::class, '_revision ' );
57+ $ revision ->setAccessible (true );
58+ $ this ->assertEquals ('15 ' , $ revision ->getValue ($ this ->config ));
59+
60+ // Check group ID map
61+ $ groupIdMap = new \ReflectionProperty (ProjectConfig::class, '_groupIdMap ' );
62+ $ groupIdMap ->setAccessible (true );
63+ $ this ->assertEquals ([
64+ '7722400015 ' => $ this ->config ->getGroup ('7722400015 ' )
65+ ], $ groupIdMap ->getValue ($ this ->config ));
66+
67+ // Check experiment key map
68+ $ experimentKeyMap = new \ReflectionProperty (ProjectConfig::class, '_experimentKeyMap ' );
69+ $ experimentKeyMap ->setAccessible (true );
70+ $ this ->assertEquals ([
71+ 'test_experiment ' => $ this ->config ->getExperimentFromKey ('test_experiment ' ),
72+ 'group_experiment_1 ' => $ this ->config ->getExperimentFromKey ('group_experiment_1 ' ),
73+ 'group_experiment_2 ' => $ this ->config ->getExperimentFromKey ('group_experiment_2 ' )
74+ ], $ experimentKeyMap ->getValue ($ this ->config ));
75+
76+ // Check experiment ID map
77+ $ experimentIdMap = new \ReflectionProperty (ProjectConfig::class, '_experimentIdMap ' );
78+ $ experimentIdMap ->setAccessible (true );
79+ $ this ->assertEquals ([
80+ '7716830082 ' => $ this ->config ->getExperimentFromId ('7716830082 ' ),
81+ '7723330021 ' => $ this ->config ->getExperimentFromId ('7723330021 ' ),
82+ '7718750065 ' => $ this ->config ->getExperimentFromId ('7718750065 ' )
83+ ], $ experimentIdMap ->getValue ($ this ->config ));
84+
85+ // Check event key map
86+ $ eventKeyMap = new \ReflectionProperty (ProjectConfig::class, '_eventKeyMap ' );
87+ $ eventKeyMap ->setAccessible (true );
88+ $ this ->assertEquals ([
89+ 'purchase ' => $ this ->config ->getEvent ('purchase ' )
90+ ], $ eventKeyMap ->getValue ($ this ->config ));
91+
92+ // Check attribute key map
93+ $ attributeKeyMap = new \ReflectionProperty (ProjectConfig::class, '_attributeKeyMap ' );
94+ $ attributeKeyMap ->setAccessible (true );
95+ $ this ->assertEquals ([
96+ 'device_type ' => $ this ->config ->getAttribute ('device_type ' ),
97+ 'location ' => $ this ->config ->getAttribute ('location ' )
98+ ], $ attributeKeyMap ->getValue ($ this ->config ));
99+
100+ // Check audience ID map
101+ $ audienceIdMap = new \ReflectionProperty (ProjectConfig::class, '_audienceIdMap ' );
102+ $ audienceIdMap ->setAccessible (true );
103+ $ this ->assertEquals ([
104+ '7718080042 ' => $ this ->config ->getAudience ('7718080042 ' )
105+ ], $ audienceIdMap ->getValue ($ this ->config ));
106+
107+ // Check variation key map
108+ $ variationKeyMap = new \ReflectionProperty (ProjectConfig::class, '_variationKeyMap ' );
109+ $ variationKeyMap ->setAccessible (true );
110+ $ this ->assertEquals ([
111+ 'test_experiment ' => [
112+ 'control ' => $ this ->config ->getVariationFromKey ('test_experiment ' , 'control ' ),
113+ 'variation ' => $ this ->config ->getVariationFromKey ('test_experiment ' , 'variation ' )
114+ ],
115+ 'group_experiment_1 ' => [
116+ 'group_exp_1_var_1 ' => $ this ->config ->getVariationFromKey ('group_experiment_1 ' , 'group_exp_1_var_1 ' ),
117+ 'group_exp_1_var_2 ' => $ this ->config ->getVariationFromKey ('group_experiment_1 ' , 'group_exp_1_var_2 ' )
118+ ],
119+ 'group_experiment_2 ' => [
120+ 'group_exp_2_var_1 ' => $ this ->config ->getVariationFromKey ('group_experiment_2 ' , 'group_exp_2_var_1 ' ),
121+ 'group_exp_2_var_2 ' => $ this ->config ->getVariationFromKey ('group_experiment_2 ' , 'group_exp_2_var_2 ' )
122+ ]
123+ ], $ variationKeyMap ->getValue ($ this ->config ));
124+
125+ // Check variation ID map
126+ $ variationIdMap = new \ReflectionProperty (ProjectConfig::class, '_variationIdMap ' );
127+ $ variationIdMap ->setAccessible (true );
128+ $ this ->assertEquals ([
129+ 'test_experiment ' => [
130+ '7722370027 ' => $ this ->config ->getVariationFromId ('test_experiment ' , '7722370027 ' ),
131+ '7721010009 ' => $ this ->config ->getVariationFromId ('test_experiment ' , '7721010009 ' )
132+ ],
133+ 'group_experiment_1 ' => [
134+ '7722260071 ' => $ this ->config ->getVariationFromId ('group_experiment_1 ' , '7722260071 ' ),
135+ '7722360022 ' => $ this ->config ->getVariationFromId ('group_experiment_1 ' , '7722360022 ' )
136+ ],
137+ 'group_experiment_2 ' => [
138+ '7713030086 ' => $ this ->config ->getVariationFromId ('group_experiment_2 ' , '7713030086 ' ),
139+ '7725250007 ' => $ this ->config ->getVariationFromId ('group_experiment_2 ' , '7725250007 ' )
140+ ]
141+ ], $ variationIdMap ->getValue ($ this ->config ));
40142 }
41143
42144 public function testGetAccountId ()
@@ -98,6 +200,18 @@ public function testGetEventInvalidKey()
98200 $ this ->assertEquals (new Event (), $ this ->config ->getEvent ('invalid_key ' ));
99201 }
100202
203+ public function testGetAudienceValidId ()
204+ {
205+ $ audience = $ this ->config ->getAudience ('7718080042 ' );
206+ $ this ->assertEquals ('7718080042 ' , $ audience ->getId ());
207+ $ this ->assertEquals ('iPhone users in San Francisco ' , $ audience ->getName ());
208+ }
209+
210+ public function testGetAudienceInvalidKey ()
211+ {
212+ $ this ->assertEquals (new Audience (), $ this ->config ->getAudience ('invalid_id ' ));
213+ }
214+
101215 public function testGetAttributeValidKey ()
102216 {
103217 $ attribute = $ this ->config ->getAttribute ('device_type ' );
0 commit comments