77 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
88 * @link https://sitekit.withgoogle.com
99 */
10- // phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760
11-
12-
1310namespace Google \Site_Kit \Tests \Core \Consent_Mode ;
1411
1512use Google \Site_Kit \Context ;
@@ -88,8 +85,8 @@ public function test_register() {
8885
8986 $ this ->controller ->register ();
9087
91- $ this ->assertTrue ( has_filter ( 'googlesitekit_rest_routes ' ) );
92- $ this ->assertTrue ( has_filter ( 'googlesitekit_apifetch_preload_paths ' ) );
88+ $ this ->assertTrue ( has_filter ( 'googlesitekit_rest_routes ' ), ' Consent mode REST routes should be registered. ' );
89+ $ this ->assertTrue ( has_filter ( 'googlesitekit_apifetch_preload_paths ' ), ' Consent mode preload paths should be registered. ' );
9390 }
9491
9592 public function test_get_settings () {
@@ -108,7 +105,7 @@ public function test_get_settings() {
108105 $ request = new WP_REST_Request ( 'GET ' , '/ ' . REST_Routes::REST_ROOT . '/core/site/data/consent-mode ' );
109106 $ response = rest_get_server ()->dispatch ( $ request );
110107
111- $ this ->assertEqualSetsWithIndex ( $ original_settings , $ response ->get_data () );
108+ $ this ->assertEqualSetsWithIndex ( $ original_settings , $ response ->get_data (), ' Consent mode response should contain stored settings. ' );
112109 }
113110
114111 public function test_get_settings__requires_authenticated_admin () {
@@ -127,7 +124,7 @@ public function test_get_settings__requires_authenticated_admin() {
127124
128125 // This admin hasn't authenticated with the Site Kit proxy service yet,
129126 // so they aren't allowed to modify Dashboard Sharing settings.
130- $ this ->assertEquals ( 'rest_forbidden ' , $ response ->get_data ()['code ' ] );
127+ $ this ->assertEquals ( 'rest_forbidden ' , $ response ->get_data ()['code ' ], ' Settings response should forbid unauthenticated admins. ' );
131128 }
132129
133130 public function test_set_settings () {
@@ -158,7 +155,7 @@ public function test_set_settings() {
158155 );
159156
160157 $ response = rest_get_server ()->dispatch ( $ request );
161- $ this ->assertEqualSetsWithIndex ( $ changed_settings , $ response ->get_data () );
158+ $ this ->assertEqualSetsWithIndex ( $ changed_settings , $ response ->get_data (), ' Consent mode response should contain changed settings. ' );
162159 }
163160
164161 public function test_set_settings__requires_authenticated_admin () {
@@ -189,7 +186,7 @@ public function test_set_settings__requires_authenticated_admin() {
189186 $ response = rest_get_server ()->dispatch ( $ request );
190187 // This admin hasn't authenticated with the Site Kit proxy service yet,
191188 // so they aren't allowed to modify Dashboard Sharing settings.
192- $ this ->assertEquals ( 'rest_forbidden ' , $ response ->get_data ()['code ' ] );
189+ $ this ->assertEquals ( 'rest_forbidden ' , $ response ->get_data ()['code ' ], ' Settings update should forbid unauthenticated admins. ' );
193190 }
194191
195192 /**
@@ -208,8 +205,8 @@ public function test_set_settings__wrong_data( $settings ) {
208205 );
209206
210207 $ response = rest_get_server ()->dispatch ( $ request );
211- $ this ->assertEquals ( 400 , $ response ->get_status () );
212- $ this ->assertEquals ( 'rest_invalid_param ' , $ response ->get_data ()['code ' ] );
208+ $ this ->assertEquals ( 400 , $ response ->get_status (), ' Invalid settings response should use bad request status. ' );
209+ $ this ->assertEquals ( 'rest_invalid_param ' , $ response ->get_data ()['code ' ], ' Invalid settings response should include invalid param code. ' );
213210 }
214211
215212 public function provider_wrong_settings_data () {
@@ -246,17 +243,17 @@ public function test_get_api_info() {
246243
247244 $ response_data = $ response ->get_data ();
248245
249- $ this ->assertFalse ( $ response_data ['hasConsentAPI ' ] );
250- $ this ->assertIsArray ( $ response_data ['wpConsentPlugin ' ] );
246+ $ this ->assertFalse ( $ response_data ['hasConsentAPI ' ], ' Consent API info should report no consent API. ' );
247+ $ this ->assertIsArray ( $ response_data ['wpConsentPlugin ' ], ' Consent API info should include WP Consent plugin data. ' );
251248
252249 $ wp_consent_plugin = $ response_data ['wpConsentPlugin ' ];
253250
254251 // Plugin not installed (see mock_installed_plugins)
255- $ this ->assertFalse ( $ wp_consent_plugin ['installed ' ] );
252+ $ this ->assertFalse ( $ wp_consent_plugin ['installed ' ], ' WP Consent plugin should not be installed. ' );
256253 // Plugin is not installed, hence cannot be activated.
257- $ this ->assertFalse ( $ wp_consent_plugin ['activateURL ' ] );
254+ $ this ->assertFalse ( $ wp_consent_plugin ['activateURL ' ], ' WP Consent plugin should not have an activate URL. ' );
258255
259- $ this ->assertStringStartsWith ( 'http://example.org/wp-admin/update.php?action=install-plugin&plugin=wp-consent-api&_wpnonce= ' , $ wp_consent_plugin ['installURL ' ] );
256+ $ this ->assertStringStartsWith ( 'http://example.org/wp-admin/update.php?action=install-plugin&plugin=wp-consent-api&_wpnonce= ' , $ wp_consent_plugin ['installURL ' ], ' WP Consent plugin should include an install URL. ' );
260257 }
261258
262259 /**
@@ -276,16 +273,16 @@ public function test_get_api_info__multisite() {
276273
277274 $ response_data = $ response ->get_data ();
278275
279- $ this ->assertFalse ( $ response_data ['hasConsentAPI ' ] );
280- $ this ->assertIsArray ( $ response_data ['wpConsentPlugin ' ] );
276+ $ this ->assertFalse ( $ response_data ['hasConsentAPI ' ], ' Multisite consent API info should report no consent API. ' );
277+ $ this ->assertIsArray ( $ response_data ['wpConsentPlugin ' ], ' Multisite response should include WP Consent plugin data. ' );
281278
282279 $ wp_consent_plugin = $ response_data ['wpConsentPlugin ' ];
283280
284- $ this ->assertFalse ( $ wp_consent_plugin ['installed ' ] );
281+ $ this ->assertFalse ( $ wp_consent_plugin ['installed ' ], ' WP Consent plugin should not be installed on multisite. ' );
285282
286283 // We don't expect the ability to install or activate plugins on multisite.
287- $ this ->assertFalse ( $ wp_consent_plugin ['activateURL ' ] );
288- $ this ->assertFalse ( $ wp_consent_plugin ['installURL ' ] );
284+ $ this ->assertFalse ( $ wp_consent_plugin ['activateURL ' ], ' WP Consent plugin should not have a multisite activate URL. ' );
285+ $ this ->assertFalse ( $ wp_consent_plugin ['installURL ' ], ' WP Consent plugin should not have a multisite install URL. ' );
289286 }
290287
291288 public function test_get_api_info__requires_authenticated_admin () {
@@ -296,7 +293,7 @@ public function test_get_api_info__requires_authenticated_admin() {
296293
297294 // This admin hasn't authenticated with the Site Kit proxy service yet,
298295 // so they aren't allowed to modify Dashboard Sharing settings.
299- $ this ->assertEquals ( 'rest_forbidden ' , $ response ->get_data ()['code ' ] );
296+ $ this ->assertEquals ( 'rest_forbidden ' , $ response ->get_data ()['code ' ], ' Consent API info should forbid unauthenticated admins. ' );
300297 }
301298
302299 public function test_get_ads_measurement_status () {
@@ -309,7 +306,7 @@ public function test_get_ads_measurement_status() {
309306
310307 $ response_data = $ response ->get_data ();
311308
312- $ this ->assertFalse ( $ response_data ['connected ' ] );
309+ $ this ->assertFalse ( $ response_data ['connected ' ], ' Ads measurement status should default to disconnected. ' );
313310 }
314311
315312 private function grant_manage_options_permission () {
@@ -341,7 +338,7 @@ public function test_get_ads_measurement_status__requires_authenticated_admin()
341338 $ request = new WP_REST_Request ( 'GET ' , '/ ' . REST_Routes::REST_ROOT . '/core/site/data/ads-measurement-status ' );
342339 $ response = rest_get_server ()->dispatch ( $ request );
343340
344- $ this ->assertEquals ( 'rest_forbidden ' , $ response ->get_data ()['code ' ] );
341+ $ this ->assertEquals ( 'rest_forbidden ' , $ response ->get_data ()['code ' ], ' Ads measurement status should forbid unauthenticated admins. ' );
345342 }
346343
347344 public function test_get_ads_measurement_status__early_return_on_first_passing_check () {
@@ -380,10 +377,10 @@ function () use ( &$check_calls ) {
380377
381378 $ response_data = $ response ->get_data ();
382379
383- $ this ->assertTrue ( $ response_data ['connected ' ] );
384- $ this ->assertEquals ( 1 , $ check_calls ['first ' ] );
385- $ this ->assertEquals ( 1 , $ check_calls ['second ' ] );
386- $ this ->assertEquals ( 0 , $ check_calls ['third ' ] );
380+ $ this ->assertTrue ( $ response_data ['connected ' ], ' Ads measurement status should be connected after passing check. ' );
381+ $ this ->assertEquals ( 1 , $ check_calls ['first ' ], ' First ads measurement check should run once. ' );
382+ $ this ->assertEquals ( 1 , $ check_calls ['second ' ], ' Second ads measurement check should run once. ' );
383+ $ this ->assertEquals ( 0 , $ check_calls ['third ' ], ' Third ads measurement check should not run. ' );
387384 }
388385
389386 public function test_get_ads_measurement_status__handles_empty_checks_array () {
@@ -398,7 +395,7 @@ public function test_get_ads_measurement_status__handles_empty_checks_array() {
398395
399396 $ response_data = $ response ->get_data ();
400397
401- $ this ->assertFalse ( $ response_data ['connected ' ] );
398+ $ this ->assertFalse ( $ response_data ['connected ' ], ' Ads measurement status should be disconnected with no checks. ' );
402399 }
403400
404401 public function data_non_callable_checks_provider () {
@@ -429,7 +426,7 @@ function () use ( $non_callable_check ) {
429426
430427 $ response_data = $ response ->get_data ();
431428
432- $ this ->assertFalse ( $ response_data ['connected ' ] );
429+ $ this ->assertFalse ( $ response_data ['connected ' ], ' Ads measurement status should ignore non-callable checks. ' );
433430 }
434431
435432 public function data_non_array_filter_result_provider () {
@@ -460,6 +457,6 @@ function () use ( $non_array_value ) {
460457
461458 $ response_data = $ response ->get_data ();
462459
463- $ this ->assertFalse ( $ response_data ['connected ' ] );
460+ $ this ->assertFalse ( $ response_data ['connected ' ], ' Ads measurement status should ignore non-array checks. ' );
464461 }
465462}
0 commit comments