Changeset 64687
- Timestamp:
- 10/23/2026 07:43:15 AM (less than one hour ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/wp-includes/abilities.php (modified) (1 diff)
-
tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/abilities.php
r64500 r64687 359 359 return array_intersect_key( $all, array_flip( $requested_fields ) ); 360 360 }, 361 'required_capabilities' => array( ' manage_options' ),361 'required_capabilities' => array( 'view_site_health_checks' ), 362 362 'meta' => array( 363 363 'annotations' => array( -
trunk/tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php
r64362 r64687 302 302 */ 303 303 public function test_core_get_environment_info_executes(): void { 304 // Requires manage_options.304 // Requires access to Site Health diagnostics. 305 305 $admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 306 wp_set_current_user( $admin_id ); 306 $user = wp_set_current_user( $admin_id ); 307 $user->add_cap( 'view_site_health_checks' ); 307 308 308 309 $ability = wp_get_ability( 'core/get-environment-info' ); … … 319 320 320 321 /** 322 * Tests that managing site options does not grant access to environment information. 323 * 324 * @ticket 66369 325 */ 326 public function test_core_get_environment_info_requires_site_health_access(): void { 327 $user_id = self::factory()->user->create( array( 'role' => 'subscriber' ) ); 328 $user = wp_set_current_user( $user_id ); 329 $user->add_cap( 'manage_options' ); 330 331 $this->assertTrue( current_user_can( 'manage_options' ) ); 332 $this->assertFalse( current_user_can( 'view_site_health_checks' ) ); 333 334 $result = wp_get_ability( 'core/get-environment-info' )->execute(); 335 336 $this->assertWPError( $result ); 337 $this->assertSame( 'ability_invalid_permissions', $result->get_error_code() ); 338 } 339 340 /** 341 * Tests that Site Health access can be delegated without granting site management access. 342 * 343 * @ticket 66369 344 */ 345 public function test_core_get_environment_info_allows_delegated_site_health_access(): void { 346 $user_id = self::factory()->user->create( array( 'role' => 'subscriber' ) ); 347 $user = wp_set_current_user( $user_id ); 348 $user->add_cap( 'view_site_health_checks' ); 349 350 $this->assertFalse( current_user_can( 'manage_options' ) ); 351 352 $result = wp_get_ability( 'core/get-environment-info' )->execute(); 353 354 $this->assertIsArray( $result ); 355 } 356 357 /** 358 * Tests that multisite site administrators cannot access environment information. 359 * 360 * @ticket 66369 361 * @group ms-required 362 */ 363 public function test_core_get_environment_info_denies_multisite_site_administrator(): void { 364 $admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 365 wp_set_current_user( $admin_id ); 366 367 $this->assertFalse( is_super_admin() ); 368 $this->assertTrue( current_user_can( 'manage_options' ) ); 369 $this->assertFalse( current_user_can( 'view_site_health_checks' ) ); 370 371 $result = wp_get_ability( 'core/get-environment-info' )->execute(); 372 373 $this->assertWPError( $result ); 374 $this->assertSame( 'ability_invalid_permissions', $result->get_error_code() ); 375 } 376 377 /** 321 378 * Tests that the `core/get-environment-info` ability is registered with the expected schema. 322 379 * … … 357 414 public function test_core_get_environment_info_filters_fields(): void { 358 415 $admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 359 wp_set_current_user( $admin_id ); 416 $user = wp_set_current_user( $admin_id ); 417 $user->add_cap( 'view_site_health_checks' ); 360 418 361 419 $ability = wp_get_ability( 'core/get-environment-info' ); … … 382 440 public function test_core_get_environment_info_rejects_invalid_fields(): void { 383 441 $admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 384 wp_set_current_user( $admin_id ); 442 $user = wp_set_current_user( $admin_id ); 443 $user->add_cap( 'view_site_health_checks' ); 385 444 386 445 $ability = wp_get_ability( 'core/get-environment-info' );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)