|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\BannerServer\Tests\Unit\UseCase\BannerSelection; |
|
6
|
|
|
|
|
7
|
|
|
use Monolog\Handler\TestHandler; |
|
8
|
|
|
use Monolog\Logger; |
|
9
|
|
|
use Psr\Log\NullLogger; |
|
10
|
|
|
use WMDE\BannerServer\Entity\BannerSelection\CampaignCollection; |
|
11
|
|
|
use WMDE\BannerServer\UseCase\BannerSelection\CampaignConfigurationLoader; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @covers \WMDE\BannerServer\UseCase\BannerSelection\CampaignConfigurationLoader |
|
15
|
|
|
* Class ActiveBannerSelectionDataTest |
|
16
|
|
|
*/ |
|
17
|
|
|
class CampaignConfigurationLoaderTest extends \PHPUnit\Framework\TestCase { |
|
18
|
|
|
|
|
19
|
|
|
const TEST_CAMPAIGN_CONFIGURATION_FILE = 'tests/Fixtures/campaigns/campaigns.yml'; |
|
20
|
|
|
|
|
21
|
|
|
public function test_given_campaigns_are_loaded_then_loaded_campaign_data_is_correct() { |
|
22
|
|
|
$loader = new CampaignConfigurationLoader( new NullLogger(), self::TEST_CAMPAIGN_CONFIGURATION_FILE ); |
|
23
|
|
|
$collection = $loader->getCampaignCollection(); |
|
24
|
|
|
|
|
25
|
|
|
$campaign = $collection->getCampaign( new \DateTime( '2018-12-12' ) ); |
|
26
|
|
|
$this->assertNotNull( $campaign ); |
|
27
|
|
|
$this->assertEquals( 'B18WPDE_01_180131', $campaign->getIdentifier() ); |
|
28
|
|
|
$this->assertEquals( '2019-01-01 14:00:00', $campaign->getEnd()->format( 'Y-m-d H:i:s' ) ); |
|
29
|
|
|
$this->assertEquals( 10, $campaign->getDisplayPercentage() ); |
|
30
|
|
|
|
|
31
|
|
|
$bucketA = $campaign->selectBucket( 'B18WPDE_01_180131_ctrl' ); |
|
32
|
|
|
$bucketB = $campaign->selectBucket( 'B18WPDE_01_180131_var' ); |
|
33
|
|
|
$this->assertEquals( $bucketA->getIdentifier(), 'B18WPDE_01_180131_ctrl' ); |
|
34
|
|
|
$this->assertEquals( $bucketB->getIdentifier(), 'B18WPDE_01_180131_var' ); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertEquals( 'B18WPDE_01_180131_fulltop_ctrl', $bucketA->getBanner( 0 ) ); |
|
37
|
|
|
$this->assertEquals( 'B18WPDE_01_180131_top_ctrl2', $bucketA->getBanner( 1 ) ); |
|
38
|
|
|
$this->assertEquals( 'B18WPDE_02_180511_top_ctrl_last', $bucketA->getBanner( 5 ) ); |
|
39
|
|
|
$this->assertEquals( 'B18WPDE_02_180511_top_ctrl_last', $bucketA->getBanner( 10 ) ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function test_given_invalid_campaign_file_then_empty_campaign_configuration_is_returned() { |
|
43
|
|
|
$testHandler = new TestHandler(); |
|
44
|
|
|
$loader = new CampaignConfigurationLoader( |
|
45
|
|
|
new Logger( 'TestLogger', [ $testHandler ] ), |
|
46
|
|
|
'SOME_INVALID_PATH/' . self::TEST_CAMPAIGN_CONFIGURATION_FILE |
|
47
|
|
|
); |
|
48
|
|
|
$this->assertEquals( new CampaignCollection(), $loader->getCampaignCollection() ); |
|
49
|
|
|
$this->assertTrue( $testHandler->hasCritical( 'Unable to read banner server config file.' ) ); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|