|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
namespace WMDE\BannerServer\Tests\Unit\Entity\BannerSelection; |
|
4
|
|
|
|
|
5
|
|
|
use WMDE\BannerServer\Entity\BannerSelection\Campaign; |
|
6
|
|
|
use WMDE\BannerServer\Entity\BannerSelection\TrafficImpressionThreshold; |
|
7
|
|
|
|
|
8
|
|
|
class CampaignTest extends \PHPUnit\Framework\TestCase { |
|
9
|
|
|
|
|
10
|
|
|
public static function returnRandomBucket( $buckets ) { |
|
|
|
|
|
|
11
|
|
|
return $buckets[0]; |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function test_given_time_out_of_date_range_campaign_is_not_active() { |
|
15
|
|
|
$campaign = new Campaign( |
|
16
|
|
|
'C18_WMDE_Test', |
|
17
|
|
|
new \DateTime( '2018-10-01 14:00:00' ), |
|
18
|
|
|
new \DateTime( '2018-10-31 14:00:00' ), |
|
19
|
|
|
[], |
|
20
|
|
|
new TrafficImpressionThreshold( 10, 10 ) |
|
21
|
|
|
); |
|
22
|
|
|
$this->assertTrue( |
|
23
|
|
|
$campaign->isInActiveDateRange( new \DateTime( '2018-10-20 14:00:00' ) ), |
|
24
|
|
|
'date given is between the start and the end of the campaign' |
|
25
|
|
|
); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function test_given_time_the_date_range_campaign_is_active() { |
|
29
|
|
|
$campaign = new Campaign( |
|
30
|
|
|
'C18_WMDE_Test', |
|
31
|
|
|
new \DateTime( '2018-10-01 14:00:00' ), |
|
32
|
|
|
new \DateTime( '2018-10-31 14:00:00' ), |
|
33
|
|
|
[], |
|
34
|
|
|
new TrafficImpressionThreshold( 10, 10 ) |
|
35
|
|
|
); |
|
36
|
|
|
$this->assertFalse( |
|
37
|
|
|
$campaign->isInActiveDateRange( new \DateTime( '2018-09-22 14:00:00' ) ), |
|
38
|
|
|
'date given is before the start of the campaign' |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function test_given_valid_bucket_id_returns_bucket() { |
|
43
|
|
|
$campaign = new Campaign( |
|
44
|
|
|
'C18_WMDE_Test', |
|
45
|
|
|
new \DateTime( '2018-10-01 14:00:00' ), |
|
46
|
|
|
new \DateTime( '2018-10-31 14:00:00' ), |
|
47
|
|
|
[], |
|
48
|
|
|
new TrafficImpressionThreshold( 10, 10 ) |
|
49
|
|
|
); |
|
50
|
|
|
$this->assertEquals( |
|
51
|
|
|
$campaign->selectBucket( 'C18_WMDE_Test_var', [CampaignTest::class, 'returnRandomBucket'] ), |
|
|
|
|
|
|
52
|
|
|
'C18_WMDE_Test_var' |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function test_given_invalid_bucket_id_returns_random_bucket() { |
|
57
|
|
|
$campaign = new Campaign( |
|
58
|
|
|
'C18_WMDE_Test', |
|
59
|
|
|
new \DateTime( '2018-10-01 14:00:00' ), |
|
60
|
|
|
new \DateTime( '2018-10-31 14:00:00' ), |
|
61
|
|
|
[], |
|
62
|
|
|
new TrafficImpressionThreshold( 10, 10 ) |
|
63
|
|
|
); |
|
64
|
|
|
$this->assertEquals( |
|
65
|
|
|
$campaign->selectBucket( 9999, [CampaignTest::class, 'returnRandomBucket'] ), |
|
|
|
|
|
|
66
|
|
|
'' |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function test_given_no_bucket_id_returns_random_bucket() { |
|
71
|
|
|
$campaign = new Campaign( |
|
72
|
|
|
'C18_WMDE_Test', |
|
73
|
|
|
new \DateTime( '2018-10-01 14:00:00' ), |
|
74
|
|
|
new \DateTime( '2018-10-31 14:00:00' ), |
|
75
|
|
|
[], |
|
76
|
|
|
new TrafficImpressionThreshold( 10, 10 ) |
|
77
|
|
|
); |
|
78
|
|
|
$this->assertEquals( |
|
79
|
|
|
$campaign->selectBucket( null, [CampaignTest::class, 'returnRandomBucket'] ), |
|
|
|
|
|
|
80
|
|
|
'' |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|