Completed
Push — master ( 996d66...c95bf7 )
by Jeroen De
58:45
created

TrackingDataSelectorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetPreferredValueReturnsFirstSetElementOrEmptyString() 0 4 1
A preferredValueProvider() 0 8 1
A testConcatTrackingFromVarCouple() 0 9 1
A trackingVarProvider() 0 8 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\DonationContext\Tests\Unit\UseCases\AddDonation;
6
7
use WMDE\Fundraising\Frontend\Infrastructure\TrackingDataSelector;
8
9
/**
10
 * @covers WMDE\Fundraising\Frontend\Infrastructure\TrackingDataSelector
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Kai Nissen < [email protected] >
14
 */
15
class TrackingDataSelectorTest extends \PHPUnit_Framework_TestCase {
16
17
	/**
18
	 * @dataProvider preferredValueProvider
19
	 *
20
	 * @param string $expectedResult
21
	 * @param string[] $values
22
	 */
23
	public function testGetPreferredValueReturnsFirstSetElementOrEmptyString( $expectedResult, $values ) {
24
		$value = TrackingDataSelector::getFirstNonEmptyValue( $values );
25
		$this->assertSame( $expectedResult, $value );
26
	}
27
28
	public function preferredValueProvider() {
29
		return [
30
			[ 'chocolate', [ 'chocolate', 'hazelnuts', 'campaign/keyword' ] ],
31
			[ 'hazelnuts', [ '', 'hazelnuts', 'campaign/keyword' ] ],
32
			[ 'campaign/keyword', [ '', '', 'campaign/keyword' ] ],
33
			[ '', [ '', '', '' ] ],
34
		];
35
	}
36
37
	/**
38
	 * @dataProvider trackingVarProvider
39
	 *
40
	 * @param $expectedResult
41
	 * @param $campaign
42
	 * @param $keyword
43
	 */
44
	public function testConcatTrackingFromVarCouple( $expectedResult, $campaign, $keyword ) {
45
		$value = TrackingDataSelector::getFirstNonEmptyValue( [
46
			'',
47
			'',
48
			TrackingDataSelector::concatTrackingFromVarTuple( $campaign, $keyword )
49
		] );
50
51
		$this->assertSame( $expectedResult, $value );
52
	}
53
54
	public function trackingVarProvider() {
55
		return [
56
			[ 'campaign/keyword', 'campaign', 'keyword' ],
57
			[ 'campaign/keyword', 'Campaign', 'Keyword' ],
58
			[ 'campaign', 'campaign', '' ],
59
			[ '', '', 'keyword' ],
60
		];
61
	}
62
63
}
64