| | 497 | /** |
| | 498 | * @ticket 41059 |
| | 499 | */ |
| | 500 | public function test_do_not_allow_is_denied_for_all_roles() { |
| | 501 | foreach ( self::$users as $role => $user ) { |
| | 502 | |
| | 503 | # Test adding the cap directly to the user |
| | 504 | $user->add_cap( 'do_not_allow' ); |
| | 505 | $has_cap = $user->has_cap( 'do_not_allow' ); |
| | 506 | $user->remove_cap( 'do_not_allow' ); |
| | 507 | $this->assertFalse( $has_cap, "User with the {$role} role should not have the do_not_allow capability" ); |
| | 508 | |
| | 509 | # Test adding the cap to the user's role |
| | 510 | $role_obj = get_role( $role ); |
| | 511 | $role_obj->add_cap( 'do_not_allow' ); |
| | 512 | $has_cap = $user->has_cap( 'do_not_allow' ); |
| | 513 | $role_obj->remove_cap( 'do_not_allow' ); |
| | 514 | $this->assertFalse( $has_cap, "User with the {$role} role should not have the do_not_allow capability" ); |
| | 515 | |
| | 516 | # Test adding the cap via a filter |
| | 517 | add_filter( 'user_has_cap', array( $this, 'grant_do_not_allow' ), 10, 4 ); |
| | 518 | $has_cap = $user->has_cap( 'do_not_allow' ); |
| | 519 | remove_filter( 'user_has_cap', array( $this, 'grant_do_not_allow' ), 10, 4 ); |
| | 520 | $this->assertFalse( $has_cap, "User with the {$role} role should not have the do_not_allow capability" ); |
| | 521 | |
| | 522 | } |
| | 523 | } |
| | 524 | |
| | 525 | /** |
| | 526 | * @group ms-required |
| | 527 | * @ticket 41059 |
| | 528 | */ |
| | 529 | public function test_do_not_allow_is_denied_for_super_admins() { |
| | 530 | # Test adding the cap directly to the user |
| | 531 | self::$super_admin->add_cap( 'do_not_allow' ); |
| | 532 | $has_cap = self::$super_admin->has_cap( 'do_not_allow' ); |
| | 533 | self::$super_admin->remove_cap( 'do_not_allow' ); |
| | 534 | $this->assertFalse( $has_cap, 'Super admins should not have the do_not_allow capability' ); |
| | 535 | |
| | 536 | # Test adding the cap via a filter |
| | 537 | add_filter( 'user_has_cap', array( $this, 'grant_do_not_allow' ), 10, 4 ); |
| | 538 | $has_cap = self::$super_admin->has_cap( 'do_not_allow' ); |
| | 539 | remove_filter( 'user_has_cap', array( $this, 'grant_do_not_allow' ), 10, 4 ); |
| | 540 | $this->assertFalse( $has_cap, 'Super admins should not have the do_not_allow capability' ); |
| | 541 | } |
| | 542 | |
| | 543 | public function grant_do_not_allow( $allcaps, $caps, $args, $user ) { |
| | 544 | $allcaps['do_not_allow'] = true; |
| | 545 | return $allcaps; |
| | 546 | } |
| | 547 | |