[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @group core
   5   * @group nav
   6   * @ticket BP6534
   7   * @expectedIncorrectUsage bp_nav
   8   */
   9  class BP_Core_Nav_BackCompat extends BP_UnitTestCase {
  10      protected $bp_nav;
  11      protected $bp_options_nav;
  12  
  13  	public function setUp() {
  14          parent::setUp();
  15          $this->bp_nav = buddypress()->bp_nav;
  16          $this->bp_options_nav = buddypress()->bp_options_nav;
  17      }
  18  
  19  	public function tearDown() {
  20          buddypress()->bp_nav = $this->bp_nav;
  21          buddypress()->bp_options_nav = $this->bp_options_nav;
  22          parent::tearDown();
  23      }
  24  
  25  	protected function create_nav_items() {
  26          bp_core_new_nav_item( array(
  27              'name'                => 'Foo',
  28              'slug'                => 'foo',
  29              'position'            => 25,
  30              'screen_function'     => 'foo_screen_function',
  31              'default_subnav_slug' => 'foo-subnav'
  32          ) );
  33  
  34          bp_core_new_subnav_item( array(
  35              'name'            => 'Foo Subnav',
  36              'slug'            => 'foo-subnav',
  37              'parent_url'      => 'example.com/foo',
  38              'parent_slug'     => 'foo',
  39              'screen_function' => 'foo_screen_function',
  40              'position'        => 10
  41          ) );
  42      }
  43  
  44      /**
  45       * Create a group, set up nav item, and go to the group.
  46       */
  47  	protected function set_up_group() {
  48          $g = self::factory()->group->create( array(
  49              'slug' => 'testgroup',
  50          ) );
  51  
  52          $group = groups_get_group( $g );
  53          $group_permalink = bp_get_group_permalink( $group );
  54  
  55          $this->go_to( $group_permalink );
  56  
  57          bp_core_new_subnav_item( array(
  58              'name'            => 'Foo',
  59              'slug'            => 'foo',
  60              'parent_url'      => $group_permalink,
  61              'parent_slug'     => 'testgroup',
  62              'screen_function' => 'foo_screen_function',
  63              'position'        => 10
  64          ), 'groups' );
  65      }
  66  
  67  	public function test_bp_nav_isset() {
  68          $this->create_nav_items();
  69  
  70          $bp = buddypress();
  71  
  72          $this->assertTrue( isset( $bp->bp_nav ) );
  73          $this->assertTrue( isset( $bp->bp_nav['foo'] ) );
  74          $this->assertTrue( isset( $bp->bp_nav['foo']['name'] ) );
  75      }
  76  
  77  	public function test_bp_nav_unset() {
  78          $this->create_nav_items();
  79  
  80          $bp = buddypress();
  81  
  82          // No support for this - it would create a malformed nav item.
  83          /*
  84          unset( $bp->bp_nav['foo']['css_id'] );
  85          $this->assertFalse( isset( $bp->bp_nav['foo']['css_id'] ) );
  86          */
  87  
  88          unset( $bp->bp_nav['foo'] );
  89          $this->assertFalse( isset( $bp->bp_nav['foo'] ) );
  90      }
  91  
  92  	public function test_bp_nav_get() {
  93          $this->create_nav_items();
  94  
  95          $bp = buddypress();
  96  
  97          $foo = $bp->bp_nav['foo'];
  98          $this->assertSame( 'Foo', $foo['name'] );
  99  
 100          $this->assertSame( 'Foo', $bp->bp_nav['foo']['name'] );
 101      }
 102  
 103  	public function test_bp_nav_set() {
 104          $this->create_nav_items();
 105  
 106          $bp = buddypress();
 107  
 108          $bp->bp_nav['foo']['name'] = 'Bar';
 109  
 110          $nav = bp_get_nav_menu_items();
 111  
 112          foreach ( $nav as $_nav ) {
 113              if ( 'foo' === $_nav->css_id ) {
 114                  $found = $_nav;
 115                  break;
 116              }
 117          }
 118  
 119          $this->assertSame( 'Bar', $found->name );
 120      }
 121  
 122  	public function test_bp_options_nav_isset() {
 123          $this->create_nav_items();
 124  
 125          $bp = buddypress();
 126  
 127          $this->assertTrue( isset( $bp->bp_options_nav ) );
 128          $this->assertTrue( isset( $bp->bp_options_nav['foo'] ) );
 129          $this->assertTrue( isset( $bp->bp_options_nav['foo']['foo-subnav'] ) );
 130          $this->assertTrue( isset( $bp->bp_options_nav['foo']['foo-subnav']['name'] ) );
 131      }
 132  
 133  	public function test_bp_options_nav_unset() {
 134          $this->create_nav_items();
 135  
 136          $bp = buddypress();
 137  
 138          // No support for this - it would create a malformed nav item.
 139          /*
 140          unset( $bp->bp_options_nav['foo']['foo-subnav']['user_has_access'] );
 141          $this->assertFalse( isset( $bp->bp_options_nav['foo']['foo-subnav']['user_has_access'] ) );
 142          */
 143  
 144          unset( $bp->bp_options_nav['foo']['foo-subnav'] );
 145          $this->assertFalse( isset( $bp->bp_options_nav['foo']['foo-subnav'] ) );
 146  
 147          // Make sure the parent nav hasn't been wiped out.
 148          $this->assertTrue( isset( $bp->bp_options_nav['foo'] ) );
 149  
 150          unset( $bp->bp_options_nav['foo'] );
 151          $this->assertFalse( isset( $bp->bp_options_nav['foo'] ) );
 152      }
 153  
 154  	public function test_bp_options_nav_get() {
 155          $this->create_nav_items();
 156  
 157          $bp = buddypress();
 158  
 159          $foo_subnav = $bp->bp_options_nav['foo']['foo-subnav'];
 160          $this->assertSame( 'Foo Subnav', $foo_subnav['name'] );
 161  
 162          $this->assertSame( 'Foo Subnav', $bp->bp_options_nav['foo']['foo-subnav']['name'] );
 163      }
 164  
 165  	public function test_bp_options_nav_set() {
 166          $this->create_nav_items();
 167  
 168          $bp = buddypress();
 169  
 170          $bp->bp_options_nav['foo']['foo-subnav']['name'] = 'Bar';
 171          $nav = bp_get_nav_menu_items();
 172  
 173          foreach ( $nav as $_nav ) {
 174              if ( 'foo-subnav' === $_nav->css_id ) {
 175                  $found = $_nav;
 176                  break;
 177              }
 178          }
 179  
 180          $this->assertSame( 'Bar', $found->name );
 181  
 182          $subnav = array(
 183              'name' => 'Bar',
 184              'css_id' => 'bar-id',
 185              'link' => 'bar-link',
 186              'slug' => 'bar-slug',
 187              'user_has_access' => true,
 188          );
 189          $bp->bp_options_nav['foo']['foo-subnav'] = $subnav;
 190          $nav = bp_get_nav_menu_items();
 191  
 192          foreach ( $nav as $_nav ) {
 193              if ( 'bar-id' === $_nav->css_id ) {
 194                  $found = $_nav;
 195                  break;
 196              }
 197          }
 198  
 199          $this->assertSame( 'Bar', $found->name );
 200      }
 201  
 202      /**
 203       * @group groups
 204       */
 205  	public function test_bp_options_nav_isset_group_nav() {
 206          $this->set_up_group();
 207  
 208          $bp = buddypress();
 209  
 210          $this->assertTrue( isset( $bp->bp_options_nav ) );
 211          $this->assertTrue( isset( $bp->bp_options_nav['testgroup'] ) );
 212          $this->assertTrue( isset( $bp->bp_options_nav['testgroup']['foo'] ) );
 213          $this->assertTrue( isset( $bp->bp_options_nav['testgroup']['foo']['name'] ) );
 214      }
 215  
 216      /**
 217       * @group groups
 218       */
 219  	public function test_bp_options_nav_unset_group_nav() {
 220          $this->set_up_group();
 221  
 222          $bp = buddypress();
 223  
 224          // No support for this - it would create a malformed nav item.
 225          /*
 226          unset( $bp->bp_options_nav['testgroup']['foo']['user_has_access'] );
 227          $this->assertFalse( isset( $bp->bp_options_nav['testgroup']['foo']['user_has_access'] ) );
 228          */
 229  
 230          unset( $bp->bp_options_nav['testgroup']['foo'] );
 231          $this->assertFalse( isset( $bp->bp_options_nav['testgroup']['foo'] ) );
 232  
 233          unset( $bp->bp_options_nav['testgroup'] );
 234          $this->assertFalse( isset( $bp->bp_options_nav['testgroup'] ) );
 235      }
 236  
 237      /**
 238       * @group groups
 239       */
 240  	public function test_bp_options_nav_get_group_nav() {
 241          $this->set_up_group();
 242  
 243          $bp = buddypress();
 244  
 245          $foo = $bp->bp_options_nav['testgroup']['foo'];
 246          $this->assertSame( 'Foo', $foo['name'] );
 247  
 248          $this->assertSame( 'Foo', $bp->bp_options_nav['testgroup']['foo']['name'] );
 249      }
 250  
 251      /**
 252       * @group groups
 253       */
 254  	public function test_bp_options_nav_set_group_nav() {
 255          $this->set_up_group();
 256  
 257          $bp = buddypress();
 258  
 259          $bp->bp_options_nav['testgroup']['foo']['name'] = 'Bar';
 260          $nav = bp_get_nav_menu_items( 'groups' );
 261  
 262          foreach ( $nav as $_nav ) {
 263              if ( 'foo' === $_nav->css_id ) {
 264                  $found = $_nav;
 265                  break;
 266              }
 267          }
 268  
 269          $this->assertSame( 'Bar', $found->name );
 270  
 271          $subnav = array(
 272              'name' => 'Bar',
 273              'css_id' => 'bar-id',
 274              'link' => 'bar-link',
 275              'slug' => 'bar-slug',
 276              'user_has_access' => true,
 277          );
 278          $bp->bp_options_nav['testgroup']['foo'] = $subnav;
 279          $nav = bp_get_nav_menu_items( 'groups' );
 280  
 281          foreach ( $nav as $_nav ) {
 282              if ( 'bar-id' === $_nav->css_id ) {
 283                  $found = $_nav;
 284                  break;
 285              }
 286          }
 287  
 288          $this->assertSame( 'Bar', $found->name );
 289      }
 290  
 291      /**
 292       * @group groups
 293       */
 294      public function test_bp_core_new_subnav_item_should_work_in_group_context() {
 295          $this->set_up_group();
 296  
 297          bp_core_new_subnav_item( array(
 298              'name' => 'Foo Subnav',
 299              'slug' => 'foo-subnav',
 300              'parent_slug' => bp_get_current_group_slug(),
 301              'parent_url' => bp_get_group_permalink( groups_get_current_group() ),
 302              'screen_function' => 'foo_subnav',
 303          ) );
 304  
 305          $bp = buddypress();
 306  
 307          // Touch bp_nav since we told PHPUnit it was expectedDeprecated.
 308          $f = $bp->bp_options_nav[ bp_get_current_group_slug() ];
 309  
 310          $nav = bp_get_nav_menu_items( 'groups' );
 311  
 312          foreach ( $nav as $_nav ) {
 313              if ( 'foo-subnav' === $_nav->css_id ) {
 314                  $found = $_nav;
 315                  break;
 316              }
 317          }
 318  
 319          $this->assertSame( 'Foo Subnav', $found->name );
 320      }
 321  }


Generated: Sun Jun 25 01:01:25 2023 Cross-referenced by PHPXref 0.7.1