1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Test get_modules methods in Jetpack class |
4
|
|
|
* |
5
|
|
|
* @package jetpack |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Test get_modules |
10
|
|
|
*/ |
11
|
|
|
class WP_Test_Get_Modules extends WP_UnitTestCase { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Store all available modules. |
15
|
|
|
* |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
public static $all_modules; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This is an expensive operation so let's make it only once |
22
|
|
|
*/ |
23
|
|
|
public static function setUpBeforeClass() { |
24
|
|
|
self::$all_modules = Jetpack::get_available_modules(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Make sure all our modules are being found. |
29
|
|
|
*/ |
30
|
|
|
public function test_get_available_modules() { |
31
|
|
|
|
32
|
|
|
$expected_modules = array( |
33
|
|
|
'comment-likes', |
34
|
|
|
'comments', |
35
|
|
|
'contact-form', |
36
|
|
|
'copy-post', |
37
|
|
|
'custom-content-types', |
38
|
|
|
'custom-css', |
39
|
|
|
'enhanced-distribution', |
40
|
|
|
'google-analytics', |
41
|
|
|
'gravatar-hovercards', |
42
|
|
|
'infinite-scroll', |
43
|
|
|
'json-api', |
44
|
|
|
'latex', |
45
|
|
|
'lazy-images', |
46
|
|
|
'likes', |
47
|
|
|
'markdown', |
48
|
|
|
'masterbar', |
49
|
|
|
'monitor', |
50
|
|
|
'notes', |
51
|
|
|
'photon-cdn', |
52
|
|
|
'photon', |
53
|
|
|
'post-by-email', |
54
|
|
|
'protect', |
55
|
|
|
'publicize', |
56
|
|
|
'related-posts', |
57
|
|
|
'search', |
58
|
|
|
'seo-tools', |
59
|
|
|
'sharedaddy', |
60
|
|
|
'shortcodes', |
61
|
|
|
'shortlinks', |
62
|
|
|
'sitemaps', |
63
|
|
|
'sso', |
64
|
|
|
'stats', |
65
|
|
|
'subscriptions', |
66
|
|
|
'tiled-gallery', |
67
|
|
|
'vaultpress', |
68
|
|
|
'verification-tools', |
69
|
|
|
'videopress', |
70
|
|
|
'widget-visibility', |
71
|
|
|
'widgets', |
72
|
|
|
'woocommerce-analytics', |
73
|
|
|
'wordads', |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$this->assertSame( asort( $expected_modules ), asort( self::$all_modules ) ); |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Test |
82
|
|
|
* |
83
|
|
|
* @dataProvider get_test_connection_filters_data |
84
|
|
|
* @param null|bool $value_requires_connection Value to be used in the requires_connection filter. |
85
|
|
|
* @param null|bool $value_requires_user_connection Value to be used in the requires_user_connection filter. |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
|
|
public function test_filter_by_require_connection( $value_requires_connection, $value_requires_user_connection ) { |
89
|
|
|
$modules = Jetpack::get_available_modules( false, false, $value_requires_connection, $value_requires_user_connection ); |
90
|
|
|
$found = array(); |
91
|
|
|
foreach ( $modules as $module ) { |
92
|
|
|
$found[] = $module; |
93
|
|
|
$details = Jetpack::get_module( $module ); |
94
|
|
|
if ( is_bool( $value_requires_connection ) ) { |
95
|
|
|
$this->assertSame( $value_requires_connection, $details['requires_connection'] ); |
96
|
|
|
} |
97
|
|
|
if ( is_bool( $value_requires_user_connection ) ) { |
98
|
|
|
$this->assertSame( $value_requires_user_connection, $details['requires_user_connection'] ); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
// Make sure no one was left behind. |
103
|
|
|
$max_matches = 0; |
104
|
|
|
if ( is_bool( $value_requires_connection ) ) { |
105
|
|
|
$max_matches++; |
106
|
|
|
} |
107
|
|
|
if ( is_bool( $value_requires_user_connection ) ) { |
108
|
|
|
$max_matches++; |
109
|
|
|
} |
110
|
|
|
foreach ( self::$all_modules as $module ) { |
111
|
|
|
if ( in_array( $module, $found, true ) ) { |
112
|
|
|
continue; |
113
|
|
|
} |
114
|
|
|
$matches = 0; |
115
|
|
|
$details = Jetpack::get_module( $module ); |
116
|
|
|
if ( is_bool( $value_requires_connection ) && $details['requires_connection'] === $value_requires_connection ) { |
117
|
|
|
$matches++; |
118
|
|
|
} |
119
|
|
|
if ( is_bool( $value_requires_user_connection ) && $details['requires_user_connection'] === $value_requires_user_connection ) { |
120
|
|
|
$matches++; |
121
|
|
|
} |
122
|
|
|
$this->assertGreaterThan( $matches, $max_matches, $module . ' module should be returned by get_available_modules but was not.' ); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Send all the possible combinations to test_filter_by_require_connection |
128
|
|
|
* |
129
|
|
|
* @return array |
130
|
|
|
*/ |
131
|
|
|
public function get_test_connection_filters_data() { |
132
|
|
|
return array( |
133
|
|
|
array( |
134
|
|
|
true, |
135
|
|
|
true, |
136
|
|
|
), |
137
|
|
|
array( |
138
|
|
|
true, |
139
|
|
|
false, |
140
|
|
|
), |
141
|
|
|
array( |
142
|
|
|
false, |
143
|
|
|
true, |
144
|
|
|
), |
145
|
|
|
array( |
146
|
|
|
false, |
147
|
|
|
false, |
148
|
|
|
), |
149
|
|
|
array( |
150
|
|
|
null, |
151
|
|
|
true, |
152
|
|
|
), |
153
|
|
|
array( |
154
|
|
|
null, |
155
|
|
|
false, |
156
|
|
|
), |
157
|
|
|
array( |
158
|
|
|
false, |
159
|
|
|
null, |
160
|
|
|
), |
161
|
|
|
array( |
162
|
|
|
true, |
163
|
|
|
null, |
164
|
|
|
), |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
} |
169
|
|
|
|