Skip to:
Content

BuddyPress.org

Changeset 10905


Ignore:
Timestamp:
06/27/2016 03:07:47 AM (8 years ago)
Author:
imath
Message:

Groups: Make sure BP_Group_Extension::widget_display() can be used

On the single item home (eg: a custom front template), it will now be possible to use bp_custom_group_boxes() to get the content provided by the Group extensions in their widget.

2 unit tests are checking this only happens when on the Groups single item home.

Fixes #7131

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-group-extension.php

    r10745 r10905  
    764764
    765765        // Hook the group home widget.
    766         if ( ! bp_current_action() && bp_is_current_action( 'home' ) ) {
     766        if ( bp_is_group_home() ) {
    767767            add_action( $this->display_hook, array( &$this, 'widget_display' ) );
    768768        }
  • trunk/tests/phpunit/assets/group-extensions.php

    r9819 r10905  
    410410    }
    411411}
     412
     413class BPTest_Group_Extension_Widget_Method extends BP_Group_Extension {
     414    public function __construct() {
     415        $class_name = get_class( $this );
     416
     417        $args = array(
     418            'name' => $class_name,
     419            'slug' => sanitize_title( $class_name ),
     420        );
     421
     422        parent::init( $args );
     423    }
     424
     425    public function widget_display() {
     426        echo 'Widget Displayed';
     427    }
     428}
  • trunk/tests/phpunit/testcases/groups/class-bp-group-extension.php

    r10745 r10905  
    846846        $this->set_current_user( $old_current_user );
    847847    }
     848
     849    /**
     850     * @ticket BP7131
     851     */
     852    public function test_widget_on_group_home_page() {
     853        $g = $this->factory->group->create( array(
     854            'status' => 'public',
     855        ) );
     856        $g_obj = groups_get_group( array( 'group_id' => $g ) );
     857
     858        $this->go_to( bp_get_group_permalink( $g_obj ) );
     859
     860        $e1 = new BPTest_Group_Extension_Widget_Method();
     861        $e1->_register();
     862
     863        ob_start();
     864        bp_custom_group_boxes();
     865        $content = ob_get_clean();
     866
     867        $this->assertTrue( $content === 'Widget Displayed' );
     868    }
     869
     870    /**
     871     * @ticket BP7131
     872     */
     873    public function test_widget_on_group_members_page() {
     874        $g = $this->factory->group->create( array(
     875            'status' => 'public',
     876        ) );
     877        $g_obj = groups_get_group( array( 'group_id' => $g ) );
     878
     879        $this->go_to( trailingslashit( bp_get_group_permalink( $g_obj ) ) . 'members/' );
     880
     881        $e1 = new BPTest_Group_Extension_Widget_Method();
     882        $e1->_register();
     883
     884        ob_start();
     885        bp_custom_group_boxes();
     886        $content = ob_get_clean();
     887
     888        $this->assertFalse( $content === 'Widget Displayed' );
     889    }
    848890}
Note: See TracChangeset for help on using the changeset viewer.