Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/11/2019 01:33:14 PM (5 years ago)
Author:
imath
Message:

Improve i18n of Groups activity updates action string

Dynamically generated activity action strings were introduced in BuddyPress 2.0 to ensure these strings are always up to date and multilingual-friendly (see #3856).

It appeared although the activity_update type enjoys this feature when activities are shared by users on their profiles, it was not the case for activity updates posted within Groups.

Thanks to this commit, BuddyPress is now taking it in charge by:

  • Registering a new group activity action to reference a specific formatting callback function for activities posted within Groups.
  • Making sure this new activity action type does not interfere with the one of regular activity updates in dropdown filters or into the Activity Administration screens.

BTW happy 4th WPTranslationDay to everyone :)

Fixes #8089

File:
1 edited

Legend:

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

    r12393 r12395  
    66 */
    77class BP_Tests_Groups_Activity extends BP_UnitTestCase {
     8    protected $groups_post_update_args;
     9
    810    /**
    911     * @group activity_action
     
    223225
    224226        $this->set_current_user( $old_user );
     227    }
     228
     229    /**
     230     * @group activity_action
     231     * @group bp_groups_format_activity_action_group_activity_update
     232     */
     233    public function test_bp_groups_format_activity_action_group_activity_update() {
     234        $u = self::factory()->user->create();
     235        $g = self::factory()->group->create();
     236        $a = self::factory()->activity->create( array(
     237            'component' => buddypress()->groups->id,
     238            'type' => 'activity_update',
     239            'user_id' => $u,
     240            'item_id' => $g,
     241        ) );
     242
     243        $a_obj = new BP_Activity_Activity( $a );
     244        $g_obj = groups_get_group( $g );
     245
     246        $expected = sprintf( esc_html__( '%1$s posted an update in the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ),  '<a href="' . esc_url( bp_get_group_permalink( $g_obj ) ) . '">' . esc_html( $g_obj->name ) . '</a>' );
     247
     248        $this->assertSame( $expected, $a_obj->action );
     249    }
     250
     251    /**
     252     * @group groups_post_update
     253     */
     254    public function test_groups_post_update() {
     255        $u = self::factory()->user->create();
     256        $g = self::factory()->group->create();
     257
     258        // The user is a group member.
     259        groups_join_group( $g, $u );
     260
     261        $activity_args = array(
     262            'content'    => 'Test group_post_update',
     263            'user_id'    => $u,
     264            'group_id'   => $g,
     265            'error_type' => 'wp_error',
     266        );
     267
     268        add_filter( 'bp_before_groups_record_activity_parse_args', array( $this, 'groups_post_update_args' ), 10, 1 );
     269
     270        groups_post_update( $activity_args );
     271
     272        remove_filter( 'bp_before_groups_record_activity_parse_args', array( $this, 'groups_post_update_args' ), 10, 1 );
     273
     274        $expected = array_merge( $activity_args, array( 'item_id' => $g ) );
     275        unset( $expected['group_id'] );
     276
     277        $this->assertEquals( $expected, $this->groups_post_update_args );
     278    }
     279
     280    /**
     281     * @group groups_post_update
     282     */
     283    public function test_groups_post_update_in_group() {
     284        $bp = buddypress();
     285        $u  = self::factory()->user->create();
     286        $g  = self::factory()->group->create();
     287
     288        // The user is a group member.
     289        groups_join_group( $g, $u );
     290
     291        $bp->groups->current_group = groups_get_group( $g );
     292
     293        $activity_args = array(
     294            'content' => 'Test group_post_update in a group',
     295            'user_id' => $u,
     296        );
     297
     298        $a = groups_post_update( $activity_args );
     299        $a_obj = new BP_Activity_Activity( $a );
     300
     301        $this->assertSame( $a_obj->item_id, $g );
     302        $this->assertSame( $a_obj->component, 'groups' );
     303
     304        unset( $bp->groups->current_group );
    225305    }
    226306
     
    263343        $this->set_current_user( $old_user );
    264344    }
     345
     346    public function groups_post_update_args( $args = array() ) {
     347        $this->groups_post_update_args = array_intersect_key( $args, array(
     348            'content'    => true,
     349            'user_id'    => true,
     350            'item_id'    => true,
     351            'error_type' => true,
     352        ) );
     353
     354        return $args;
     355    }
    265356}
Note: See TracChangeset for help on using the changeset viewer.