[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/core/ -> caps.php (source)

   1  <?php
   2  
   3  /**
   4   * @group core
   5   * @group caps
   6   */
   7  class BP_Tests_Core_Caps extends BP_UnitTestCase {
   8      public function test_bp_current_user_can_should_interpret_integer_second_param_as_a_blog_id() {
   9          if ( ! is_multisite() ) {
  10              $this->markTestSkipped( __METHOD__ . ' requires multisite.' );
  11          }
  12  
  13          if ( function_exists( 'wp_initialize_site' ) ) {
  14              $this->setExpectedDeprecated( 'wpmu_new_blog' );
  15          }
  16  
  17          $b = self::factory()->blog->create();
  18          $u = self::factory()->user->create();
  19  
  20          $this->set_current_user( $u );
  21  
  22          add_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10, 2 );
  23          $can  = bp_current_user_can( 'foo', bp_get_root_blog_id() );
  24          $cant = bp_current_user_can( 'foo', $b );
  25          remove_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10 );
  26  
  27          $this->assertTrue( $can );
  28          $this->assertFalse( $cant );
  29      }
  30  
  31      /**
  32       * @ticket BP6501
  33       */
  34      public function test_bp_current_user_can_should_respect_blog_id_passed_in_args_array() {
  35          if ( ! is_multisite() ) {
  36              $this->markTestSkipped( __METHOD__ . ' requires multisite.' );
  37          }
  38  
  39          if ( function_exists( 'wp_initialize_site' ) ) {
  40              $this->setExpectedDeprecated( 'wpmu_new_blog' );
  41          }
  42  
  43          $b = self::factory()->blog->create();
  44          $u = self::factory()->user->create();
  45  
  46          $this->set_current_user( $u );
  47  
  48          add_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10, 2 );
  49          $can  = bp_current_user_can( 'foo', array( 'blog_id' => bp_get_root_blog_id() ) );
  50          $cant = bp_current_user_can( 'foo', array( 'blog_id' => $b ) );
  51          remove_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10 );
  52  
  53          $this->assertTrue( $can );
  54          $this->assertFalse( $cant );
  55      }
  56  
  57  	public function grant_cap_foo( $allcaps, $caps ) {
  58          if ( bp_is_root_blog() ) {
  59              $allcaps['foo'] = 1;
  60          }
  61  
  62          return $allcaps;
  63      }
  64  
  65  	public function check_cap_args( $caps, $cap, $user_id, $args ) {
  66          $this->test_args = $args;
  67          return $caps;
  68      }
  69  }


Generated: Tue Oct 22 01:01:36 2019 Cross-referenced by PHPXref 0.7.1