Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/07/2023 04:28:08 AM (14 months ago)
Author:
imath
Message:

BP Rewrites: Introduce the bp_members_get_user_url() function

As many member URLs are built concatenating bp_core_get_user_domain()
with URL chunks, the safer way to make sure developers update the way they
build their member URLs in favor of using BP Rewrites is:

  1. to deprecate this function
  2. create a new function bp_members_get_user_url() which is a wrapper of

bp_rewrites_get_url()

  1. replace all bp_core_get_user_domain() occurrences by

bp_members_get_user_url()

This commit also deprecates bp_core_get_username() in favor of the new
bp_members_get_user_slug() function and updates PHPUnit tests.

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/70
See #4954

File:
1 edited

Legend:

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

    r13414 r13433  
    77#[AllowDynamicProperties]
    88class BP_Tests_Activity_Notifications extends BP_UnitTestCase {
     9    protected $permalink_structure = '';
    910    protected $current_user;
    1011    protected $u1;
     
    1516    public function set_up() {
    1617        parent::set_up();
     18        $this->permalink_structure = get_option( 'permalink_structure', '' );
    1719        $this->current_user = get_current_user_id();
    1820        $this->u1 = self::factory()->user->create();
     
    3133    public function tear_down() {
    3234        $this->set_current_user( $this->current_user );
     35        $this->set_permalink_structure( $this->permalink_structure );
     36
    3337        parent::tear_down();
    3438
     
    4347    public function test_bp_activity_remove_screen_notifications_on_single_activity_permalink() {
    4448        $this->create_notifications();
     49        $this->set_permalink_structure( '/%postname%/' );
    4550
    4651        $notifications = BP_Notifications_Notification::get( array(
     
    5257
    5358        // Go to the activity permalink page
    54         $this->go_to( bp_core_get_user_domain( $this->u1 ) . 'activity/' . $this->a1 );
     59        $this->go_to(
     60            bp_members_get_user_url(
     61                $this->u1,
     62                array(
     63                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_activity', bp_get_activity_slug() ),
     64                    'single_item_action'    => $this->a1,
     65                )
     66            )
     67        );
    5568
    5669        $notifications = BP_Notifications_Notification::get( array(
     
    6881    public function test_bp_activity_remove_screen_notifications_on_single_activity_permalink_logged_out() {
    6982        $this->create_notifications();
     83        $this->set_permalink_structure( '/%postname%/' );
    7084
    7185        $notifications = BP_Notifications_Notification::get( array(
     
    8094
    8195        // Go to the activity permalink page
    82         $this->go_to( bp_core_get_user_domain( $this->u1 ) . 'activity/' . $this->a1 );
     96        $this->go_to(
     97            bp_members_get_user_url(
     98                $this->u1,
     99                array(
     100                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_activity', bp_get_activity_slug() ),
     101                    'single_item_action'    => $this->a1,
     102                )
     103            )
     104        );
    83105
    84106        $notifications = BP_Notifications_Notification::get( array(
     
    98120    public function test_bp_activity_remove_screen_notifications_on_single_activity_permalink_wrong_user() {
    99121        $this->create_notifications();
     122        $this->set_permalink_structure( '/%postname%/' );
    100123
    101124        $notifications = BP_Notifications_Notification::get( array(
     
    110133
    111134        // Go to the activity permalink page
    112         $this->go_to( bp_core_get_user_domain( $this->u1 ) . 'activity/' . $this->a1 );
     135        $this->go_to(
     136            bp_members_get_user_url(
     137                $this->u1,
     138                array(
     139                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_activity', bp_get_activity_slug() ),
     140                    'single_item_action'    => $this->a1,
     141                )
     142            )
     143        );
    113144
    114145        $notifications = BP_Notifications_Notification::get( array(
     
    128159    public function test_bp_activity_remove_screen_notifications_on_mentions() {
    129160        $this->create_notifications();
     161        $this->set_permalink_structure( '/%postname%/' );
    130162
    131163        $notifications = BP_Notifications_Notification::get( array(
     
    137169
    138170        // Go to the My Activity page
    139         $this->go_to( bp_core_get_user_domain( $this->u1 ) . bp_get_activity_slug() . '/mentions/' );
     171        $this->go_to(
     172            bp_members_get_user_url(
     173                $this->u1,
     174                array(
     175                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_activity', bp_get_activity_slug() ),
     176                    'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_activity_mentions', 'mentions' ),
     177                )
     178            )
     179        );
    140180
    141181        $notifications = BP_Notifications_Notification::get( array(
     
    153193    public function test_bp_activity_remove_screen_notifications_on_mentions_logged_out() {
    154194        $this->create_notifications();
     195        $this->set_permalink_structure( '/%postname%/' );
    155196
    156197        $notifications = BP_Notifications_Notification::get( array(
     
    165206
    166207        // Go to the My Activity page
    167         $this->go_to( bp_core_get_user_domain( $this->u1 ) . bp_get_activity_slug() . '/mentions/' );
     208        $this->go_to(
     209            bp_members_get_user_url(
     210                $this->u1,
     211                array(
     212                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_activity', bp_get_activity_slug() ),
     213                    'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_activity_mentions', 'mentions' ),
     214                )
     215            )
     216        );
    168217
    169218        $notifications = BP_Notifications_Notification::get( array(
     
    184233    public function test_bp_activity_remove_screen_notifications_on_mentions_wrong_user() {
    185234        $this->create_notifications();
     235        $this->set_permalink_structure( '/%postname%/' );
    186236
    187237        $notifications = BP_Notifications_Notification::get( array(
     
    196246
    197247        // Go to the My Activity page
    198         $this->go_to( bp_core_get_user_domain( $this->u1 ) . bp_get_activity_slug() . '/mentions/' );
     248        $this->go_to(
     249            bp_members_get_user_url(
     250                $this->u1,
     251                array(
     252                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_activity', bp_get_activity_slug() ),
     253                    'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_activity_mentions', 'mentions' ),
     254                )
     255            )
     256        );
    199257
    200258        $notifications = BP_Notifications_Notification::get( array(
     
    215273    public function test_bp_activity_at_mention_delete_notification() {
    216274        $this->create_notifications();
     275        $this->set_permalink_structure( '/%postname%/' );
    217276
    218277        $notifications = BP_Notifications_Notification::get( array(
Note: See TracChangeset for help on using the changeset viewer.