mirror of
https://github.com/buddypress/buddypress.git
synced 2026-07-22 20:56:55 +08:00
Use of the `@expectedDeprecated` annotation means that the deprecation notice is expected across all versions of WordPress, while we in fact need to suppress the notices only on WP 5.0+. See #7984. git-svn-id: https://buddypress.svn.wordpress.org/trunk@12246 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group core
|
|
* @group caps
|
|
*/
|
|
class BP_Tests_Core_Caps extends BP_UnitTestCase {
|
|
public function test_bp_current_user_can_should_interpret_integer_second_param_as_a_blog_id() {
|
|
if ( ! is_multisite() ) {
|
|
$this->markTestSkipped( __METHOD__ . ' requires multisite.' );
|
|
}
|
|
|
|
if ( function_exists( 'wp_initialize_site' ) ) {
|
|
$this->setExpectedDeprecated( 'wpmu_new_blog' );
|
|
}
|
|
|
|
$b = self::factory()->blog->create();
|
|
$u = self::factory()->user->create();
|
|
|
|
$this->set_current_user( $u );
|
|
|
|
add_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10, 2 );
|
|
$can = bp_current_user_can( 'foo', bp_get_root_blog_id() );
|
|
$cant = bp_current_user_can( 'foo', $b );
|
|
remove_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10 );
|
|
|
|
$this->assertTrue( $can );
|
|
$this->assertFalse( $cant );
|
|
}
|
|
|
|
/**
|
|
* @ticket BP6501
|
|
*/
|
|
public function test_bp_current_user_can_should_respect_blog_id_passed_in_args_array() {
|
|
if ( ! is_multisite() ) {
|
|
$this->markTestSkipped( __METHOD__ . ' requires multisite.' );
|
|
}
|
|
|
|
if ( function_exists( 'wp_initialize_site' ) ) {
|
|
$this->setExpectedDeprecated( 'wpmu_new_blog' );
|
|
}
|
|
|
|
$b = self::factory()->blog->create();
|
|
$u = self::factory()->user->create();
|
|
|
|
$this->set_current_user( $u );
|
|
|
|
add_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10, 2 );
|
|
$can = bp_current_user_can( 'foo', array( 'blog_id' => bp_get_root_blog_id() ) );
|
|
$cant = bp_current_user_can( 'foo', array( 'blog_id' => $b ) );
|
|
remove_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10 );
|
|
|
|
$this->assertTrue( $can );
|
|
$this->assertFalse( $cant );
|
|
}
|
|
|
|
public function grant_cap_foo( $allcaps, $caps ) {
|
|
if ( bp_is_root_blog() ) {
|
|
$allcaps['foo'] = 1;
|
|
}
|
|
|
|
return $allcaps;
|
|
}
|
|
|
|
public function check_cap_args( $caps, $cap, $user_id, $args ) {
|
|
$this->test_args = $args;
|
|
return $caps;
|
|
}
|
|
}
|