@@ -31,12 +31,14 @@ class OptimizelyTest extends \PHPUnit_Framework_TestCase
3131{
3232 private $ datafile ;
3333 private $ eventBuilderMock ;
34+ private $ optObj ;
3435 private $ projectConfig ;
3536
3637 public function setUp ()
3738 {
3839 $ this ->datafile = DATAFILE ;
3940 $ this ->projectConfig = new ProjectConfig ($ this ->datafile );
41+ $ this ->optObj = new Optimizely ($ this ->datafile );
4042
4143 // Mock EventBuilder
4244 $ this ->eventBuilderMock = $ this ->getMockBuilder (EventBuilder::class)
@@ -143,6 +145,92 @@ public function testValidateInputsInvalidFileJsonValidationSkipped()
143145 );
144146 }
145147
148+ public function testValidatePreconditionsExperimentNotRunning ()
149+ {
150+ $ validatePreconditions = new \ReflectionMethod ('Optimizely\Optimizely ' , 'validatePreconditions ' );
151+ $ validatePreconditions ->setAccessible (true );
152+
153+ $ this ->assertFalse (
154+ $ validatePreconditions ->invoke (
155+ $ this ->optObj ,
156+ $ this ->projectConfig ->getExperimentFromKey ('paused_experiment ' ),
157+ 'test_user ' ,
158+ [])
159+ );
160+ }
161+
162+ public function testValidatePreconditionsExperimentRunning ()
163+ {
164+ $ validatePreconditions = new \ReflectionMethod ('Optimizely\Optimizely ' , 'validatePreconditions ' );
165+ $ validatePreconditions ->setAccessible (true );
166+
167+ $ this ->assertTrue (
168+ $ validatePreconditions ->invoke (
169+ $ this ->optObj ,
170+ $ this ->projectConfig ->getExperimentFromKey ('test_experiment ' ),
171+ 'test_user ' ,
172+ [])
173+ );
174+ }
175+
176+ public function testValidatePreconditionsUserInForcedVariationNotInExperiment ()
177+ {
178+ $ validatePreconditions = new \ReflectionMethod ('Optimizely\Optimizely ' , 'validatePreconditions ' );
179+ $ validatePreconditions ->setAccessible (true );
180+
181+ $ this ->assertTrue (
182+ $ validatePreconditions ->invoke (
183+ $ this ->optObj ,
184+ $ this ->projectConfig ->getExperimentFromKey ('test_experiment ' ),
185+ 'user_1 ' ,
186+ [])
187+ );
188+ }
189+
190+ public function testValidatePreconditionsUserInForcedVariationInExperiment ()
191+ {
192+ $ validatePreconditions = new \ReflectionMethod ('Optimizely\Optimizely ' , 'validatePreconditions ' );
193+ $ validatePreconditions ->setAccessible (true );
194+
195+ $ this ->assertTrue (
196+ $ validatePreconditions ->invoke (
197+ $ this ->optObj ,
198+ $ this ->projectConfig ->getExperimentFromKey ('test_experiment ' ),
199+ 'user1 ' ,
200+ [])
201+ );
202+ }
203+
204+ public function testValidatePreconditionsUserNotInForcedVariationNotInExperiment ()
205+ {
206+ $ validatePreconditions = new \ReflectionMethod ('Optimizely\Optimizely ' , 'validatePreconditions ' );
207+ $ validatePreconditions ->setAccessible (true );
208+
209+ // Will get updated when we have audience evaluation and user does not meet conditions
210+ $ this ->assertTrue (
211+ $ validatePreconditions ->invoke (
212+ $ this ->optObj ,
213+ $ this ->projectConfig ->getExperimentFromKey ('test_experiment ' ),
214+ 'test_user ' ,
215+ [])
216+ );
217+ }
218+
219+ public function testValidatePreconditionsUserNotInForcedVariationInExperiment ()
220+ {
221+ $ validatePreconditions = new \ReflectionMethod ('Optimizely\Optimizely ' , 'validatePreconditions ' );
222+ $ validatePreconditions ->setAccessible (true );
223+
224+ // Will get updated when we have audience evaluation and user does meets conditions
225+ $ this ->assertTrue (
226+ $ validatePreconditions ->invoke (
227+ $ this ->optObj ,
228+ $ this ->projectConfig ->getExperimentFromKey ('test_experiment ' ),
229+ 'test_user ' ,
230+ [])
231+ );
232+ }
233+
146234 public function testActivateNoAttributes ()
147235 {
148236 $ this ->eventBuilderMock ->expects ($ this ->once ())
0 commit comments