Completed
Push — master ( 00092a...39103d )
by wiese
86:17 queued 21:06
created

TemplateTestCampaignTest::isRunningDataProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Tests\Unit\Presentation;
6
7
use WMDE\Fundraising\Frontend\Presentation\TemplateTestCampaign;
8
9
/**
10
 * @covers \WMDE\Fundraising\Frontend\Presentation\TemplateTestCampaign
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Leszek Manicki <[email protected]>
14
 * @author Kai Nissen < [email protected] >
15
 */
16
class TemplateTestCampaignTest extends \PHPUnit\Framework\TestCase {
17
18
	public function testConstructorSetsFields(): void {
19
		$campaign = new TemplateTestCampaign( [
20
			'code' => 'FOO',
21
			'active' => true,
22
			'startDate' => '2015-11-01 08:00:00',
23
			'endDate' => '2015-11-08 08:00:00',
24
			'templates' => [
25
				'bar',
26
				'baz'
27
			]
28
		] );
29
30
		$this->assertSame( 'FOO', $campaign->getCode() );
31
		$this->assertTrue( $campaign->isActive() );
32
		$this->assertSame( '2015-11-01 08:00:00', $campaign->getStartTimestamp()->format( 'Y-m-d H:i:s' ) );
33
		$this->assertSame( '2015-11-08 08:00:00', $campaign->getEndTimestamp()->format( 'Y-m-d H:i:s' ) );
34
		$this->assertSame( [ 'bar', 'baz' ], $campaign->getTemplates() );
35
	}
36
37
	private function newCampaign( array $campaignData ): TemplateTestCampaign {
38
		$campaignTemplate = [
39
			'code' => 'FOO',
40
			'active' => true,
41
			'startDate' => '2015-11-01 08:00:00',
42
			'endDate' => '2015-11-08 08:00:00',
43
			'templates' => [
44
				'bar',
45
				'baz'
46
			]
47
		];
48
		return new TemplateTestCampaign( array_merge( $campaignTemplate, $campaignData ) );
49
	}
50
51
	public function testHasStarted(): void {
52
		$startedCampaign = $this->newCampaign( [
53
			'startDate' => '2015-01-01 08:00:00',
54
			'endDate' => '2115-01-01 08:00:00',
55
		] );
56
		$notStartedCampaign = $this->newCampaign( [
57
			'startDate' => '2115-01-01 08:00:00',
58
			'endDate' => '2115-08-01 08:00:00',
59
		] );
60
		$this->assertTrue( $startedCampaign->hasStarted() );
61
		$this->assertFalse( $notStartedCampaign->hasStarted() );
62
63
	}
64
65
	public function testHasEnded(): void {
66
		$finishedCampaign = $this->newCampaign( [
67
			'startDate' => '2015-01-01 08:00:00',
68
			'endDate' => '2015-09-01 08:00:00',
69
		] );
70
		$notFinishedCampaign = $this->newCampaign( [
71
			'startDate' => '2015-01-01 08:00:00',
72
			'endDate' => '2115-01-01 08:00:00',
73
		] );
74
		$this->assertTrue( $finishedCampaign->hasEnded() );
75
		$this->assertFalse( $notFinishedCampaign->hasEnded() );
76
	}
77
78
	/**
79
	 * @dataProvider isRunningDataProvider
80
	 */
81
	public function testIsRunning( bool $expected, array $data ): void {
82
		$campaign = $this->newCampaign( $data );
83
		$this->assertSame( $expected, $campaign->isRunning() );
84
	}
85
86
	public function isRunningDataProvider(): array {
87
		return [
88
			[
89
				true,
90
				[
91
					'active' => true,
92
					'startDate' => '2015-01-01 08:00:00',
93
					'endDate' => '2115-01-01 08:00:00',
94
				]
95
			],
96
			[
97
				false,
98
				[
99
					'active' => true,
100
					'startDate' => '2115-01-01 08:00:00',
101
					'endDate' => '2115-08-01 08:00:00',
102
				]
103
			],
104
			[
105
				false,
106
				[
107
					'active' => true,
108
					'startDate' => '2005-01-01 08:00:00',
109
					'endDate' => '2005-08-01 08:00:00',
110
				]
111
			],
112
			[
113
				false,
114
				[
115
					'active' => false,
116
					'startDate' => '2015-01-01 08:00:00',
117
					'endDate' => '2115-01-01 08:00:00',
118
				]
119
			],
120
		];
121
	}
122
123
}
124