Skip to:
Content

BuddyPress.org

Changeset 9405


Ignore:
Timestamp:
01/28/2015 10:39:33 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Add unit tests for bp_has_activities() to test results with different group privacies. Props imath. See #6169.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/activity/template.php

    r9372 r9405  
    859859
    860860        /**
     861         * @ticket BP6169
     862         * @group bp_has_activities
     863         */
     864        public function test_bp_has_activities_private_group_home_scope() {
     865                global $activities_template;
     866                $bp = buddypress();
     867                $reset_current_group = $bp->groups->current_group;
     868                $reset_current_action = $bp->current_action;
     869
     870                $u1 = $this->factory->user->create();
     871                $u2 = $this->factory->user->create();
     872                $u3 = $this->factory->user->create();
     873
     874                $this->set_current_user( $u1 );
     875
     876                $g = $this->factory->group->create( array(
     877                        'status' => 'private',
     878                ) );
     879
     880                groups_join_group( $g, $u2 );
     881                groups_join_group( $g, $u3 );
     882
     883                $a1 = $this->factory->activity->create( array(
     884                        'component' => $bp->groups->id,
     885                        'item_id'   => $g,
     886                        'type'      => 'activity_update',
     887                        'user_id'   => $u2,
     888                        'content'   => 'foo bar',
     889                ) );
     890
     891                $a2 = $this->factory->activity->create( array(
     892                        'component' => $bp->groups->id,
     893                        'item_id'   => $g,
     894                        'type'      => 'activity_update',
     895                        'user_id'   => $u3,
     896                        'content'   => 'bar foo',
     897                ) );
     898
     899                $bp->groups->current_group = groups_get_group( array(
     900                        'group_id'        => $g,
     901                        'populate_extras' => true,
     902                ) );
     903
     904                // On group's home the scope is set to 'home'
     905                $bp->current_action = 'home';
     906
     907                bp_has_activities( array( 'action' => 'activity_update' ) );
     908
     909                $this->assertEqualSets( array( $a1, $a2 ), wp_list_pluck( $activities_template->activities, 'id' ) );
     910
     911                // clean up!
     912                $activities_template = null;
     913                $bp->groups->current_group = $reset_current_group;
     914                $bp->current_action = $reset_current_action;
     915        }
     916
     917        /**
     918         * @ticket BP6169
     919         * @group bp_has_activities
     920         */
     921        public function test_bp_has_activities_hidden_group_home_scope() {
     922                global $activities_template;
     923                $bp = buddypress();
     924                $reset_current_group = $bp->groups->current_group;
     925                $reset_current_action = $bp->current_action;
     926
     927                $u1 = $this->factory->user->create();
     928                $u2 = $this->factory->user->create();
     929                $u3 = $this->factory->user->create();
     930
     931                $this->set_current_user( $u1 );
     932
     933                $g = $this->factory->group->create( array(
     934                        'status' => 'hidden',
     935                ) );
     936
     937                groups_join_group( $g, $u2 );
     938                groups_join_group( $g, $u3 );
     939
     940                $a1 = $this->factory->activity->create( array(
     941                        'component' => $bp->groups->id,
     942                        'item_id'   => $g,
     943                        'type'      => 'activity_update',
     944                        'user_id'   => $u2,
     945                        'content'   => 'foo bar',
     946                ) );
     947
     948                $a2 = $this->factory->activity->create( array(
     949                        'component' => $bp->groups->id,
     950                        'item_id'   => $g,
     951                        'type'      => 'activity_update',
     952                        'user_id'   => $u3,
     953                        'content'   => 'bar foo',
     954                ) );
     955
     956                $bp->groups->current_group = groups_get_group( array(
     957                        'group_id'        => $g,
     958                        'populate_extras' => true,
     959                ) );
     960
     961                // On group's home the scope is set to 'home'
     962                $bp->current_action = 'home';
     963
     964                bp_has_activities( array( 'action' => 'activity_update' ) );
     965
     966                $this->assertEqualSets( array( $a1, $a2 ), wp_list_pluck( $activities_template->activities, 'id' ) );
     967
     968                // clean up!
     969                $activities_template = null;
     970                $bp->groups->current_group = $reset_current_group;
     971                $bp->current_action = $reset_current_action;
     972        }
     973
     974        /**
    861975         * Integration test for 'meta_query' param
    862976         */
Note: See TracChangeset for help on using the changeset viewer.