Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/26/2021 01:29:03 AM (3 years ago)
Author:
espellcaste
Message:

Adding the newly created helper functions bp_get_group_by and bp_get_group for Groups related functions
and template files.

Also, adding several PHP fixes/tweaks. And unit tests.

Fixes #6749

File:
1 edited

Legend:

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

    r12744 r13097  
    55 */
    66class BP_Tests_Groups_Template extends BP_UnitTestCase {
     7
     8    public function setUp() {
     9        parent::setUp();
     10
     11        if ( isset( $GLOBALS['groups_template'] ) ) {
     12            $this->groups_template = $GLOBALS['groups_template'];
     13        }
     14    }
     15
     16    public function tearDown() {
     17        if ( $this->groups_template ) {
     18            $GLOBALS['groups_template'] = $this->groups_template;
     19        }
     20
     21        parent::tearDown();
     22    }
     23
    724    /**
    825     * Integration test to make sure meta_query is getting passed through
     
    951968
    952969    /**
     970     * @group bp_group_is_forum_enabled
     971     */
     972    public function test_bp_group_is_forum_enabled() {
     973        $g1 = $this->factory->group->create( array( 'enable_forum' => 0 ) );
     974        $g2 = $this->factory->group->create( array( 'enable_forum' => 1 ) );
     975
     976        $this->assertFalse( bp_group_is_forum_enabled( $g1 ) );
     977        $this->assertTrue( bp_group_is_forum_enabled( $g2 ) );
     978    }
     979
     980    /**
     981     * @group bp_get_group_member_is_banned
     982     */
     983    public function test_bp_group_member_is_banned() {
     984        $this->assertFalse( bp_get_group_member_is_banned() );
     985    }
     986
     987    /**
     988     * @group bp_get_group_member_id
     989     */
     990    public function test_bp_get_group_member_id() {
     991        $this->assertFalse( (bool) bp_get_group_member_id() );
     992    }
     993
     994    /**
     995     * @group bp_get_group_form_action
     996     */
     997    public function test_bp_bp_get_group_form_action_when_empty() {
     998        $this->assertEmpty( bp_get_group_form_action( '' ) );
     999    }
     1000
     1001    /**
     1002     * @group bp_get_group_form_action
     1003     */
     1004    public function test_bp_bp_get_group_form_action() {
     1005        $g   = $this->factory->group->create();
     1006        $p   = 2;
     1007        $url = trailingslashit( bp_get_group_permalink( $g ) . $p );
     1008
     1009        $this->assertSame( bp_get_group_form_action( $p, $g ), $url );
     1010    }
     1011
     1012    /**
    9531013     * @group bp_get_group_member_count
    9541014     */
    9551015    public function test_bp_get_group_member_count_0_members() {
    956         global $groups_template;
    957         $gt = $groups_template;
    958         $groups_template = new stdClass;
    959         $groups_template->group = new stdClass;
    960         $groups_template->group->total_member_count = 0;
    961 
    962         $found = bp_get_group_member_count();
    963 
    964         $groups_template = $gt;
    965 
    966         $this->assertSame( '0 members', $found );
     1016        $u = $this->factory->user->create();
     1017        $g = $this->factory->group->create( array( 'creator_id' => $u ) );
     1018
     1019        // Fake the current group.
     1020        $GLOBALS['groups_template'] = new stdClass;
     1021        $GLOBALS['groups_template']->group = groups_get_group( $g );
     1022
     1023        // Kick group creator.
     1024        wp_delete_user( $u );
     1025
     1026        $this->assertNotSame( '0 member', bp_get_group_member_count() );
    9671027    }
    9681028
     
    9711031     */
    9721032    public function test_bp_get_group_member_count_1_member() {
    973         global $groups_template;
    974         $gt = $groups_template;
    975         $groups_template = new stdClass;
    976         $groups_template->group = new stdClass;
    977         $groups_template->group->total_member_count = 1;
    978 
    979         $found = bp_get_group_member_count();
    980 
    981         $groups_template = $gt;
    982 
    983         $this->assertSame( '1 member', $found );
     1033        $g = $this->factory->group->create();
     1034
     1035        // Fake the current group.
     1036        $GLOBALS['groups_template'] = new stdClass;
     1037        $GLOBALS['groups_template']->group = groups_get_group( $g );
     1038
     1039        $this->assertSame( '1 member', bp_get_group_member_count() );
    9841040    }
    9851041
     
    9881044     */
    9891045    public function test_bp_get_group_member_count_2_members() {
    990         global $groups_template;
    991         $gt = $groups_template;
    992         $groups_template = new stdClass;
    993         $groups_template->group = new stdClass;
    994         $groups_template->group->total_member_count = 2;
    995 
    996         $found = bp_get_group_member_count();
    997 
    998         $groups_template = $gt;
    999 
    1000         $this->assertSame( '2 members', $found );
     1046        $u1 = $this->factory->user->create();
     1047        $u2 = $this->factory->user->create();
     1048        $g  = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     1049
     1050        $this->add_user_to_group( $u2, $g );
     1051
     1052        // Fake the current group.
     1053        $GLOBALS['groups_template'] = new stdClass;
     1054        $GLOBALS['groups_template']->group = groups_get_group( $g );
     1055
     1056        $this->assertSame( '2 members', bp_get_group_member_count() );
    10011057    }
    10021058
Note: See TracChangeset for help on using the changeset viewer.