Skip to:
Content

BuddyPress.org

Changeset 11147


Ignore:
Timestamp:
09/21/2016 11:07:33 PM (9 years ago)
Author:
r-a-y
Message:

Core: In bp_core_remove_nav_item(), fix notice when a nav item's screen function uses a class method as a callback.

Props needle, imath.

Fixes #7203.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-core-nav.php

    r10943 r11147  
    277277
    278278            // Return the deleted item's screen functions.
    279             return array_unique( $screen_functions );
     279            return $screen_functions;
    280280        }
    281281    }
  • trunk/tests/phpunit/testcases/core/nav/bpCoreRemoveNavItem.php

    r10745 r11147  
    6565        $bp->bp_options_nav = $_bp_options_nav;
    6666    }
     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, 2 );
     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    }
    67115}
Note: See TracChangeset for help on using the changeset viewer.