1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class WP_Test_Jetpack_Sync_Module_Stats extends WP_Test_Jetpack_Sync_Base { |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Test sends stats data on heartbeat |
7
|
|
|
* |
8
|
|
|
* @expectedDeprecated Jetpack_Heartbeat::cron_exec |
9
|
|
|
* @return void |
10
|
|
|
*/ |
11
|
|
View Code Duplication |
public function test_sends_stats_data_on_heartbeat() { |
12
|
|
|
$this->make_site_active(); |
13
|
|
|
|
14
|
|
|
$heartbeat = Jetpack_Heartbeat::init(); |
15
|
|
|
add_filter( 'jetpack_heartbeat_stats_array', array( $heartbeat, 'add_stats_to_heartbeat' ) ); |
16
|
|
|
|
17
|
|
|
add_filter( 'pre_http_request', array( $this, 'pre_http_request_success' ) ); |
18
|
|
|
$heartbeat->cron_exec(); |
|
|
|
|
19
|
|
|
remove_filter( 'pre_http_request', array( $this, 'pre_http_request_success' ) ); |
20
|
|
|
|
21
|
|
|
$this->sender->do_sync(); |
22
|
|
|
|
23
|
|
|
$action = $this->server_event_storage->get_most_recent_event( 'jetpack_sync_heartbeat_stats' ); |
24
|
|
|
|
25
|
|
|
$this->delete_connection_options(); |
26
|
|
|
|
27
|
|
|
$this->assertEquals( JETPACK__VERSION, $action->args[0]['version'] ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Test dont send expensive data on heartbeat |
32
|
|
|
* |
33
|
|
|
* @expectedDeprecated Jetpack_Heartbeat::cron_exec |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function test_dont_send_expensive_data_on_heartbeat() { |
37
|
|
|
$this->make_site_active(); |
38
|
|
|
|
39
|
|
|
$heartbeat = Jetpack_Heartbeat::init(); |
40
|
|
|
add_filter( 'jetpack_heartbeat_stats_array', array( $heartbeat, 'add_stats_to_heartbeat' ) ); |
41
|
|
|
|
42
|
|
|
add_filter( 'pre_http_request', array( $this, 'pre_http_request_success' ) ); |
43
|
|
|
$heartbeat->cron_exec(); |
|
|
|
|
44
|
|
|
remove_filter( 'pre_http_request', array( $this, 'pre_http_request_success' ) ); |
45
|
|
|
$this->sender->do_sync(); |
46
|
|
|
|
47
|
|
|
$action = $this->server_event_storage->get_most_recent_event( 'jetpack_sync_heartbeat_stats' ); |
48
|
|
|
|
49
|
|
|
$this->delete_connection_options(); |
50
|
|
|
|
51
|
|
|
$this->assertFalse( isset( $action->args[0]['users'] ) ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Test sends stats data on heartbeat on multisite |
56
|
|
|
* |
57
|
|
|
* @expectedDeprecated Jetpack_Heartbeat::cron_exec |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function test_sends_stats_data_on_heartbeat_on_multisite() { |
61
|
|
|
global $wpdb; |
62
|
|
|
|
63
|
|
|
if ( ! is_multisite() ) { |
64
|
|
|
$this->markTestSkipped( 'Run it in multi site mode' ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$user_id = $this->factory->user->create(); |
68
|
|
|
$mu_blog_user_id = $this->factory->user->create(); |
69
|
|
|
|
70
|
|
|
// Create a different blog. |
71
|
|
|
$suppress = $wpdb->suppress_errors(); |
72
|
|
|
$other_blog_id = wpmu_create_blog( 'foo.com', '', 'My Blog', $user_id ); |
73
|
|
|
$wpdb->suppress_errors( $suppress ); |
74
|
|
|
|
75
|
|
|
// Create a user from within that blog (won't be synced). |
76
|
|
|
switch_to_blog( $other_blog_id ); |
77
|
|
|
$this->make_site_active(); |
78
|
|
|
|
79
|
|
|
add_user_to_blog( $other_blog_id, $mu_blog_user_id, 'administrator' ); |
80
|
|
|
|
81
|
|
|
$heartbeat = Jetpack_Heartbeat::init(); |
82
|
|
|
add_filter( 'jetpack_heartbeat_stats_array', array( $heartbeat, 'add_stats_to_heartbeat' ) ); |
83
|
|
|
|
84
|
|
|
add_filter( 'pre_http_request', array( $this, 'pre_http_request_success' ) ); |
85
|
|
|
$heartbeat->cron_exec(); |
|
|
|
|
86
|
|
|
remove_filter( 'pre_http_request', array( $this, 'pre_http_request_success' ) ); |
87
|
|
|
|
88
|
|
|
$this->sender->do_sync(); |
89
|
|
|
|
90
|
|
|
$action = $this->server_event_storage->get_most_recent_event( 'jetpack_sync_heartbeat_stats' ); |
91
|
|
|
|
92
|
|
|
$this->delete_connection_options(); |
93
|
|
|
|
94
|
|
|
restore_current_blog(); |
95
|
|
|
|
96
|
|
|
$this->assertEquals( JETPACK__VERSION, $action->args[0]['version'] ); |
97
|
|
|
$this->assertFalse( isset( $action->args[0]['users'] ) ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Sets the 'master_user' and 'user_tokens' options so the site is considered connected. |
102
|
|
|
*/ |
103
|
|
|
private function make_site_active() { |
104
|
|
|
$user_id = 1; |
105
|
|
|
Jetpack_Options::update_option( 'master_user', $user_id ); |
106
|
|
|
Jetpack_Options::update_option( |
107
|
|
|
'user_tokens', |
108
|
|
|
array( |
109
|
|
|
$user_id => 'apple.a.' . $user_id, |
110
|
|
|
) |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Deletes the 'master_user' and 'user_tokens" options. |
116
|
|
|
*/ |
117
|
|
|
private function delete_connection_options() { |
118
|
|
|
Jetpack_Options::delete_option( 'master_user' ); |
119
|
|
|
Jetpack_Options::delete_option( 'user_tokens' ); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.