1
|
|
|
<?php |
2
|
|
|
namespace OptimizelyPHPTest\Service\v2; |
3
|
|
|
|
4
|
|
|
use PHPUnit_Framework_TestCase; |
5
|
|
|
use WebMarketingROI\OptimizelyPHP\OptimizelyApiClient; |
6
|
|
|
use WebMarketingROI\OptimizelyPHP\Result; |
7
|
|
|
use WebMarketingROI\OptimizelyPHP\Service\v2\Experiments; |
8
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\Experiment; |
9
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\ExperimentResults; |
10
|
|
|
|
11
|
|
|
class ExperimentsTest extends PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
public function testListAll() |
14
|
|
|
{ |
15
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
16
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
17
|
|
|
->disableOriginalConstructor() |
18
|
|
|
->getMock(); |
19
|
|
|
|
20
|
|
|
$curDate = date('Y-m-d H:i:s'); |
|
|
|
|
21
|
|
|
|
22
|
|
|
$result = new Result(array( |
23
|
|
|
array( |
24
|
|
|
"project_id" => 1000, |
25
|
|
|
"audience_ids" => array( |
26
|
|
|
1234, |
27
|
|
|
1212, |
28
|
|
|
1432 |
29
|
|
|
), |
30
|
|
|
"campaign_id" => 2000, |
31
|
|
|
"changes" => array( |
32
|
|
|
array( |
33
|
|
|
"type" => "custom_code", |
34
|
|
|
"allow_additional_redirect" => true, |
35
|
|
|
"async" => true, |
36
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
37
|
|
|
"dependencies" => array( |
38
|
|
|
24, |
39
|
|
|
26 |
40
|
|
|
), |
41
|
|
|
"destination" => "https://app.optimizely.com/", |
42
|
|
|
"extension_id" => 1234, |
43
|
|
|
"preserve_parameters" => true, |
44
|
|
|
"src" => 524, |
45
|
|
|
"value" => "window.someGlobalFunction();", |
46
|
|
|
"id" => "string" |
47
|
|
|
) |
48
|
|
|
), |
49
|
|
|
"description" => "string", |
50
|
|
|
"holdback" => 5000, |
51
|
|
|
"key" => "home_page_experiment", |
52
|
|
|
"metrics" => array( |
53
|
|
|
array( |
54
|
|
|
"kind" => "string", |
55
|
|
|
"id" => 0 |
56
|
|
|
) |
57
|
|
|
), |
58
|
|
|
"name" => "Blue Button Experiment", |
59
|
|
|
"schedule" => array( |
60
|
|
|
"start_time" => "2016-10-17T07:05:00.070Z", |
61
|
|
|
"stop_time" => "2016-10-17T07:05:00.070Z", |
62
|
|
|
"time_zone" => "UTC" |
63
|
|
|
), |
64
|
|
|
"status" => "active", |
65
|
|
|
"variations" => array( |
66
|
|
|
array( |
67
|
|
|
"actions" => array( |
68
|
|
|
array( |
69
|
|
|
"changes" => array( |
70
|
|
|
array( |
71
|
|
|
"type" => "custom_code", |
72
|
|
|
"allow_additional_redirect" => true, |
73
|
|
|
"async" => true, |
74
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
75
|
|
|
"dependencies" => array( |
76
|
|
|
24, |
77
|
|
|
26 |
78
|
|
|
), |
79
|
|
|
"destination" => "https://app.optimizely.com/", |
80
|
|
|
"extension_id" => 1234, |
81
|
|
|
"preserve_parameters" => true, |
82
|
|
|
"src" => 524, |
83
|
|
|
"value" => "window.someGlobalFunction();", |
84
|
|
|
"id" => "string" |
85
|
|
|
) |
86
|
|
|
), |
87
|
|
|
"page_id" => 0 |
88
|
|
|
) |
89
|
|
|
), |
90
|
|
|
"archived"=> true, |
91
|
|
|
"key" => "blue_button_variation", |
92
|
|
|
"name" => "Blue Button", |
93
|
|
|
"variation_id" => 0, |
94
|
|
|
"weight" => 0 |
95
|
|
|
) |
96
|
|
|
), |
97
|
|
|
"created" => "2016-10-17T07:05:00.070Z", |
98
|
|
|
"id" => 3000, |
99
|
|
|
"is_classic" => false, |
100
|
|
|
"last_modified" => "2016-10-17T07:05:00.070Z" |
101
|
|
|
) |
102
|
|
|
), 200); |
103
|
|
|
|
104
|
|
|
$optimizelyApiClientMock->method('sendApiRequest') |
105
|
|
|
->willReturn($result); |
106
|
|
|
|
107
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
108
|
|
|
|
109
|
|
|
$result = $experimentsService->listAll(1000); |
110
|
|
|
$experiments = $result->getPayload(); |
111
|
|
|
|
112
|
|
|
$this->assertTrue(count($experiments)==1); |
113
|
|
|
$this->assertTrue($experiments[0] instanceOf Experiment); |
114
|
|
|
$this->assertTrue($experiments[0]->getName()=='Blue Button Experiment'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @expectedException Exception |
119
|
|
|
*/ |
120
|
|
View Code Duplication |
public function testListAll_BothProjectIdAndCampaignIdAreNull() |
|
|
|
|
121
|
|
|
{ |
122
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
123
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
124
|
|
|
->disableOriginalConstructor() |
125
|
|
|
->getMock(); |
126
|
|
|
|
127
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
128
|
|
|
|
129
|
|
|
$result = $experimentsService->listAll(null, null, false, 1, 25); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @expectedException Exception |
134
|
|
|
*/ |
135
|
|
View Code Duplication |
public function testListAll_InvalidPage() |
|
|
|
|
136
|
|
|
{ |
137
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
138
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
139
|
|
|
->disableOriginalConstructor() |
140
|
|
|
->getMock(); |
141
|
|
|
|
142
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
143
|
|
|
|
144
|
|
|
$result = $experimentsService->listAll(1000, null, false, -1, 25); |
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @expectedException Exception |
149
|
|
|
*/ |
150
|
|
View Code Duplication |
public function testListAll_InvalidPerPage() |
|
|
|
|
151
|
|
|
{ |
152
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
153
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
154
|
|
|
->disableOriginalConstructor() |
155
|
|
|
->getMock(); |
156
|
|
|
|
157
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
158
|
|
|
|
159
|
|
|
$result = $experimentsService->listAll(1000, null, false, 1, 10000); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function testGet() |
163
|
|
|
{ |
164
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
165
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
166
|
|
|
->disableOriginalConstructor() |
167
|
|
|
->getMock(); |
168
|
|
|
|
169
|
|
|
$result = new Result(array( |
170
|
|
|
"project_id" => 1000, |
171
|
|
|
"audience_ids" => array( |
172
|
|
|
1234, |
173
|
|
|
1212, |
174
|
|
|
1432 |
175
|
|
|
), |
176
|
|
|
"campaign_id" => 2000, |
177
|
|
|
"changes" => array( |
178
|
|
|
array( |
179
|
|
|
"type" => "custom_code", |
180
|
|
|
"allow_additional_redirect" => true, |
181
|
|
|
"async" => true, |
182
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
183
|
|
|
"dependencies" => array( |
184
|
|
|
24, |
185
|
|
|
26 |
186
|
|
|
), |
187
|
|
|
"destination" => "https://app.optimizely.com/", |
188
|
|
|
"extension_id" => 1234, |
189
|
|
|
"preserve_parameters" => true, |
190
|
|
|
"src" => 524, |
191
|
|
|
"value" => "window.someGlobalFunction();", |
192
|
|
|
"id" => "string" |
193
|
|
|
) |
194
|
|
|
), |
195
|
|
|
"description" => "string", |
196
|
|
|
"holdback" => 5000, |
197
|
|
|
"key" => "home_page_experiment", |
198
|
|
|
"metrics" => array( |
199
|
|
|
array( |
200
|
|
|
"kind" => "string", |
201
|
|
|
"id" => 0 |
202
|
|
|
) |
203
|
|
|
), |
204
|
|
|
"name" => "Blue Button Experiment", |
205
|
|
|
"schedule" => array( |
206
|
|
|
"start_time" => "2016-10-17T07:05:00.070Z", |
207
|
|
|
"stop_time" => "2016-10-17T07:05:00.070Z", |
208
|
|
|
"time_zone" => "UTC" |
209
|
|
|
), |
210
|
|
|
"status" => "active", |
211
|
|
|
"variations" => array( |
212
|
|
|
array( |
213
|
|
|
"actions" => array( |
214
|
|
|
array( |
215
|
|
|
"changes" => array( |
216
|
|
|
array( |
217
|
|
|
"type" => "custom_code", |
218
|
|
|
"allow_additional_redirect" => true, |
219
|
|
|
"async" => true, |
220
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
221
|
|
|
"dependencies" => array( |
222
|
|
|
24, |
223
|
|
|
26 |
224
|
|
|
), |
225
|
|
|
"destination" => "https://app.optimizely.com/", |
226
|
|
|
"extension_id" => 1234, |
227
|
|
|
"preserve_parameters" => true, |
228
|
|
|
"src" => 524, |
229
|
|
|
"value" => "window.someGlobalFunction();", |
230
|
|
|
"id" => "string" |
231
|
|
|
) |
232
|
|
|
), |
233
|
|
|
"page_id" => 0 |
234
|
|
|
) |
235
|
|
|
), |
236
|
|
|
"archived"=> true, |
237
|
|
|
"key" => "blue_button_variation", |
238
|
|
|
"name" => "Blue Button", |
239
|
|
|
"variation_id" => 0, |
240
|
|
|
"weight" => 0 |
241
|
|
|
) |
242
|
|
|
), |
243
|
|
|
"created" => "2016-10-17T07:05:00.070Z", |
244
|
|
|
"id" => 3000, |
245
|
|
|
"is_classic" => false, |
246
|
|
|
"last_modified" => "2016-10-17T07:05:00.070Z" |
247
|
|
|
), 200); |
248
|
|
|
|
249
|
|
|
$optimizelyApiClientMock->method('sendApiRequest') |
250
|
|
|
->willReturn($result); |
251
|
|
|
|
252
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
253
|
|
|
|
254
|
|
|
$result = $experimentsService->get(3000); |
255
|
|
|
$experiment = $result->getPayload(); |
256
|
|
|
|
257
|
|
|
$this->assertTrue($experiment instanceOf Experiment); |
258
|
|
|
$this->assertTrue($experiment->getName()=='Blue Button Experiment'); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @expectedException Exception |
263
|
|
|
*/ |
264
|
|
View Code Duplication |
public function testGet_NotIntegerExperimentId() |
|
|
|
|
265
|
|
|
{ |
266
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
267
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
268
|
|
|
->disableOriginalConstructor() |
269
|
|
|
->getMock(); |
270
|
|
|
|
271
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
272
|
|
|
|
273
|
|
|
$result = $experimentsService->get('1'); |
|
|
|
|
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @expectedException Exception |
278
|
|
|
*/ |
279
|
|
View Code Duplication |
public function testGet_NegativeExperimentId() |
|
|
|
|
280
|
|
|
{ |
281
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
282
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
283
|
|
|
->disableOriginalConstructor() |
284
|
|
|
->getMock(); |
285
|
|
|
|
286
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
287
|
|
|
|
288
|
|
|
$result = $experimentsService->get(-1); |
|
|
|
|
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
public function testGetResults() |
292
|
|
|
{ |
293
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
294
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
295
|
|
|
->disableOriginalConstructor() |
296
|
|
|
->getMock(); |
297
|
|
|
|
298
|
|
|
$result = new Result(array( |
299
|
|
|
"confidence_threshold" => 0.9, |
300
|
|
|
"end_time" => "2016-10-17T07:05:00.089Z", |
301
|
|
|
"experiment_id" => 3000, |
302
|
|
|
"metrics" => array( |
303
|
|
|
array( |
304
|
|
|
"event" => "string", |
305
|
|
|
"event_name" => "string", |
306
|
|
|
"measure" => "conversions", |
307
|
|
|
"metric_id" => "string", |
308
|
|
|
"priority" => 1, |
309
|
|
|
"unit" => "session", |
310
|
|
|
"variation_results" => array( |
311
|
|
|
"9000" => array( |
312
|
|
|
"experiment_id" => 0, |
313
|
|
|
"is_baseline" => true, |
314
|
|
|
"lift" => array( |
315
|
|
|
"confidence_interval" => array( |
316
|
|
|
0.010399560300730457, |
317
|
|
|
0.0850821459929161 |
318
|
|
|
), |
319
|
|
|
"is_most_conclusive" => true, |
320
|
|
|
"is_significant" => true, |
321
|
|
|
"significance" => 0, |
322
|
|
|
"value" => 0, |
323
|
|
|
"visitors_remaining" => 0 |
324
|
|
|
), |
325
|
|
|
"name" => "Blue Button", |
326
|
|
|
"rate" => 0, |
327
|
|
|
"scope" => "variation", |
328
|
|
|
"total_increase" => array( |
329
|
|
|
"confidence_interval" => array( |
330
|
|
|
0.010399560300730457, |
331
|
|
|
0.0850821459929161 |
332
|
|
|
), |
333
|
|
|
"is_most_conclusive" => true, |
334
|
|
|
"is_significant" => true, |
335
|
|
|
"significance" => 0, |
336
|
|
|
"value" => 0, |
337
|
|
|
"visitors_remaining" => 0 |
338
|
|
|
), |
339
|
|
|
"value" => 0, |
340
|
|
|
"variation_id" => "string" |
341
|
|
|
) |
342
|
|
|
) |
343
|
|
|
) |
344
|
|
|
), |
345
|
|
|
"reach" => array( |
346
|
|
|
"baseline_count" => 0, |
347
|
|
|
"baseline_reach" => 0, |
348
|
|
|
"total_count" => 0, |
349
|
|
|
"treatment_count" => 0, |
350
|
|
|
"treatment_reach" => 0, |
351
|
|
|
"variations" => array( |
352
|
|
|
"9000" => array( |
353
|
|
|
"count" => 0, |
354
|
|
|
"name" => "Blue Button", |
355
|
|
|
"variation_id" => "string", |
356
|
|
|
"variation_reach" => 0 |
357
|
|
|
) |
358
|
|
|
) |
359
|
|
|
), |
360
|
|
|
"start_time" => "2016-10-17T07:05:00.090Z" |
361
|
|
|
), 200); |
362
|
|
|
|
363
|
|
|
$optimizelyApiClientMock->method('sendApiRequest') |
364
|
|
|
->willReturn($result); |
365
|
|
|
|
366
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
367
|
|
|
|
368
|
|
|
$result = $experimentsService->getResults(3000); |
369
|
|
|
$experimentResults = $result->getPayload(); |
370
|
|
|
|
371
|
|
|
$this->assertTrue($experimentResults instanceOf ExperimentResults); |
372
|
|
|
$this->assertTrue($experimentResults->getConfidenceThreshold()==0.9); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
public function testCreate() |
376
|
|
|
{ |
377
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
378
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
379
|
|
|
->disableOriginalConstructor() |
380
|
|
|
->getMock(); |
381
|
|
|
|
382
|
|
|
$result = new Result(array( |
383
|
|
|
"project_id" => 1000, |
384
|
|
|
"audience_ids" => array( |
385
|
|
|
1234, |
386
|
|
|
1212, |
387
|
|
|
1432 |
388
|
|
|
), |
389
|
|
|
"campaign_id" => 2000, |
390
|
|
|
"changes" => array( |
391
|
|
|
array( |
392
|
|
|
"type" => "custom_code", |
393
|
|
|
"allow_additional_redirect" => true, |
394
|
|
|
"async" => true, |
395
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
396
|
|
|
"dependencies" => array( |
397
|
|
|
24, |
398
|
|
|
26 |
399
|
|
|
), |
400
|
|
|
"destination" => "https://app.optimizely.com/", |
401
|
|
|
"extension_id" => 1234, |
402
|
|
|
"preserve_parameters" => true, |
403
|
|
|
"src" => 524, |
404
|
|
|
"value" => "window.someGlobalFunction();", |
405
|
|
|
"id" => "string" |
406
|
|
|
) |
407
|
|
|
), |
408
|
|
|
"description" => "string", |
409
|
|
|
"holdback" => 5000, |
410
|
|
|
"key" => "home_page_experiment", |
411
|
|
|
"metrics" => array( |
412
|
|
|
array( |
413
|
|
|
"kind" => "string", |
414
|
|
|
"id" => 0 |
415
|
|
|
) |
416
|
|
|
), |
417
|
|
|
"name" => "Blue Button Experiment", |
418
|
|
|
"schedule" => array( |
419
|
|
|
"start_time" => "2016-10-17T07:05:00.099Z", |
420
|
|
|
"stop_time" => "2016-10-17T07:05:00.099Z", |
421
|
|
|
"time_zone" => "UTC" |
422
|
|
|
), |
423
|
|
|
"status" => "active", |
424
|
|
|
"variations" => array( |
425
|
|
|
array( |
426
|
|
|
"actions" => array( |
427
|
|
|
array( |
428
|
|
|
"changes" => array( |
429
|
|
|
array( |
430
|
|
|
"type" => "custom_code", |
431
|
|
|
"allow_additional_redirect" => true, |
432
|
|
|
"async" => true, |
433
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
434
|
|
|
"dependencies" => array( |
435
|
|
|
24, |
436
|
|
|
26 |
437
|
|
|
), |
438
|
|
|
"destination" => "https://app.optimizely.com/", |
439
|
|
|
"extension_id" => 1234, |
440
|
|
|
"preserve_parameters" => true, |
441
|
|
|
"src" => 524, |
442
|
|
|
"value" => "window.someGlobalFunction();", |
443
|
|
|
"id" => "string" |
444
|
|
|
) |
445
|
|
|
), |
446
|
|
|
"page_id" => 0 |
447
|
|
|
) |
448
|
|
|
), |
449
|
|
|
"archived" => true, |
450
|
|
|
"key" => "blue_button_variation", |
451
|
|
|
"name" => "Blue Button", |
452
|
|
|
"variation_id" => 0, |
453
|
|
|
"weight" => 0 |
454
|
|
|
) |
455
|
|
|
), |
456
|
|
|
"created" => "2016-10-17T07:05:00.099Z", |
457
|
|
|
"id" => 3000, |
458
|
|
|
"is_classic" => false, |
459
|
|
|
"last_modified" => "2016-10-17T07:05:00.099Z" |
460
|
|
|
), 201); |
461
|
|
|
|
462
|
|
|
$optimizelyApiClientMock->method('sendApiRequest') |
463
|
|
|
->willReturn($result); |
464
|
|
|
|
465
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
466
|
|
|
|
467
|
|
|
$experiment = new Experiment(array( |
468
|
|
|
"project_id" => 1000, |
469
|
|
|
"audience_ids" => array( |
470
|
|
|
1234, |
471
|
|
|
1212, |
472
|
|
|
1432 |
473
|
|
|
), |
474
|
|
|
"campaign_id" => 2000, |
475
|
|
|
"changes" => array( |
476
|
|
|
array( |
477
|
|
|
"type" => "custom_code", |
478
|
|
|
"allow_additional_redirect" => true, |
479
|
|
|
"async" => true, |
480
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
481
|
|
|
"dependencies" => array( |
482
|
|
|
24, |
483
|
|
|
26 |
484
|
|
|
), |
485
|
|
|
"destination" => "https://app.optimizely.com/", |
486
|
|
|
"extension_id" => 1234, |
487
|
|
|
"preserve_parameters" => true, |
488
|
|
|
"src" => 524, |
489
|
|
|
"value" => "window.someGlobalFunction();" |
490
|
|
|
) |
491
|
|
|
), |
492
|
|
|
"description" => "string", |
493
|
|
|
"holdback" => 5000, |
494
|
|
|
"key" => "home_page_experiment", |
495
|
|
|
"metrics" => array( |
496
|
|
|
array( |
497
|
|
|
"kind" => "string" |
498
|
|
|
) |
499
|
|
|
), |
500
|
|
|
"name" => "Blue Button Experiment", |
501
|
|
|
"schedule" => array( |
502
|
|
|
"start_time" => "2016-10-17T07:04:59.724Z", |
503
|
|
|
"stop_time" => "2016-10-17T07:04:59.724Z", |
504
|
|
|
"time_zone" => "UTC" |
505
|
|
|
), |
506
|
|
|
"status" => "active", |
507
|
|
|
"variations" => array( |
508
|
|
|
array( |
509
|
|
|
"actions" => array( |
510
|
|
|
array( |
511
|
|
|
"changes" => array( |
512
|
|
|
array( |
513
|
|
|
"type" => "custom_code", |
514
|
|
|
"allow_additional_redirect" => true, |
515
|
|
|
"async" => true, |
516
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
517
|
|
|
"dependencies" => array( |
518
|
|
|
24, |
519
|
|
|
26 |
520
|
|
|
), |
521
|
|
|
"destination" => "https://app.optimizely.com/", |
522
|
|
|
"extension_id" => 1234, |
523
|
|
|
"preserve_parameters" => true, |
524
|
|
|
"src" => 524, |
525
|
|
|
"value" => "window.someGlobalFunction();" |
526
|
|
|
) |
527
|
|
|
), |
528
|
|
|
"page_id" => 0 |
529
|
|
|
) |
530
|
|
|
), |
531
|
|
|
"archived" => true, |
532
|
|
|
"key" => "blue_button_variation", |
533
|
|
|
"name" => "Blue Button", |
534
|
|
|
"variation_id" => 0, |
535
|
|
|
"weight" => 0 |
536
|
|
|
) |
537
|
|
|
) |
538
|
|
|
)); |
539
|
|
|
|
540
|
|
|
$result = $experimentsService->create($experiment, true); |
541
|
|
|
$createdExperiment = $result->getPayload(); |
542
|
|
|
|
543
|
|
|
$this->assertTrue($createdExperiment instanceOf Experiment); |
544
|
|
|
$this->assertTrue($createdExperiment->getName()=='Blue Button Experiment'); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
public function testUpdate() |
548
|
|
|
{ |
549
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
550
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
551
|
|
|
->disableOriginalConstructor() |
552
|
|
|
->getMock(); |
553
|
|
|
|
554
|
|
|
$result = new Result(array( |
555
|
|
|
"project_id" => 1000, |
556
|
|
|
"audience_ids" => array( |
557
|
|
|
1234, |
558
|
|
|
1212, |
559
|
|
|
1432 |
560
|
|
|
), |
561
|
|
|
"campaign_id" => 2000, |
562
|
|
|
"changes" => array( |
563
|
|
|
array( |
564
|
|
|
"type" => "custom_code", |
565
|
|
|
"allow_additional_redirect" => true, |
566
|
|
|
"async" => true, |
567
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
568
|
|
|
"dependencies" => array( |
569
|
|
|
24, |
570
|
|
|
26 |
571
|
|
|
), |
572
|
|
|
"destination" => "https://app.optimizely.com/", |
573
|
|
|
"extension_id" => 1234, |
574
|
|
|
"preserve_parameters" => true, |
575
|
|
|
"src" => 524, |
576
|
|
|
"value" => "window.someGlobalFunction();", |
577
|
|
|
"id" => "string" |
578
|
|
|
) |
579
|
|
|
), |
580
|
|
|
"description" => "string", |
581
|
|
|
"holdback" => 5000, |
582
|
|
|
"key" => "home_page_experiment", |
583
|
|
|
"metrics" => array( |
584
|
|
|
array( |
585
|
|
|
"kind" => "string", |
586
|
|
|
"id" => 0 |
587
|
|
|
) |
588
|
|
|
), |
589
|
|
|
"name" => "Blue Button Experiment", |
590
|
|
|
"schedule" => array( |
591
|
|
|
"start_time" => "2016-10-17T07:05:00.109Z", |
592
|
|
|
"stop_time" => "2016-10-17T07:05:00.109Z", |
593
|
|
|
"time_zone" => "UTC" |
594
|
|
|
), |
595
|
|
|
"status" => "active", |
596
|
|
|
"variations" => array( |
597
|
|
|
array( |
598
|
|
|
"actions" => array( |
599
|
|
|
array( |
600
|
|
|
"changes" => array( |
601
|
|
|
array( |
602
|
|
|
"type" => "custom_code", |
603
|
|
|
"allow_additional_redirect" => true, |
604
|
|
|
"async" => true, |
605
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
606
|
|
|
"dependencies" => array( |
607
|
|
|
24, |
608
|
|
|
26 |
609
|
|
|
), |
610
|
|
|
"destination" => "https://app.optimizely.com/", |
611
|
|
|
"extension_id" => 1234, |
612
|
|
|
"preserve_parameters" => true, |
613
|
|
|
"src" => 524, |
614
|
|
|
"value" => "window.someGlobalFunction();", |
615
|
|
|
"id" => "string" |
616
|
|
|
) |
617
|
|
|
), |
618
|
|
|
"page_id" => 0 |
619
|
|
|
) |
620
|
|
|
), |
621
|
|
|
"archived" => true, |
622
|
|
|
"key" => "blue_button_variation", |
623
|
|
|
"name" => "Blue Button", |
624
|
|
|
"variation_id" => 0, |
625
|
|
|
"weight" => 0 |
626
|
|
|
) |
627
|
|
|
), |
628
|
|
|
"created" => "2016-10-17T07:05:00.109Z", |
629
|
|
|
"id" => 3000, |
630
|
|
|
"is_classic" => false, |
631
|
|
|
"last_modified" => "2016-10-17T07:05:00.109Z" |
632
|
|
|
), 200); |
633
|
|
|
|
634
|
|
|
$optimizelyApiClientMock->method('sendApiRequest') |
635
|
|
|
->willReturn($result); |
636
|
|
|
|
637
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
638
|
|
|
|
639
|
|
|
$experiment = new Experiment(array( |
640
|
|
|
"audience_ids" => array( |
641
|
|
|
0 |
642
|
|
|
), |
643
|
|
|
"changes" => array( |
644
|
|
|
array( |
645
|
|
|
"type" => "custom_code", |
646
|
|
|
"allow_additional_redirect" => true, |
647
|
|
|
"async" => true, |
648
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
649
|
|
|
"dependencies" => array( |
650
|
|
|
24, |
651
|
|
|
26 |
652
|
|
|
), |
653
|
|
|
"destination" => "https://app.optimizely.com/", |
654
|
|
|
"extension_id" => 1234, |
655
|
|
|
"preserve_parameters" => true, |
656
|
|
|
"src" => 524, |
657
|
|
|
"value" => "window.someGlobalFunction();" |
658
|
|
|
) |
659
|
|
|
), |
660
|
|
|
"description" => "AB Test to see if the Blue Button converts more visitors", |
661
|
|
|
"holdback" => 0, |
662
|
|
|
"key" => "home_page_experiment", |
663
|
|
|
"metrics" => array( |
664
|
|
|
array( |
665
|
|
|
"kind" => "string" |
666
|
|
|
) |
667
|
|
|
), |
668
|
|
|
"name" => "Blue Button Experiment", |
669
|
|
|
"schedule" => array( |
670
|
|
|
"start_time" => "2016-10-17T07:04:59.731Z", |
671
|
|
|
"stop_time" => "2016-10-17T07:04:59.731Z", |
672
|
|
|
"time_zone" => "UTC" |
673
|
|
|
), |
674
|
|
|
"status" => "active", |
675
|
|
|
"variations" => array( |
676
|
|
|
array( |
677
|
|
|
"actions" => array( |
678
|
|
|
array( |
679
|
|
|
"changes" => array( |
680
|
|
|
array( |
681
|
|
|
"type" => "custom_code", |
682
|
|
|
"allow_additional_redirect" => true, |
683
|
|
|
"async" => true, |
684
|
|
|
"css_selector" => "a[href*=\"optimizely\"]", |
685
|
|
|
"dependencies" => array( |
686
|
|
|
24, |
687
|
|
|
26 |
688
|
|
|
), |
689
|
|
|
"destination" => "https://app.optimizely.com/", |
690
|
|
|
"extension_id" => 1234, |
691
|
|
|
"preserve_parameters" => true, |
692
|
|
|
"src" => 524, |
693
|
|
|
"value" => "window.someGlobalFunction();" |
694
|
|
|
) |
695
|
|
|
), |
696
|
|
|
"page_id" => 0 |
697
|
|
|
) |
698
|
|
|
), |
699
|
|
|
"archived" => true, |
700
|
|
|
"key" => "blue_button_variation", |
701
|
|
|
"name" => "Blue Button", |
702
|
|
|
"variation_id" => 0, |
703
|
|
|
"weight" => 0 |
704
|
|
|
) |
705
|
|
|
) |
706
|
|
|
)); |
707
|
|
|
|
708
|
|
|
$result = $experimentsService->update(1000, $experiment, true, true); |
709
|
|
|
$updatedExperiment = $result->getPayload(); |
710
|
|
|
|
711
|
|
|
$this->assertTrue($updatedExperiment instanceOf Experiment); |
712
|
|
|
$this->assertTrue($updatedExperiment->getName()=='Blue Button Experiment'); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
View Code Duplication |
public function testDelete() |
|
|
|
|
716
|
|
|
{ |
717
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
718
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
719
|
|
|
->disableOriginalConstructor() |
720
|
|
|
->getMock(); |
721
|
|
|
|
722
|
|
|
$result = new Result(array(), 200); |
723
|
|
|
|
724
|
|
|
$optimizelyApiClientMock->method('sendApiRequest') |
725
|
|
|
->willReturn($result); |
726
|
|
|
|
727
|
|
|
$experimentsService = new Experiments($optimizelyApiClientMock); |
728
|
|
|
|
729
|
|
|
$result = $experimentsService->delete(1000); |
730
|
|
|
|
731
|
|
|
$this->assertEquals(200, $result->getHttpCode()); |
732
|
|
|
} |
733
|
|
|
} |
734
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.