Changeset 49605
- Timestamp:
- 11/15/2020 02:57:39 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user/capabilities.php
r49604 r49605 323 323 'assign_post_tags' => array( 'administrator', 'editor', 'author', 'contributor' ), 324 324 ); 325 } 326 327 public function dataAllCapsAndRoles() { 328 $data = array(); 329 $caps = $this->getAllCapsAndRoles(); 330 331 foreach ( self::$users as $role => $null ) { 332 foreach ( $caps as $cap => $roles ) { 333 $data[] = array( 334 $role, 335 $cap, 336 ); 337 } 338 } 339 340 return $data; 325 341 } 326 342 … … 521 537 522 538 /** 523 * Test the default roles and caps. 524 */ 525 function test_all_roles_and_caps() { 526 $caps = $this->getAllCapsAndRoles(); 527 539 * Test the default capabilities of all user roles. 540 * 541 * @dataProvider dataAllCapsAndRoles 542 */ 543 function test_default_caps_for_all_roles( $role, $cap ) { 544 $user = self::$users[ $role ]; 545 $roles_by_cap = $this->getAllCapsAndRoles(); 546 547 if ( in_array( $role, $roles_by_cap[ $cap ], true ) ) { 548 $this->assertTrue( $user->has_cap( $cap ), "User with the {$role} role should have the {$cap} capability" ); 549 $this->assertTrue( user_can( $user, $cap ), "User with the {$role} role should have the {$cap} capability" ); 550 } else { 551 $this->assertFalse( $user->has_cap( $cap ), "User with the {$role} role should not have the {$cap} capability" ); 552 $this->assertFalse( user_can( $user, $cap ), "User with the {$role} role should not have the {$cap} capability" ); 553 } 554 } 555 556 /** 557 * Test miscellaneous capabilities of all user roles. 558 */ 559 function test_other_caps_for_all_roles() { 528 560 foreach ( self::$users as $role => $user ) { 529 530 561 // Make sure the user is valid. 531 562 $this->assertTrue( $user->exists(), "User with {$role} role does not exist" ); … … 533 564 // Make sure the role name is correct. 534 565 $this->assertSame( array( $role ), $user->roles, "User should only have the {$role} role" ); 535 536 foreach ( $caps as $cap => $roles ) {537 if ( in_array( $role, $roles, true ) ) {538 $this->assertTrue( $user->has_cap( $cap ), "User with the {$role} role should have the {$cap} capability" );539 $this->assertTrue( user_can( $user, $cap ), "User with the {$role} role should have the {$cap} capability" );540 } else {541 $this->assertFalse( $user->has_cap( $cap ), "User with the {$role} role should not have the {$cap} capability" );542 $this->assertFalse( user_can( $user, $cap ), "User with the {$role} role should not have the {$cap} capability" );543 }544 }545 566 546 567 $this->assertFalse( $user->has_cap( 'start_a_fire' ), "User with the {$role} role should not have a custom capability" );
Note: See TracChangeset
for help on using the changeset viewer.