[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @group core
   5   * @group nav
   6   */
   7  class BP_Tests_Core_Nav_BpCoreRemoveNavItem extends BP_UnitTestCase {
   8      /**
   9       * @expectedIncorrectUsage bp_nav
  10       */
  11  	public function test_should_remove_subnav_items() {
  12          $bp = buddypress();
  13  
  14          $_bp_nav = $bp->bp_nav;
  15          $_bp_options_nav = $bp->bp_options_nav;
  16  
  17          bp_core_new_nav_item( array(
  18              'name' => 'Foo',
  19              'slug' => 'foo',
  20              'screen_function' => 'foo',
  21          ) );
  22  
  23          bp_core_new_subnav_item( array(
  24              'name' => 'Bar',
  25              'slug' => 'bar',
  26              'parent_slug' => 'foo',
  27              'parent_url' => 'foo',
  28              'screen_function' => 'bar',
  29          ) );
  30  
  31          $this->assertTrue( isset( $bp->bp_nav['foo'] ) );
  32          $this->assertTrue( isset( $bp->bp_options_nav['foo'] ) );
  33          $this->assertTrue( isset( $bp->bp_options_nav['foo']['bar'] ) );
  34  
  35          bp_core_remove_nav_item( 'foo' );
  36  
  37          $this->assertFalse( isset( $bp->bp_options_nav['foo']['bar'] ) );
  38  
  39          $bp->bp_nav = $_bp_nav;
  40          $bp->bp_options_nav = $_bp_options_nav;
  41      }
  42  
  43      /**
  44       * @expectedIncorrectUsage bp_nav
  45       */
  46  	public function test_should_remove_nav_item() {
  47          $bp = buddypress();
  48  
  49          $_bp_nav = $bp->bp_nav;
  50          $_bp_options_nav = $bp->bp_options_nav;
  51  
  52          bp_core_new_nav_item( array(
  53              'name' => 'Foo',
  54              'slug' => 'foo',
  55              'screen_function' => 'foo',
  56          ) );
  57  
  58          $this->assertTrue( isset( $bp->bp_nav['foo'] ) );
  59  
  60          bp_core_remove_nav_item( 'foo' );
  61  
  62          $this->assertFalse( isset( $bp->bp_nav['foo'] ) );
  63  
  64          $bp->bp_nav = $_bp_nav;
  65          $bp->bp_options_nav = $_bp_options_nav;
  66      }
  67  
  68      /**
  69       * @ticket BP7203
  70       */
  71      public function test_remove_subnav_item_array_as_screen_function() {
  72          $bp = buddypress();
  73  
  74          add_filter( 'bp_is_active', array( $this, 'foo_is_active' ), 10, 2 );
  75  
  76          $bp->foo = new stdClass;
  77          $bp->foo->nav = new BP_Core_Nav( 0 );
  78  
  79          $expected = array( 'foo', 'bar' );
  80  
  81          bp_core_new_nav_item( array(
  82              'name' => 'Foo',
  83              'slug' => 'foo',
  84              'screen_function' => $expected,
  85          ), 'foo' );
  86  
  87          bp_core_new_subnav_item( array(
  88              'name' => 'Bar',
  89              'slug' => 'bar',
  90              'parent_slug' => 'foo',
  91              'parent_url' => 'foo',
  92              'screen_function' => $expected,
  93          ), 'foo' );
  94  
  95          remove_filter( 'bp_is_active', array( $this, 'foo_is_active' ), 10 );
  96  
  97          $this->assertNotEmpty( $bp->foo->nav->get_primary( array( 'slug' => 'foo' ), false ) );
  98  
  99          $tested = $bp->foo->nav->delete_nav( 'foo' );
 100          $this->assertSame( $expected, reset( $tested ) );
 101  
 102          $this->assertEmpty( $bp->foo->nav->get_primary( array( 'slug' => 'foo' ), false ) );
 103      }
 104  
 105      /**
 106       * Helper method to filter 'bp_is_active' for unit tests.
 107       */
 108  	public function foo_is_active( $retval, $component ) {
 109          if ( 'foo' === $component ) {
 110              $retval = true;
 111          }
 112  
 113          return $retval;
 114      }
 115  }


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1