Skip to:
Content

BuddyPress.org

Ticket #6730: 6730.01.patch

File 6730.01.patch, 1.9 KB (added by r-a-y, 8 years ago)
  • src/bp-core/bp-core-caps.php

     
    291291                unset( $args['blog_id'] );
    292292        }
    293293
     294        // Backward compatibility for older bp_current_user_can() checks
     295        if ( empty( $args ) ) {
     296                $args = null;
     297        }
     298
    294299        // Use root blog if no ID passed
    295300        if ( empty( $blog_id ) ) {
    296301                $blog_id = bp_get_root_blog_id();
  • tests/phpunit/testcases/core/caps.php

     
    4646                $this->assertFalse( $cant );
    4747        }
    4848
     49        /**
     50         * @group bp_xprofile_change_field_visibility
     51         */
     52        public function test_bp_current_user_can_should_pass_null_in_args_parameter_if_empty() {
     53                $u = $this->factory->user->create();
     54                $this->set_current_user( $u );
     55
     56                /**
     57                 * Fake bp_get_the_profile_field_id() to pretend we're in the field loop and
     58                 * to avoid notices when checking 'bp_xprofile_change_field_visibility' cap
     59                 */
     60                $GLOBALS['field'] = new stdClass;
     61                $GLOBALS['field']->id = 1;
     62
     63                // Capture the cap's $args
     64                add_filter( 'bp_xprofile_map_meta_caps', array( $this, 'check_cap_args' ), 10, 4 );
     65
     66                // Use a cap check that depends on a null value for a cap's args
     67                bp_current_user_can( 'bp_xprofile_change_field_visibility' );
     68
     69                // Assert!
     70                $this->assertEquals( null, $this->test_args[0] );
     71
     72                // Reset
     73                remove_filter( 'bp_xprofile_map_meta_caps', array( $this, 'check_cap_args' ), 10, 4 );
     74                unset( $GLOBALS['field'], $this->test_args );
     75        }
     76
    4977        public function grant_cap_foo( $allcaps, $caps ) {
    5078                if ( bp_is_root_blog() ) {
    5179                        $allcaps['foo'] = 1;
     
    5381
    5482                return $allcaps;
    5583        }
     84
     85        public function check_cap_args( $caps, $cap, $user_id, $args ) {
     86                $this->test_args = $args;
     87                return $caps;
     88        }
    5689}