Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (4 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/capabilities.php

    r41635 r42343  
    99class Tests_User_Capabilities extends WP_UnitTestCase {
    1010
    11     protected static $users = array(
     11    protected static $users       = array(
    1212        'administrator' => null,
    1313        'editor'        => null,
     
    1919
    2020    public static function wpSetUpBeforeClass( $factory ) {
    21         self::$users = array(
     21        self::$users       = array(
    2222            'administrator' => $factory->user->create_and_get( array( 'role' => 'administrator' ) ),
    2323            'editor'        => $factory->user->create_and_get( array( 'role' => 'editor' ) ),
     
    4040        // we want to make sure we're testing against the db, not just in-memory data
    4141        // this will flush everything and reload it from the db
    42         unset($GLOBALS['wp_user_roles']);
     42        unset( $GLOBALS['wp_user_roles'] );
    4343        global $wp_roles;
    4444        $wp_roles = new WP_Roles();
     
    490490                }
    491491            }
    492 
    493492        }
    494493
     
    610609    public function test_user_can_edit_comment_on_own_post( $role, $can_edit_own_post ) {
    611610        $owner   = self::$users[ $role ];
    612         $post    = self::factory()->post->create_and_get( array(
    613             'post_author' => $owner->ID,
    614         ) );
    615         $comment = self::factory()->comment->create_and_get( array(
    616             'comment_post_ID' => $post->ID,
    617         ) );
     611        $post    = self::factory()->post->create_and_get(
     612            array(
     613                'post_author' => $owner->ID,
     614            )
     615        );
     616        $comment = self::factory()->comment->create_and_get(
     617            array(
     618                'comment_post_ID' => $post->ID,
     619            )
     620        );
    618621
    619622        $owner_can_edit = user_can( $owner->ID, 'edit_comment', $comment->comment_ID );
     
    629632    public function test_user_can_edit_comment_on_others_post( $role, $can_edit_others_post ) {
    630633        $user    = self::$users[ $role ];
    631         $owner   = self::factory()->user->create_and_get( array(
    632             'role' => 'editor',
    633         ) );
    634         $post    = self::factory()->post->create_and_get( array(
    635             'post_author' => $owner->ID,
    636         ) );
    637         $comment = self::factory()->comment->create_and_get( array(
    638             'comment_post_ID' => $post->ID,
    639         ) );
     634        $owner   = self::factory()->user->create_and_get(
     635            array(
     636                'role' => 'editor',
     637            )
     638        );
     639        $post    = self::factory()->post->create_and_get(
     640            array(
     641                'post_author' => $owner->ID,
     642            )
     643        );
     644        $comment = self::factory()->comment->create_and_get(
     645            array(
     646                'comment_post_ID' => $post->ID,
     647            )
     648        );
    640649
    641650        $user_can_edit = user_can( $user->ID, 'edit_comment', $comment->comment_ID );
     
    644653
    645654    public function data_user_with_role_can_edit_own_post() {
    646         $data  = array();
    647         $caps  = $this->getPrimitiveCapsAndRoles();
     655        $data = array();
     656        $caps = $this->getPrimitiveCapsAndRoles();
    648657
    649658        foreach ( self::$users as $role => $null ) {
     
    658667
    659668    public function data_user_with_role_can_edit_others_posts() {
    660         $data  = array();
    661         $caps  = $this->getPrimitiveCapsAndRoles();
     669        $data = array();
     670        $caps = $this->getPrimitiveCapsAndRoles();
    662671
    663672        foreach ( self::$users as $role => $null ) {
     
    685694        }
    686695
    687         $this->assertTrue( $user->has_cap( 'start_a_fire' ), "Super admins should have all custom capabilities" );
    688         $this->assertTrue( user_can( $user, 'start_a_fire' ), "Super admins should have all custom capabilities" );
     696        $this->assertTrue( $user->has_cap( 'start_a_fire' ), 'Super admins should have all custom capabilities' );
     697        $this->assertTrue( user_can( $user, 'start_a_fire' ), 'Super admins should have all custom capabilities' );
    689698
    690699        $this->assertFalse( $user->has_cap( 'do_not_allow' ), 'Super Admins should not have the do_not_allow capability' );
     
    701710
    702711        // make sure the user is valid
    703         $this->assertTrue( $user->exists(), "User does not exist" );
     712        $this->assertTrue( $user->exists(), 'User does not exist' );
    704713
    705714        // make sure the role name is correct
    706         $this->assertEquals( array(), $user->roles, "User should not have any roles" );
     715        $this->assertEquals( array(), $user->roles, 'User should not have any roles' );
    707716
    708717        $caps = $this->getAllCapsAndRoles();
     
    719728
    720729        // make sure the user is valid
    721         $this->assertTrue( $user->exists(), "User does not exist" );
     730        $this->assertTrue( $user->exists(), 'User does not exist' );
    722731
    723732        $user->add_role( 'contributor' );
     
    757766
    758767        // make sure the user is valid
    759         $this->assertTrue( $user->exists(), "User does not exist" );
     768        $this->assertTrue( $user->exists(), 'User does not exist' );
    760769
    761770        // make sure the role name is correct
     
    779788        global $wp_roles;
    780789
    781         $role_name = 'janitor';
     790        $role_name     = 'janitor';
    782791        $expected_caps = array(
    783792            'edit_posts' => true,
     
    794803
    795804        // make sure the user is valid
    796         $this->assertTrue( $user->exists(), "User does not exist" );
     805        $this->assertTrue( $user->exists(), 'User does not exist' );
    797806
    798807        // make sure the role name is correct
     
    823832        global $wp_roles;
    824833        $role_name = 'janitor';
    825         add_role( $role_name, 'Janitor', array('level_1'=>true) );
     834        add_role( $role_name, 'Janitor', array( 'level_1' => true ) );
    826835        $this->_flush_roles();
    827         $this->assertTrue( $wp_roles->is_role($role_name) );
     836        $this->assertTrue( $wp_roles->is_role( $role_name ) );
    828837
    829838        // assign a user to that role
     
    831840
    832841        // now add a cap to the role
    833         $wp_roles->add_cap($role_name, 'sweep_floor');
     842        $wp_roles->add_cap( $role_name, 'sweep_floor' );
    834843        $this->_flush_roles();
    835844
    836         $user = new WP_User($id);
    837         $this->assertTrue($user->exists(), "Problem getting user $id");
    838         $this->assertEquals(array($role_name), $user->roles);
     845        $user = new WP_User( $id );
     846        $this->assertTrue( $user->exists(), "Problem getting user $id" );
     847        $this->assertEquals( array( $role_name ), $user->roles );
    839848
    840849        // the user should have all the above caps
    841         $this->assertTrue($user->has_cap($role_name));
    842         $this->assertTrue($user->has_cap('level_1'));
    843         $this->assertTrue($user->has_cap('sweep_floor'));
     850        $this->assertTrue( $user->has_cap( $role_name ) );
     851        $this->assertTrue( $user->has_cap( 'level_1' ) );
     852        $this->assertTrue( $user->has_cap( 'sweep_floor' ) );
    844853
    845854        // shouldn't have any other caps
     
    852861
    853862        // clean up
    854         remove_role($role_name);
     863        remove_role( $role_name );
    855864        $this->_flush_roles();
    856         $this->assertFalse($wp_roles->is_role($role_name));
     865        $this->assertFalse( $wp_roles->is_role( $role_name ) );
    857866
    858867    }
     
    863872        global $wp_roles;
    864873        $role_name = 'janitor';
    865         add_role( $role_name, 'Janitor', array('level_1'=>true, 'sweep_floor'=>true, 'polish_doorknobs'=>true) );
     874        add_role(
     875            $role_name, 'Janitor', array(
     876                'level_1'          => true,
     877                'sweep_floor'      => true,
     878                'polish_doorknobs' => true,
     879            )
     880        );
    866881        $this->_flush_roles();
    867         $this->assertTrue( $wp_roles->is_role($role_name) );
     882        $this->assertTrue( $wp_roles->is_role( $role_name ) );
    868883
    869884        // assign a user to that role
     
    871886
    872887        // now remove a cap from the role
    873         $wp_roles->remove_cap($role_name, 'polish_doorknobs');
     888        $wp_roles->remove_cap( $role_name, 'polish_doorknobs' );
    874889        $this->_flush_roles();
    875890
    876         $user = new WP_User($id);
    877         $this->assertTrue($user->exists(), "Problem getting user $id");
    878         $this->assertEquals(array($role_name), $user->roles);
     891        $user = new WP_User( $id );
     892        $this->assertTrue( $user->exists(), "Problem getting user $id" );
     893        $this->assertEquals( array( $role_name ), $user->roles );
    879894
    880895        // the user should have all the above caps
    881         $this->assertTrue($user->has_cap($role_name));
    882         $this->assertTrue($user->has_cap('level_1'));
    883         $this->assertTrue($user->has_cap('sweep_floor'));
     896        $this->assertTrue( $user->has_cap( $role_name ) );
     897        $this->assertTrue( $user->has_cap( 'level_1' ) );
     898        $this->assertTrue( $user->has_cap( 'sweep_floor' ) );
    884899
    885900        // shouldn't have the removed cap
    886         $this->assertFalse($user->has_cap('polish_doorknobs'));
     901        $this->assertFalse( $user->has_cap( 'polish_doorknobs' ) );
    887902
    888903        // clean up
    889         remove_role($role_name);
     904        remove_role( $role_name );
    890905        $this->_flush_roles();
    891         $this->assertFalse($wp_roles->is_role($role_name));
     906        $this->assertFalse( $wp_roles->is_role( $role_name ) );
    892907
    893908    }
     
    901916
    902917        // user 1 has an extra capability
    903         $user_1 = new WP_User($id_1);
    904         $this->assertTrue($user_1->exists(), "Problem getting user $id_1");
    905         $user_1->add_cap('publish_posts');
     918        $user_1 = new WP_User( $id_1 );
     919        $this->assertTrue( $user_1->exists(), "Problem getting user $id_1" );
     920        $user_1->add_cap( 'publish_posts' );
    906921
    907922        // re-fetch both users from the db
    908         $user_1 = new WP_User($id_1);
    909         $this->assertTrue($user_1->exists(), "Problem getting user $id_1");
    910         $user_2 = new WP_User($id_2);
    911         $this->assertTrue($user_2->exists(), "Problem getting user $id_2");
     923        $user_1 = new WP_User( $id_1 );
     924        $this->assertTrue( $user_1->exists(), "Problem getting user $id_1" );
     925        $user_2 = new WP_User( $id_2 );
     926        $this->assertTrue( $user_2->exists(), "Problem getting user $id_2" );
    912927
    913928        // make sure they're both still contributors
    914         $this->assertEquals(array('contributor'), $user_1->roles);
    915         $this->assertEquals(array('contributor'), $user_2->roles);
     929        $this->assertEquals( array( 'contributor' ), $user_1->roles );
     930        $this->assertEquals( array( 'contributor' ), $user_2->roles );
    916931
    917932        // check the extra cap on both users
    918         $this->assertTrue($user_1->has_cap('publish_posts'));
    919         $this->assertFalse($user_2->has_cap('publish_posts'));
     933        $this->assertTrue( $user_1->has_cap( 'publish_posts' ) );
     934        $this->assertFalse( $user_2->has_cap( 'publish_posts' ) );
    920935
    921936        // make sure the other caps didn't get messed up
     
    939954
    940955        // user 1 has an extra capability
    941         $user_1 = new WP_User($id_1);
    942         $this->assertTrue($user_1->exists(), "Problem getting user $id_1");
    943         $user_1->add_cap('publish_posts');
     956        $user_1 = new WP_User( $id_1 );
     957        $this->assertTrue( $user_1->exists(), "Problem getting user $id_1" );
     958        $user_1->add_cap( 'publish_posts' );
    944959
    945960        // now remove the extra cap
    946         $user_1->remove_cap('publish_posts');
     961        $user_1->remove_cap( 'publish_posts' );
    947962
    948963        // re-fetch both users from the db
    949         $user_1 = new WP_User($id_1);
    950         $this->assertTrue($user_1->exists(), "Problem getting user $id_1");
    951         $user_2 = new WP_User($id_2);
    952         $this->assertTrue($user_2->exists(), "Problem getting user $id_2");
     964        $user_1 = new WP_User( $id_1 );
     965        $this->assertTrue( $user_1->exists(), "Problem getting user $id_1" );
     966        $user_2 = new WP_User( $id_2 );
     967        $this->assertTrue( $user_2->exists(), "Problem getting user $id_2" );
    953968
    954969        // make sure they're both still contributors
    955         $this->assertEquals(array('contributor'), $user_1->roles);
    956         $this->assertEquals(array('contributor'), $user_2->roles);
     970        $this->assertEquals( array( 'contributor' ), $user_1->roles );
     971        $this->assertEquals( array( 'contributor' ), $user_2->roles );
    957972
    958973        // check the removed cap on both users
    959         $this->assertFalse($user_1->has_cap('publish_posts'));
    960         $this->assertFalse($user_2->has_cap('publish_posts'));
     974        $this->assertFalse( $user_1->has_cap( 'publish_posts' ) );
     975        $this->assertFalse( $user_2->has_cap( 'publish_posts' ) );
    961976
    962977    }
     
    966981
    967982        // user starts as an author
    968         $id = self::factory()->user->create( array( 'role' => 'author' ) );
    969         $user = new WP_User($id);
    970         $this->assertTrue($user->exists(), "Problem getting user $id");
     983        $id   = self::factory()->user->create( array( 'role' => 'author' ) );
     984        $user = new WP_User( $id );
     985        $this->assertTrue( $user->exists(), "Problem getting user $id" );
    971986
    972987        // author = user level 2
     
    974989
    975990        // they get promoted to editor - level should get bumped to 7
    976         $user->set_role('editor');
     991        $user->set_role( 'editor' );
    977992        $this->assertEquals( 7, $user->user_level );
    978993
    979994        // demoted to contributor - level is reduced to 1
    980         $user->set_role('contributor');
     995        $user->set_role( 'contributor' );
    981996        $this->assertEquals( 1, $user->user_level );
    982997
    983998        // if they have two roles, user_level should be the max of the two
    984         $user->add_role('editor');
    985         $this->assertEquals(array('contributor', 'editor'), $user->roles);
     999        $user->add_role( 'editor' );
     1000        $this->assertEquals( array( 'contributor', 'editor' ), $user->roles );
    9861001        $this->assertEquals( 7, $user->user_level );
    9871002    }
     
    9891004    function test_user_remove_all_caps() {
    9901005        // user starts as an author
    991         $id = self::factory()->user->create( array( 'role' => 'author' ) );
    992         $user = new WP_User($id);
    993         $this->assertTrue($user->exists(), "Problem getting user $id");
     1006        $id   = self::factory()->user->create( array( 'role' => 'author' ) );
     1007        $user = new WP_User( $id );
     1008        $this->assertTrue( $user->exists(), "Problem getting user $id" );
    9941009
    9951010        // add some extra capabilities
    996         $user->add_cap('make_coffee');
    997         $user->add_cap('drink_coffee');
     1011        $user->add_cap( 'make_coffee' );
     1012        $user->add_cap( 'drink_coffee' );
    9981013
    9991014        // re-fetch
    1000         $user = new WP_User($id);
    1001         $this->assertTrue($user->exists(), "Problem getting user $id");
    1002 
    1003         $this->assertTrue($user->has_cap('make_coffee'));
    1004         $this->assertTrue($user->has_cap('drink_coffee'));
     1015        $user = new WP_User( $id );
     1016        $this->assertTrue( $user->exists(), "Problem getting user $id" );
     1017
     1018        $this->assertTrue( $user->has_cap( 'make_coffee' ) );
     1019        $this->assertTrue( $user->has_cap( 'drink_coffee' ) );
    10051020
    10061021        // all caps are removed
     
    10081023
    10091024        // re-fetch
    1010         $user = new WP_User($id);
    1011         $this->assertTrue($user->exists(), "Problem getting user $id");
     1025        $user = new WP_User( $id );
     1026        $this->assertTrue( $user->exists(), "Problem getting user $id" );
    10121027
    10131028        // all capabilities for the user should be gone
     
    10171032
    10181033        // the extra capabilities should be gone
    1019         $this->assertFalse($user->has_cap('make_coffee'));
    1020         $this->assertFalse($user->has_cap('drink_coffee'));
     1034        $this->assertFalse( $user->has_cap( 'make_coffee' ) );
     1035        $this->assertFalse( $user->has_cap( 'drink_coffee' ) );
    10211036
    10221037        // user level should be empty
    10231038        $this->assertEmpty( $user->user_level );
    10241039
    1025 
    10261040    }
    10271041
     
    10331047
    10341048        // make a post
    1035         $post = self::factory()->post->create( array( 'post_author' => $author->ID, 'post_type' => 'post' ) );
     1049        $post = self::factory()->post->create(
     1050            array(
     1051                'post_author' => $author->ID,
     1052                'post_type'   => 'post',
     1053            )
     1054        );
    10361055
    10371056        // the author of the post
    1038         $this->assertTrue($author->exists(), "Problem getting user $author->ID");
     1057        $this->assertTrue( $author->exists(), "Problem getting user $author->ID" );
    10391058
    10401059        // add some other users
    1041         $admin = new WP_User( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
    1042         $author_2 = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
    1043         $editor = new WP_User( self::factory()->user->create( array( 'role' => 'editor' ) ) );
     1060        $admin       = new WP_User( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     1061        $author_2    = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
     1062        $editor      = new WP_User( self::factory()->user->create( array( 'role' => 'editor' ) ) );
    10441063        $contributor = new WP_User( self::factory()->user->create( array( 'role' => 'contributor' ) ) );
    10451064
    10461065        // administrators, editors and the post owner can edit it
    1047         $this->assertTrue($admin->has_cap('edit_post', $post));
    1048         $this->assertTrue($author->has_cap('edit_post', $post));
    1049         $this->assertTrue($editor->has_cap('edit_post', $post));
     1066        $this->assertTrue( $admin->has_cap( 'edit_post', $post ) );
     1067        $this->assertTrue( $author->has_cap( 'edit_post', $post ) );
     1068        $this->assertTrue( $editor->has_cap( 'edit_post', $post ) );
    10501069        // other authors and contributors can't
    1051         $this->assertFalse($author_2->has_cap('edit_post', $post));
    1052         $this->assertFalse($contributor->has_cap('edit_post', $post));
     1070        $this->assertFalse( $author_2->has_cap( 'edit_post', $post ) );
     1071        $this->assertFalse( $contributor->has_cap( 'edit_post', $post ) );
    10531072
    10541073        // administrators, editors and the post owner can delete it
    1055         $this->assertTrue($admin->has_cap('delete_post', $post));
    1056         $this->assertTrue($author->has_cap('delete_post', $post));
    1057         $this->assertTrue($editor->has_cap('delete_post', $post));
     1074        $this->assertTrue( $admin->has_cap( 'delete_post', $post ) );
     1075        $this->assertTrue( $author->has_cap( 'delete_post', $post ) );
     1076        $this->assertTrue( $editor->has_cap( 'delete_post', $post ) );
    10581077        // other authors and contributors can't
    1059         $this->assertFalse($author_2->has_cap('delete_post', $post));
    1060         $this->assertFalse($contributor->has_cap('delete_post', $post));
     1078        $this->assertFalse( $author_2->has_cap( 'delete_post', $post ) );
     1079        $this->assertFalse( $contributor->has_cap( 'delete_post', $post ) );
    10611080
    10621081        // administrators, editors, and authors can publish it
    1063         $this->assertTrue($admin->has_cap('publish_post', $post));
    1064         $this->assertTrue($author->has_cap('publish_post', $post));
    1065         $this->assertTrue($editor->has_cap('publish_post', $post));
    1066         $this->assertTrue($author_2->has_cap('publish_post', $post));
     1082        $this->assertTrue( $admin->has_cap( 'publish_post', $post ) );
     1083        $this->assertTrue( $author->has_cap( 'publish_post', $post ) );
     1084        $this->assertTrue( $editor->has_cap( 'publish_post', $post ) );
     1085        $this->assertTrue( $author_2->has_cap( 'publish_post', $post ) );
    10671086        // contributors can't
    1068         $this->assertFalse($contributor->has_cap('publish_post', $post));
     1087        $this->assertFalse( $contributor->has_cap( 'publish_post', $post ) );
    10691088
    10701089        register_post_type( 'something', array( 'capabilities' => array( 'edit_posts' => 'draw_somethings' ) ) );
     
    10731092        $this->assertEquals( 'draw_somethings', $something->cap->create_posts );
    10741093
    1075         register_post_type( 'something', array( 'capabilities' =>
    1076                         array( 'edit_posts' => 'draw_somethings', 'create_posts' => 'create_somethings' ) ) );
     1094        register_post_type(
     1095            'something', array(
     1096                'capabilities' =>
     1097                array(
     1098                    'edit_posts'   => 'draw_somethings',
     1099                    'create_posts' => 'create_somethings',
     1100                ),
     1101            )
     1102        );
    10771103        $something = get_post_type_object( 'something' );
    10781104        $this->assertEquals( 'draw_somethings', $something->cap->edit_posts );
     
    10811107
    10821108        // Test meta authorization callbacks
    1083         if ( function_exists( 'register_meta') ) {
    1084             $this->assertTrue( $admin->has_cap('edit_post_meta',  $post) );
    1085             $this->assertTrue( $admin->has_cap('add_post_meta',  $post) );
    1086             $this->assertTrue( $admin->has_cap('delete_post_meta',  $post) );
    1087 
    1088             $this->assertFalse( $admin->has_cap('edit_post_meta', $post, '_protected') );
    1089             $this->assertFalse( $admin->has_cap('add_post_meta', $post, '_protected') );
    1090             $this->assertFalse( $admin->has_cap('delete_post_meta', $post, '_protected') );
     1109        if ( function_exists( 'register_meta' ) ) {
     1110            $this->assertTrue( $admin->has_cap( 'edit_post_meta', $post ) );
     1111            $this->assertTrue( $admin->has_cap( 'add_post_meta', $post ) );
     1112            $this->assertTrue( $admin->has_cap( 'delete_post_meta', $post ) );
     1113
     1114            $this->assertFalse( $admin->has_cap( 'edit_post_meta', $post, '_protected' ) );
     1115            $this->assertFalse( $admin->has_cap( 'add_post_meta', $post, '_protected' ) );
     1116            $this->assertFalse( $admin->has_cap( 'delete_post_meta', $post, '_protected' ) );
    10911117
    10921118            register_meta( 'post', '_protected', array( $this, '_meta_filter' ), array( $this, '_meta_yes_you_can' ) );
    1093             $this->assertTrue( $admin->has_cap('edit_post_meta',  $post, '_protected') );
    1094             $this->assertTrue( $admin->has_cap('add_post_meta',  $post, '_protected') );
    1095             $this->assertTrue( $admin->has_cap('delete_post_meta',  $post, '_protected') );
    1096 
    1097             $this->assertTrue( $admin->has_cap('edit_post_meta', $post, 'not_protected') );
    1098             $this->assertTrue( $admin->has_cap('add_post_meta', $post, 'not_protected') );
    1099             $this->assertTrue( $admin->has_cap('delete_post_meta', $post, 'not_protected') );
     1119            $this->assertTrue( $admin->has_cap( 'edit_post_meta', $post, '_protected' ) );
     1120            $this->assertTrue( $admin->has_cap( 'add_post_meta', $post, '_protected' ) );
     1121            $this->assertTrue( $admin->has_cap( 'delete_post_meta', $post, '_protected' ) );
     1122
     1123            $this->assertTrue( $admin->has_cap( 'edit_post_meta', $post, 'not_protected' ) );
     1124            $this->assertTrue( $admin->has_cap( 'add_post_meta', $post, 'not_protected' ) );
     1125            $this->assertTrue( $admin->has_cap( 'delete_post_meta', $post, 'not_protected' ) );
    11001126
    11011127            register_meta( 'post', 'not_protected', array( $this, '_meta_filter' ), array( $this, '_meta_no_you_cant' ) );
    1102             $this->assertFalse( $admin->has_cap('edit_post_meta',  $post, 'not_protected') );
    1103             $this->assertFalse( $admin->has_cap('add_post_meta',  $post, 'not_protected') );
    1104             $this->assertFalse( $admin->has_cap('delete_post_meta',  $post, 'not_protected') );
     1128            $this->assertFalse( $admin->has_cap( 'edit_post_meta', $post, 'not_protected' ) );
     1129            $this->assertFalse( $admin->has_cap( 'add_post_meta', $post, 'not_protected' ) );
     1130            $this->assertFalse( $admin->has_cap( 'delete_post_meta', $post, 'not_protected' ) );
    11051131        }
    11061132    }
     
    11161142    function test_authorless_post( $status ) {
    11171143        // Make a post without an author
    1118         $post = self::factory()->post->create( array( 'post_author' => 0, 'post_type' => 'post', 'post_status' => $status ) );
     1144        $post = self::factory()->post->create(
     1145            array(
     1146                'post_author' => 0,
     1147                'post_type'   => 'post',
     1148                'post_status' => $status,
     1149            )
     1150        );
    11191151
    11201152        // Add an editor and contributor
    1121         $editor = self::$users['editor'];
     1153        $editor      = self::$users['editor'];
    11221154        $contributor = self::$users['contributor'];
    11231155
     
    11461178
    11471179        // create_posts isn't a real cap.
    1148         $this->assertFalse($admin->has_cap('create_posts'));
    1149         $this->assertFalse($author->has_cap('create_posts'));
    1150         $this->assertFalse($editor->has_cap('create_posts'));
    1151         $this->assertFalse($contributor->has_cap('create_posts'));
    1152         $this->assertFalse($subscriber->has_cap('create_posts'));
     1180        $this->assertFalse( $admin->has_cap( 'create_posts' ) );
     1181        $this->assertFalse( $author->has_cap( 'create_posts' ) );
     1182        $this->assertFalse( $editor->has_cap( 'create_posts' ) );
     1183        $this->assertFalse( $contributor->has_cap( 'create_posts' ) );
     1184        $this->assertFalse( $subscriber->has_cap( 'create_posts' ) );
    11531185
    11541186        register_post_type( 'foobar' );
     
    11571189        $this->assertEquals( 'edit_posts', $cap->create_posts );
    11581190
    1159         $this->assertTrue($admin->has_cap( $cap->create_posts ));
    1160         $this->assertTrue($author->has_cap( $cap->create_posts ));
    1161         $this->assertTrue($editor->has_cap( $cap->create_posts ));
    1162         $this->assertTrue($contributor->has_cap( $cap->create_posts ));
    1163         $this->assertFalse($subscriber->has_cap( $cap->create_posts ));
     1191        $this->assertTrue( $admin->has_cap( $cap->create_posts ) );
     1192        $this->assertTrue( $author->has_cap( $cap->create_posts ) );
     1193        $this->assertTrue( $editor->has_cap( $cap->create_posts ) );
     1194        $this->assertTrue( $contributor->has_cap( $cap->create_posts ) );
     1195        $this->assertFalse( $subscriber->has_cap( $cap->create_posts ) );
    11641196
    11651197        _unregister_post_type( 'foobar' );
     
    11711203        $this->assertEquals( 'edit_foobars', $cap->create_posts );
    11721204
    1173         $this->assertFalse($admin->has_cap( $cap->create_posts ));
    1174         $this->assertFalse($author->has_cap( $cap->create_posts ));
    1175         $this->assertFalse($editor->has_cap( $cap->create_posts ));
    1176         $this->assertFalse($contributor->has_cap( $cap->create_posts ));
    1177         $this->assertFalse($subscriber->has_cap( $cap->create_posts ));
     1205        $this->assertFalse( $admin->has_cap( $cap->create_posts ) );
     1206        $this->assertFalse( $author->has_cap( $cap->create_posts ) );
     1207        $this->assertFalse( $editor->has_cap( $cap->create_posts ) );
     1208        $this->assertFalse( $contributor->has_cap( $cap->create_posts ) );
     1209        $this->assertFalse( $subscriber->has_cap( $cap->create_posts ) );
    11781210
    11791211        // Add edit_foobars primitive cap to a user.
    11801212        $admin->add_cap( 'edit_foobars', true );
    11811213        $admin = new WP_User( $admin->ID );
    1182         $this->assertTrue($admin->has_cap( $cap->create_posts ));
    1183         $this->assertFalse($author->has_cap( $cap->create_posts ));
    1184         $this->assertFalse($editor->has_cap( $cap->create_posts ));
    1185         $this->assertFalse($contributor->has_cap( $cap->create_posts ));
    1186         $this->assertFalse($subscriber->has_cap( $cap->create_posts ));
     1214        $this->assertTrue( $admin->has_cap( $cap->create_posts ) );
     1215        $this->assertFalse( $author->has_cap( $cap->create_posts ) );
     1216        $this->assertFalse( $editor->has_cap( $cap->create_posts ) );
     1217        $this->assertFalse( $contributor->has_cap( $cap->create_posts ) );
     1218        $this->assertFalse( $subscriber->has_cap( $cap->create_posts ) );
    11871219
    11881220        $admin->remove_cap( 'edit_foobars' );
     
    12081240
    12091241        // make a page
    1210         $page = self::factory()->post->create( array( 'post_author' => $author->ID, 'post_type' => 'page' ) );
     1242        $page = self::factory()->post->create(
     1243            array(
     1244                'post_author' => $author->ID,
     1245                'post_type'   => 'page',
     1246            )
     1247        );
    12111248
    12121249        // the author of the page
    1213         $this->assertTrue($author->exists(), "Problem getting user " . $author->ID);
     1250        $this->assertTrue( $author->exists(), 'Problem getting user ' . $author->ID );
    12141251
    12151252        // add some other users
    1216         $admin = self::$users['administrator'];
    1217         $author_2 = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
    1218         $editor = self::$users['editor'];
     1253        $admin       = self::$users['administrator'];
     1254        $author_2    = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
     1255        $editor      = self::$users['editor'];
    12191256        $contributor = self::$users['contributor'];
    12201257
    12211258        // administrators, editors and the post owner can edit it
    1222         $this->assertTrue($admin->has_cap('edit_page', $page));
    1223         $this->assertTrue($editor->has_cap('edit_page', $page));
     1259        $this->assertTrue( $admin->has_cap( 'edit_page', $page ) );
     1260        $this->assertTrue( $editor->has_cap( 'edit_page', $page ) );
    12241261        // other authors and contributors can't
    1225         $this->assertFalse($author->has_cap('edit_page', $page));
    1226         $this->assertFalse($author_2->has_cap('edit_page', $page));
    1227         $this->assertFalse($contributor->has_cap('edit_page', $page));
     1262        $this->assertFalse( $author->has_cap( 'edit_page', $page ) );
     1263        $this->assertFalse( $author_2->has_cap( 'edit_page', $page ) );
     1264        $this->assertFalse( $contributor->has_cap( 'edit_page', $page ) );
    12281265
    12291266        // administrators, editors and the post owner can delete it
    1230         $this->assertTrue($admin->has_cap('delete_page', $page));
    1231         $this->assertTrue($editor->has_cap('delete_page', $page));
     1267        $this->assertTrue( $admin->has_cap( 'delete_page', $page ) );
     1268        $this->assertTrue( $editor->has_cap( 'delete_page', $page ) );
    12321269        // other authors and contributors can't
    1233         $this->assertFalse($author->has_cap('delete_page', $page));
    1234         $this->assertFalse($author_2->has_cap('delete_page', $page));
    1235         $this->assertFalse($contributor->has_cap('delete_page', $page));
     1270        $this->assertFalse( $author->has_cap( 'delete_page', $page ) );
     1271        $this->assertFalse( $author_2->has_cap( 'delete_page', $page ) );
     1272        $this->assertFalse( $contributor->has_cap( 'delete_page', $page ) );
    12361273    }
    12371274
     
    12591296        foreach ( $expected as $meta_cap => $primitive_cap ) {
    12601297            $caps = map_meta_cap( $tax->cap->$meta_cap, $user->ID );
    1261             $this->assertEquals( array(
    1262                 $primitive_cap,
    1263             ), $caps, "Meta cap: {$meta_cap}" );
     1298            $this->assertEquals(
     1299                array(
     1300                    $primitive_cap,
     1301                ), $caps, "Meta cap: {$meta_cap}"
     1302            );
    12641303        }
    12651304    }
     
    12771316        $tax  = get_taxonomy( $taxonomy );
    12781317        $user = self::$users['administrator'];
    1279         $term = self::factory()->term->create_and_get( array(
    1280             'taxonomy' => $taxonomy,
    1281         ) );
     1318        $term = self::factory()->term->create_and_get(
     1319            array(
     1320                'taxonomy' => $taxonomy,
     1321            )
     1322        );
    12821323
    12831324        update_option( "default_{$taxonomy}", $term->term_id );
     
    12981339
    12991340        $tax  = get_taxonomy( $taxonomy );
    1300         $term = self::factory()->term->create_and_get( array(
    1301             'taxonomy' => $taxonomy,
    1302         ) );
     1341        $term = self::factory()->term->create_and_get(
     1342            array(
     1343                'taxonomy' => $taxonomy,
     1344            )
     1345        );
    13031346
    13041347        foreach ( self::$users as $role => $user ) {
     
    13471390        );
    13481391        $taxonomy = 'custom_cap_taxo';
    1349         register_taxonomy( $taxonomy, 'post', array(
    1350             'capabilities' => $expected,
    1351         ) );
     1392        register_taxonomy(
     1393            $taxonomy, 'post', array(
     1394                'capabilities' => $expected,
     1395            )
     1396        );
    13521397
    13531398        $tax  = get_taxonomy( $taxonomy );
     
    13561401        foreach ( $expected as $meta_cap => $primitive_cap ) {
    13571402            $caps = map_meta_cap( $tax->cap->$meta_cap, $user->ID );
    1358             $this->assertEquals( array(
    1359                 $primitive_cap,
    1360             ), $caps, "Meta cap: {$meta_cap}" );
     1403            $this->assertEquals(
     1404                array(
     1405                    $primitive_cap,
     1406                ), $caps, "Meta cap: {$meta_cap}"
     1407            );
    13611408        }
    13621409    }
     
    13901437
    13911438        $author->add_cap( 'foo', false );
    1392         $this->assertTrue ( isset( $author->caps['foo'] ) );
     1439        $this->assertTrue( isset( $author->caps['foo'] ) );
    13931440        $this->assertFalse( user_can( $author->ID, 'foo' ) );
    13941441
    13951442        $author->remove_cap( 'foo' );
    1396         $this->assertFalse ( isset( $author->caps['foo'] ) );
     1443        $this->assertFalse( isset( $author->caps['foo'] ) );
    13971444        $this->assertFalse( user_can( $author->ID, 'foo' ) );
    13981445    }
     
    14131460        global $wpdb;
    14141461
    1415         $user = self::$users['administrator'];
     1462        $user    = self::$users['administrator'];
    14161463        $old_uid = get_current_user_id();
    14171464        wp_set_current_user( $user->ID );
     
    14401487    function test_borked_current_user_can_for_blog() {
    14411488        $orig_blog_id = get_current_blog_id();
    1442         $blog_id = self::factory()->blog->create();
     1489        $blog_id      = self::factory()->blog->create();
    14431490
    14441491        $this->_nullify_current_user();
     
    14981545     */
    14991546    function test_multisite_administrator_can_not_edit_users() {
    1500         $user = self::$users['administrator'];
     1547        $user       = self::$users['administrator'];
    15011548        $other_user = self::$users['subscriber'];
    15021549
     
    15151562    public function test_only_admins_and_super_admins_can_remove_users() {
    15161563        if ( is_multisite() ) {
    1517             $this->assertTrue( user_can( self::$super_admin->ID,        'remove_user', self::$users['subscriber']->ID ) );
     1564            $this->assertTrue( user_can( self::$super_admin->ID, 'remove_user', self::$users['subscriber']->ID ) );
    15181565        }
    15191566
    15201567        $this->assertTrue( user_can( self::$users['administrator']->ID, 'remove_user', self::$users['subscriber']->ID ) );
    15211568
    1522         $this->assertFalse( user_can( self::$users['editor']->ID,       'remove_user', self::$users['subscriber']->ID ) );
    1523         $this->assertFalse( user_can( self::$users['author']->ID,       'remove_user', self::$users['subscriber']->ID ) );
    1524         $this->assertFalse( user_can( self::$users['contributor']->ID,  'remove_user', self::$users['subscriber']->ID ) );
    1525         $this->assertFalse( user_can( self::$users['subscriber']->ID,   'remove_user', self::$users['subscriber']->ID ) );
     1569        $this->assertFalse( user_can( self::$users['editor']->ID, 'remove_user', self::$users['subscriber']->ID ) );
     1570        $this->assertFalse( user_can( self::$users['author']->ID, 'remove_user', self::$users['subscriber']->ID ) );
     1571        $this->assertFalse( user_can( self::$users['contributor']->ID, 'remove_user', self::$users['subscriber']->ID ) );
     1572        $this->assertFalse( user_can( self::$users['subscriber']->ID, 'remove_user', self::$users['subscriber']->ID ) );
    15261573    }
    15271574
     
    15301577     */
    15311578    public function test_only_super_admins_can_delete_users_on_multisite() {
    1532         $this->assertTrue( user_can( self::$super_admin->ID,             'delete_user', self::$users['subscriber']->ID ) );
     1579        $this->assertTrue( user_can( self::$super_admin->ID, 'delete_user', self::$users['subscriber']->ID ) );
    15331580
    15341581        $this->assertFalse( user_can( self::$users['administrator']->ID, 'delete_user', self::$users['subscriber']->ID ) );
    1535         $this->assertFalse( user_can( self::$users['editor']->ID,        'delete_user', self::$users['subscriber']->ID ) );
    1536         $this->assertFalse( user_can( self::$users['author']->ID,        'delete_user', self::$users['subscriber']->ID ) );
    1537         $this->assertFalse( user_can( self::$users['contributor']->ID,   'delete_user', self::$users['subscriber']->ID ) );
    1538         $this->assertFalse( user_can( self::$users['subscriber']->ID,    'delete_user', self::$users['subscriber']->ID ) );
     1582        $this->assertFalse( user_can( self::$users['editor']->ID, 'delete_user', self::$users['subscriber']->ID ) );
     1583        $this->assertFalse( user_can( self::$users['author']->ID, 'delete_user', self::$users['subscriber']->ID ) );
     1584        $this->assertFalse( user_can( self::$users['contributor']->ID, 'delete_user', self::$users['subscriber']->ID ) );
     1585        $this->assertFalse( user_can( self::$users['subscriber']->ID, 'delete_user', self::$users['subscriber']->ID ) );
    15391586    }
    15401587
     
    15451592        $this->assertTrue( user_can( self::$users['administrator']->ID, 'delete_user', self::$users['subscriber']->ID ) );
    15461593
    1547         $this->assertFalse( user_can( self::$users['editor']->ID,       'delete_user', self::$users['subscriber']->ID ) );
    1548         $this->assertFalse( user_can( self::$users['author']->ID,       'delete_user', self::$users['subscriber']->ID ) );
    1549         $this->assertFalse( user_can( self::$users['contributor']->ID,  'delete_user', self::$users['subscriber']->ID ) );
    1550         $this->assertFalse( user_can( self::$users['subscriber']->ID,   'delete_user', self::$users['subscriber']->ID ) );
     1594        $this->assertFalse( user_can( self::$users['editor']->ID, 'delete_user', self::$users['subscriber']->ID ) );
     1595        $this->assertFalse( user_can( self::$users['author']->ID, 'delete_user', self::$users['subscriber']->ID ) );
     1596        $this->assertFalse( user_can( self::$users['contributor']->ID, 'delete_user', self::$users['subscriber']->ID ) );
     1597        $this->assertFalse( user_can( self::$users['subscriber']->ID, 'delete_user', self::$users['subscriber']->ID ) );
    15511598    }
    15521599
    15531600    public function test_only_admins_and_super_admins_can_promote_users() {
    15541601        if ( is_multisite() ) {
    1555             $this->assertTrue( user_can( self::$super_admin->ID,              'promote_user', self::$users['subscriber']->ID ) );
     1602            $this->assertTrue( user_can( self::$super_admin->ID, 'promote_user', self::$users['subscriber']->ID ) );
    15561603        }
    15571604
    15581605        $this->assertTrue( user_can( self::$users['administrator']->ID, 'promote_user', self::$users['subscriber']->ID ) );
    15591606
    1560         $this->assertFalse( user_can( self::$users['editor']->ID,       'promote_user', self::$users['subscriber']->ID ) );
    1561         $this->assertFalse( user_can( self::$users['author']->ID,       'promote_user', self::$users['subscriber']->ID ) );
    1562         $this->assertFalse( user_can( self::$users['contributor']->ID,  'promote_user', self::$users['subscriber']->ID ) );
    1563         $this->assertFalse( user_can( self::$users['subscriber']->ID,   'promote_user', self::$users['subscriber']->ID ) );
     1607        $this->assertFalse( user_can( self::$users['editor']->ID, 'promote_user', self::$users['subscriber']->ID ) );
     1608        $this->assertFalse( user_can( self::$users['author']->ID, 'promote_user', self::$users['subscriber']->ID ) );
     1609        $this->assertFalse( user_can( self::$users['contributor']->ID, 'promote_user', self::$users['subscriber']->ID ) );
     1610        $this->assertFalse( user_can( self::$users['subscriber']->ID, 'promote_user', self::$users['subscriber']->ID ) );
    15641611    }
    15651612
     
    15731620
    15741621        // Give them a scheduled post
    1575         $post = $this->factory->post->create_and_get( array(
    1576             'post_author' => $contributor->ID,
    1577             'post_status' => 'future',
    1578         ) );
     1622        $post = $this->factory->post->create_and_get(
     1623            array(
     1624                'post_author' => $contributor->ID,
     1625                'post_status' => 'future',
     1626            )
     1627        );
    15791628
    15801629        // Ensure contributor can't edit or trash the post
     
    16391688
    16401689        $subscriber_id = self::$users['subscriber']->ID;
    1641         $editor_id = self::$users['editor']->ID;
     1690        $editor_id     = self::$users['editor']->ID;
    16421691
    16431692        foreach ( array( 'delete_post', 'edit_post', 'read_post', 'publish_post' ) as $cap ) {
     
    16571706    function test_cpt_with_page_capability_type() {
    16581707
    1659         register_post_type( 'page_capability', array(
    1660             'capability_type' => 'page',
    1661         ) );
     1708        register_post_type(
     1709            'page_capability', array(
     1710                'capability_type' => 'page',
     1711            )
     1712        );
    16621713
    16631714        $cpt = get_post_type_object( 'page_capability' );
     
    16741725        $this->assertFalse( user_can( $contributor->ID, $cpt->cap->edit_posts ) );
    16751726
    1676         $admin_post = self::factory()->post->create_and_get( array(
    1677             'post_author' => $admin->ID,
    1678             'post_type'   => 'page_capability',
    1679         ) );
     1727        $admin_post = self::factory()->post->create_and_get(
     1728            array(
     1729                'post_author' => $admin->ID,
     1730                'post_type'   => 'page_capability',
     1731            )
     1732        );
    16801733
    16811734        $this->assertTrue( user_can( $admin->ID, 'edit_post', $admin_post->ID ) );
     
    16841737        $this->assertFalse( user_can( $contributor->ID, 'edit_post', $admin_post->ID ) );
    16851738
    1686         $author_post = self::factory()->post->create_and_get( array(
    1687             'post_author' => $author->ID,
    1688             'post_type'   => 'page_capability',
    1689         ) );
     1739        $author_post = self::factory()->post->create_and_get(
     1740            array(
     1741                'post_author' => $author->ID,
     1742                'post_type'   => 'page_capability',
     1743            )
     1744        );
    16901745
    16911746        $this->assertTrue( user_can( $admin->ID, 'edit_post', $author_post->ID ) );
     
    17091764
    17101765        // Special cases for link manager and unfiltered uploads:
    1711         $this->assertFalse( current_user_can( 'manage_links' ), "Non-logged-in user should not have the manage_links capability" );
    1712         $this->assertFalse( current_user_can( 'unfiltered_upload' ), "Non-logged-in user should not have the unfiltered_upload capability" );
    1713 
    1714         $this->assertFalse( current_user_can( 'start_a_fire' ), "Non-logged-in user should not have a custom capability" );
    1715         $this->assertFalse( current_user_can( 'do_not_allow' ), "Non-logged-in user should not have the do_not_allow capability" );
     1766        $this->assertFalse( current_user_can( 'manage_links' ), 'Non-logged-in user should not have the manage_links capability' );
     1767        $this->assertFalse( current_user_can( 'unfiltered_upload' ), 'Non-logged-in user should not have the unfiltered_upload capability' );
     1768
     1769        $this->assertFalse( current_user_can( 'start_a_fire' ), 'Non-logged-in user should not have a custom capability' );
     1770        $this->assertFalse( current_user_can( 'do_not_allow' ), 'Non-logged-in user should not have the do_not_allow capability' );
    17161771    }
    17171772
     
    17241779            'role' => 'test_wp_roles_init',
    17251780            'info' => array(
    1726                 'name' => 'Test WP Roles Init',
     1781                'name'         => 'Test WP Roles Init',
    17271782                'capabilities' => array( 'testing_magic' => true ),
    17281783            ),
     
    18441899
    18451900        $this->assertFalse( user_can( self::$users['administrator']->ID, 'remove_user', self::$users['administrator']->ID ) );
    1846         $this->assertFalse( user_can( self::$users['editor']->ID,        'remove_user', self::$users['editor']->ID ) );
    1847         $this->assertFalse( user_can( self::$users['author']->ID,        'remove_user', self::$users['author']->ID ) );
    1848         $this->assertFalse( user_can( self::$users['contributor']->ID,   'remove_user', self::$users['contributor']->ID ) );
    1849         $this->assertFalse( user_can( self::$users['subscriber']->ID,    'remove_user', self::$users['subscriber']->ID ) );
     1901        $this->assertFalse( user_can( self::$users['editor']->ID, 'remove_user', self::$users['editor']->ID ) );
     1902        $this->assertFalse( user_can( self::$users['author']->ID, 'remove_user', self::$users['author']->ID ) );
     1903        $this->assertFalse( user_can( self::$users['contributor']->ID, 'remove_user', self::$users['contributor']->ID ) );
     1904        $this->assertFalse( user_can( self::$users['subscriber']->ID, 'remove_user', self::$users['subscriber']->ID ) );
    18501905    }
    18511906
     
    18621917
    18631918        $role_name = 'uploader';
    1864         add_role( $role_name, 'Uploader', array(
    1865             'read'         => true,
    1866             'upload_files' => true,
    1867         ) );
     1919        add_role(
     1920            $role_name, 'Uploader', array(
     1921                'read'         => true,
     1922                'upload_files' => true,
     1923            )
     1924        );
    18681925        add_user_to_blog( $site_id, self::$users['subscriber']->ID, $role_name );
    18691926
     
    18881945
    18891946        $role_name = 'uploader';
    1890         add_role( $role_name, 'Uploader', array(
    1891             'read'         => true,
    1892             'upload_files' => true,
    1893         ) );
     1947        add_role(
     1948            $role_name, 'Uploader', array(
     1949                'read'         => true,
     1950                'upload_files' => true,
     1951            )
     1952        );
    18941953        add_user_to_blog( $site_id, self::$users['subscriber']->ID, $role_name );
    18951954
     
    19351994        // which is unnecessary for this test.
    19361995        $suppress = $wpdb->suppress_errors();
    1937         $user = new WP_User( self::$users['subscriber']->ID, '', 333 );
     1996        $user     = new WP_User( self::$users['subscriber']->ID, '', 333 );
    19381997        $wpdb->suppress_errors( $suppress );
    19391998
     
    19532012
    19542013        $role_name = 'uploader';
    1955         add_role( $role_name, 'Uploader', array(
    1956             'read'         => true,
    1957             'upload_files' => true,
    1958         ) );
     2014        add_role(
     2015            $role_name, 'Uploader', array(
     2016                'read'         => true,
     2017                'upload_files' => true,
     2018            )
     2019        );
    19592020
    19602021        restore_current_blog();
     
    20062067        // which is unnecessary for this test.
    20072068        $suppress = $wpdb->suppress_errors();
    2008         $roles = new WP_Roles( 333 );
     2069        $roles    = new WP_Roles( 333 );
    20092070        $wpdb->suppress_errors( $suppress );
    20102071
Note: See TracChangeset for help on using the changeset viewer.