Changeset 38732
- Timestamp:
- 10/05/2016 05:17:02 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user/capabilities.php
r38731 r38732 684 684 685 685 // shouldn't have any other caps 686 $this->assertFalse($user->has_cap('upload_files')); 687 $this->assertFalse($user->has_cap('edit_published_posts')); 688 $this->assertFalse($user->has_cap('upload_files')); 689 $this->assertFalse($user->has_cap('level_4')); 686 $caps = $this->getAllCapsAndRoles(); 687 foreach ( $caps as $cap => $roles ) { 688 if ( 'level_1' !== $cap ) { 689 $this->assertFalse( $user->has_cap( $cap ), "User should not have the {$cap} capability" ); 690 } 691 } 690 692 691 693 // clean up … … 758 760 759 761 // make sure the other caps didn't get messed up 760 $this->assertTrue($user_1->has_cap('edit_posts')); 761 $this->assertTrue($user_1->has_cap('read')); 762 $this->assertTrue($user_1->has_cap('level_1')); 763 $this->assertTrue($user_1->has_cap('level_0')); 764 $this->assertFalse($user_1->has_cap('upload_files')); 765 $this->assertFalse($user_1->has_cap('edit_published_posts')); 766 $this->assertFalse($user_1->has_cap('level_2')); 762 $caps = $this->getAllCapsAndRoles(); 763 foreach ( $caps as $cap => $roles ) { 764 if ( in_array( 'contributor', $roles, true ) || 'publish_posts' === $cap ) { 765 $this->assertTrue( $user_1->has_cap( $cap ), "User should have the {$cap} capability" ); 766 } else { 767 $this->assertFalse( $user_1->has_cap( $cap ), "User should not have the {$cap} capability" ); 768 } 769 } 767 770 768 771 } … … 848 851 $this->assertTrue($user->exists(), "Problem getting user $id"); 849 852 850 // capabilities for the author role should be gone 851 # $this->assertFalse($user->has_cap('edit_posts')); 852 # $this->assertFalse($user->has_cap('edit_published_posts')); 853 # $this->assertFalse($user->has_cap('upload_files')); 854 # $this->assertFalse($user->has_cap('level_2')); 853 // all capabilities for the user should be gone 854 foreach ( $this->getAllCapsAndRoles() as $cap => $roles ) { 855 $this->assertFalse( $user->has_cap( $cap ), "User should not have the {$cap} capability" ); 856 } 855 857 856 858 // the extra capabilities should be gone … … 960 962 $contributor = self::$users['contributor']; 961 963 962 // editor can edit, view, and trash 964 // editor can publish, edit, view, and trash 965 $this->assertTrue( $editor->has_cap( 'publish_post', $post ) ); 963 966 $this->assertTrue( $editor->has_cap( 'edit_post', $post ) ); 964 967 $this->assertTrue( $editor->has_cap( 'delete_post', $post ) ); … … 966 969 967 970 // a contributor cannot (except read a published post) 971 $this->assertFalse( $contributor->has_cap( 'publish_post', $post ) ); 968 972 $this->assertFalse( $contributor->has_cap( 'edit_post', $post ) ); 969 973 $this->assertFalse( $contributor->has_cap( 'delete_post', $post ) ); … … 979 983 $editor = self::$users['editor']; 980 984 $contributor = self::$users['contributor']; 985 $subscriber = self::$users['subscriber']; 981 986 982 987 // create_posts isn't a real cap. … … 985 990 $this->assertFalse($editor->has_cap('create_posts')); 986 991 $this->assertFalse($contributor->has_cap('create_posts')); 992 $this->assertFalse($subscriber->has_cap('create_posts')); 987 993 988 994 register_post_type( 'foobar' ); … … 995 1001 $this->assertTrue($editor->has_cap( $cap->create_posts )); 996 1002 $this->assertTrue($contributor->has_cap( $cap->create_posts )); 1003 $this->assertFalse($subscriber->has_cap( $cap->create_posts )); 997 1004 998 1005 _unregister_post_type( 'foobar' ); … … 1008 1015 $this->assertFalse($editor->has_cap( $cap->create_posts )); 1009 1016 $this->assertFalse($contributor->has_cap( $cap->create_posts )); 1017 $this->assertFalse($subscriber->has_cap( $cap->create_posts )); 1010 1018 1011 1019 // Add edit_foobars primitive cap to a user. … … 1016 1024 $this->assertFalse($editor->has_cap( $cap->create_posts )); 1017 1025 $this->assertFalse($contributor->has_cap( $cap->create_posts )); 1026 $this->assertFalse($subscriber->has_cap( $cap->create_posts )); 1018 1027 1019 1028 $admin->remove_cap( 'edit_foobars' ); … … 1029 1038 $this->assertTrue( $contributor->has_cap( $cap->edit_posts ) ); 1030 1039 $this->assertFalse( $contributor->has_cap( $cap->create_posts ) ); 1040 $this->assertFalse( $subscriber->has_cap( $cap->create_posts ) ); 1031 1041 } 1032 1042 … … 1197 1207 function test_negative_caps() { 1198 1208 $author = self::$users['author']; 1209 1199 1210 $author->add_cap( 'foo', false ); 1200 1211 $this->assertTrue ( isset( $author->caps['foo'] ) ); 1212 $this->assertFalse( user_can( $author->ID, 'foo' ) ); 1213 1201 1214 $author->remove_cap( 'foo' ); 1202 1215 $this->assertFalse ( isset( $author->caps['foo'] ) ); 1216 $this->assertFalse( user_can( $author->ID, 'foo' ) ); 1203 1217 } 1204 1218 … … 1364 1378 $user = new WP_User( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); 1365 1379 $user->add_cap( 'manage_network_users' ); 1366 $other_user = new WP_User( self::factory()->user->create( array( 'role' => 'subscriber' ) ) );1380 $other_user = self::$users['subscriber']; 1367 1381 1368 1382 wp_set_current_user( $user->ID ); … … 1466 1480 } 1467 1481 1482 $this->assertFalse( current_user_can( 'do_not_allow' ), "Non-logged-in user should not have the do_not_allow capability" ); 1468 1483 } 1469 1484
Note: See TracChangeset
for help on using the changeset viewer.