Completed
Push — instant-search-master ( 8be3b4...336413 )
by
unknown
06:37 queued 10s
created

Partner_Test   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 3 1
A setUp() 0 5 1
A test_init_returns_instance() 0 3 1
A code_provider() 0 16 1
A test_partner_code_is_set_via_option() 0 4 1
A test_partner_code_is_set_via_filter() 0 5 1
A test_partner_code_is_empty_by_default() 0 4 1
1
<?php
2
3
namespace Automattic\Jetpack;
4
use PHPUnit\Framework\TestCase;
5
6
use Brain\Monkey;
7
use Brain\Monkey\Functions;
8
use Brain\Monkey\Filters;
9
10
class Partner_Test extends TestCase {
11
12
	const TEST_CODE = 'abc-123';
13
14
	public function tearDown() {
15
		parent::tearDown();
16
	}
17
18
	public function setUp() {
19
		parent::setUp();
20
		Monkey\setUp();
21
		Partner::reset();
22
	}
23
24
	public function test_init_returns_instance() {
25
		$this->assertInstanceOf( Partner::class, Partner::init() );
26
	}
27
28
	public function code_provider() {
29
		return array(
30
			'subsidiary_code' =>
31
				array(
32
					Partner::SUBSIDIARY_CODE,            // Code type.
33
					'jetpack_partner_subsidiary_id',     // filter/option key.
34
					'subsidiaryId',                      // Query string parameter.
35
				),
36
			'affiliate_code'  =>
37
				array(
38
					Partner::AFFILIATE_CODE,
39
					'jetpack_affiliate_code',
40
					'aff',
41
				),
42
		);
43
	}
44
45
	/**
46
	 * @dataProvider code_provider
47
	 *
48
	 * @param string $code_type Partner code type.
49
	 * @param string $option_name Option and filter name.
50
	 * @param string $query_string_name Query string variable name.
51
	 *
52
	 * @throws Monkey\Expectation\Exception\ExpectationArgsRequired
53
	 */
54
	public function test_partner_code_is_empty_by_default( $code_type, $option_name, $query_string_name ) {
55
		Functions\expect( 'get_option' )->once()->with( $option_name )->andReturn( '' );
56
		$this->assertEmpty( Partner::init()->get_partner_code( $code_type ) );
57
	}
58
59
	/**
60
	 * @dataProvider code_provider
61
	 *
62
	 * @param string $code_type Partner code type.
63
	 * @param string $option_name Option and filter name.
64
	 * @param string $query_string_name Query string variable name.
65
	 *
66
	 * @throws Monkey\Expectation\Exception\ExpectationArgsRequired
67
	 */
68
	public function test_partner_code_is_set_via_option( $code_type, $option_name, $query_string_name ) {
69
		Functions\expect( 'get_option' )->once()->with( $option_name, '' )->andReturn( self::TEST_CODE );
70
		$this->assertEquals( self::TEST_CODE, Partner::init()->get_partner_code( $code_type ) );
71
	}
72
73
	/**
74
	 * @dataProvider code_provider
75
	 *
76
	 * @param string $code_type Partner code type.
77
	 * @param string $option_name Option and filter name.
78
	 * @param string $query_string_name Query string variable name.
79
	 *
80
	 * @throws Monkey\Expectation\Exception\ExpectationArgsRequired
81
	 */
82
	public function test_partner_code_is_set_via_filter( $code_type, $option_name, $query_string_name ) {
83
		Functions\expect( 'get_option' )->once()->with( $option_name)->andReturn( '' );
84
		Filters\expectApplied( $option_name )->once()->with('')->with( self::TEST_CODE );
85
		$this->assertEquals( self::TEST_CODE, Partner::init()->get_partner_code( $code_type ) );
86
	}
87
}
88