1
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
2
|
|
|
/** |
3
|
|
|
* Tests for Automattic\Jetpack\Tracking methods |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-tracking |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack; |
9
|
|
|
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Tracking test suite. |
14
|
|
|
*/ |
15
|
|
|
class Test_Tracking extends TestCase { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Test setup. |
19
|
|
|
*/ |
20
|
|
|
public function setUp() { |
21
|
|
|
$this->connection = $this->getMockBuilder( 'Automattic\Jetpack\Connection\Manager' ) |
22
|
|
|
->setMethods( array( 'is_user_connected' ) ) |
23
|
|
|
->getMock(); |
24
|
|
|
$this->tracking = new Tracking( 'jetpack', $this->connection ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Tests the Automattic\Jetpack\Tracking::should_enabled_tracking() method. |
29
|
|
|
* |
30
|
|
|
* @param array $inputs The test input values. |
31
|
|
|
* @param boolean $expected_output The expected output of Automattic\Jetpack\Tracking::should_enabled_tracking(). |
32
|
|
|
* |
33
|
|
|
* @covers Automattic\Jetpack\Tracking::should_enabled_tracking |
34
|
|
|
* @dataProvider data_provider_test_should_enable_tracking |
35
|
|
|
*/ |
36
|
|
|
public function test_should_enable_tracking( $inputs, $expected_output ) { |
37
|
|
|
$tos = $this->getMockBuilder( 'Automattic\Jetpack\Terms_Of_Service' ) |
38
|
|
|
->setMethods( array( 'has_agreed' ) ) |
39
|
|
|
->getMock(); |
40
|
|
|
|
41
|
|
|
$tos->method( 'has_agreed' ) |
42
|
|
|
->will( $this->returnValue( $inputs['has_agreed'] ) ); |
43
|
|
|
|
44
|
|
|
$status = $this->getMockBuilder( 'Automattic\Jetpack\Status' ) |
45
|
|
|
->setMethods( array( 'is_offline_mode' ) ) |
46
|
|
|
->getMock(); |
47
|
|
|
|
48
|
|
|
$status->method( 'is_offline_mode' ) |
49
|
|
|
->will( $this->returnValue( $inputs['offline'] ) ); |
50
|
|
|
|
51
|
|
|
$this->connection->method( 'is_user_connected' ) |
52
|
|
|
->will( $this->returnValue( $inputs['connected'] ) ); |
53
|
|
|
|
54
|
|
|
$this->assertEquals( $expected_output, $this->tracking->should_enable_tracking( $tos, $status ) ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Data provider for test_should_enable_tracking. |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function data_provider_test_should_enable_tracking() { |
63
|
|
|
return array( |
64
|
|
|
'offline: true, has agreed: true, connected: true' => array( |
65
|
|
|
array( |
66
|
|
|
'offline' => true, |
67
|
|
|
'has_agreed' => true, |
68
|
|
|
'connected' => true, |
69
|
|
|
), |
70
|
|
|
false, |
71
|
|
|
), |
72
|
|
|
'offline: false, has agreed: true, connected: true' => array( |
73
|
|
|
array( |
74
|
|
|
'offline' => false, |
75
|
|
|
'has_agreed' => true, |
76
|
|
|
'connected' => true, |
77
|
|
|
), |
78
|
|
|
true, |
79
|
|
|
), |
80
|
|
|
'offline: false, has agreed: true, connected: false' => array( |
81
|
|
|
array( |
82
|
|
|
'offline' => false, |
83
|
|
|
'has_agreed' => true, |
84
|
|
|
'connected' => false, |
85
|
|
|
), |
86
|
|
|
true, |
87
|
|
|
), |
88
|
|
|
'offline: false, has agreed: false, connected: true' => array( |
89
|
|
|
array( |
90
|
|
|
'offline' => false, |
91
|
|
|
'has_agreed' => false, |
92
|
|
|
'connected' => true, |
93
|
|
|
), |
94
|
|
|
true, |
95
|
|
|
), |
96
|
|
|
'offline: false, has agreed: false, connected: false' => array( |
97
|
|
|
array( |
98
|
|
|
'offline' => false, |
99
|
|
|
'has_agreed' => false, |
100
|
|
|
'connected' => false, |
101
|
|
|
), |
102
|
|
|
false, |
103
|
|
|
), |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|