Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/08/2023 06:31:46 AM (2 years ago)
Author:
imath
Message:

Make sure all Groups component URLs are built using BP rewrites API

  • Introduce the bp_groups_get_create_url() to ease Groups create URLs generation.
  • Improve bp_groups_get_path_chunks() to deal with front-end group admin URLs and the Groups create URLs.
  • Deprecate bp_get_groups_directory_permalink() in favor of bp_get_groups_directory_url().
  • Replace all remaining deprecated functions usage.
  • Start putting deprecated functions behind a function_exists( 'bp_classic' ) check, corresponding functions were added inside the BP Classic backcompat plugin.
  • Adjust some Groups routing unit tests.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

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

    r13448 r13449  
    5656        $this->set_permalink_structure( '/%postname%/' );
    5757        bp_groups_register_group_type( 'foo' );
    58         $this->go_to( bp_get_groups_directory_permalink() . 'type/foo/' );
     58        $this->go_to(
     59            bp_get_groups_directory_url(
     60                array(
     61                    'directory_type' => 'foo',
     62                )
     63            )
     64        );
    5965        $this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foo', 0 ) );
    6066    }
     
    6672        $this->set_permalink_structure( '/%postname%/' );
    6773        bp_groups_register_group_type( 'foo', array( 'has_directory' => 'foos' ) );
    68         $this->go_to( bp_get_groups_directory_permalink() . 'type/foos/' );
     74        $this->go_to(
     75            bp_get_groups_directory_url(
     76                array(
     77                    'directory_type' => 'foos',
     78                )
     79            )
     80        );
    6981        $this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foos', 0 ) );
    7082    }
     
    7688        $this->set_permalink_structure( '/%postname%/' );
    7789        bp_groups_register_group_type( 'taz', array( 'has_directory' => false ) );
    78         $this->go_to( bp_get_groups_directory_permalink() . 'type/taz/' );
     90        $this->go_to(
     91            bp_get_groups_directory_url(
     92                array(
     93                    'directory_type' => 'taz',
     94                )
     95            )
     96        );
    7997        $this->assertEmpty( bp_get_current_group_directory_type() );
    8098    }
     
    85103    public function test_group_directory_should_404_for_invalid_group_types() {
    86104        $this->set_permalink_structure( '/%postname%/' );
    87         $this->go_to( bp_get_groups_directory_permalink() . 'type/zat/' );
     105        $this->go_to(
     106            bp_get_groups_directory_url(
     107                array(
     108                    'directory_type' => 'zat',
     109                )
     110            )
     111        );
    88112        $this->assertEmpty( bp_get_current_group_directory_type() );
    89113    }
     
    94118    public function test_group_previous_slug_current_slug_should_resolve() {
    95119        $this->set_permalink_structure( '/%postname%/' );
    96         $g1 = self::factory()->group->create( array(
    97             'slug' => 'george',
    98         ) );
    99         groups_edit_base_group_details( array(
    100             'group_id' => $g1,
    101             'slug'     => 'ralph',
    102         ) );
    103 
    104         $this->go_to( bp_get_groups_directory_permalink() . 'ralph' );
    105 
     120        $g1 = self::factory()->group->create(
     121            array(
     122                'slug' => 'george',
     123            )
     124        );
     125
     126        groups_edit_base_group_details(
     127            array(
     128                'group_id' => $g1,
     129                'slug'     => 'ralph',
     130            )
     131        );
     132
     133        $this->go_to( bp_get_group_url( $g1 ) );
     134        $this->assertEquals( groups_get_current_group()->slug, 'ralph' );
     135    }
     136
     137    /**
     138     * @group group_previous_slug
     139     */
     140    public function test_group_previous_slug_should_resolve() {
     141        $this->set_permalink_structure( '/%postname%/' );
     142        $g1 = self::factory()->group->create(
     143            array(
     144                'slug' => 'george',
     145            )
     146        );
     147
     148        groups_edit_base_group_details(
     149            array(
     150                'group_id'       => $g1,
     151                'slug'           => 'sam!',
     152                'notify_members' => false,
     153            )
     154        );
     155
     156        $url = bp_rewrites_get_url(
     157            array(
     158                'component_id' => 'groups',
     159                'single_item'  => 'george',
     160            )
     161        );
     162
     163        $this->go_to( $url );
    106164        $this->assertEquals( $g1, bp_get_current_group_id() );
    107165    }
     
    109167    /**
    110168     * @group group_previous_slug
    111      */
    112     public function test_group_previous_slug_should_resolve() {
    113         $this->set_permalink_structure( '/%postname%/' );
    114         $g1 = self::factory()->group->create( array(
    115             'slug' => 'george',
    116         ) );
    117 
    118         groups_edit_base_group_details( array(
    119             'group_id'       => $g1,
    120             'slug'           => 'sam!',
    121             'notify_members' => false,
    122         ) );
    123         $this->go_to( bp_get_groups_directory_permalink() . 'george' );
    124 
    125         $this->assertEquals( $g1, bp_get_current_group_id() );
    126     }
    127 
    128     /**
    129      * @group group_previous_slug
     169     * @group imath
    130170     */
    131171    public function test_group_previous_slug_most_recent_takes_precedence() {
    132172        $this->set_permalink_structure( '/%postname%/' );
    133         $g1 = self::factory()->group->create( array(
    134             'slug' => 'george',
    135         ) );
    136         groups_edit_base_group_details( array(
    137             'group_id'       => $g1,
    138             'slug'           => 'ralph',
    139             'notify_members' => false,
    140         ) );
    141         $g2 = self::factory()->group->create( array(
    142             'slug' => 'george',
    143         ) );
    144         groups_edit_base_group_details( array(
    145             'group_id'       => $g2,
    146             'slug'           => 'sam',
    147             'notify_members' => false,
    148         ) );
    149 
    150         $this->go_to( bp_get_groups_directory_permalink() . 'george' );
     173        $g1 = self::factory()->group->create(
     174            array(
     175                'slug' => 'george',
     176            )
     177        );
     178
     179        groups_edit_base_group_details(
     180            array(
     181                'group_id'       => $g1,
     182                'slug'           => 'ralph',
     183                'notify_members' => false,
     184            )
     185        );
     186
     187        $g2 = self::factory()->group->create(
     188            array(
     189                'slug' => 'george',
     190            )
     191        );
     192
     193        groups_edit_base_group_details(
     194            array(
     195                'group_id'       => $g2,
     196                'slug'           => 'sam',
     197                'notify_members' => false,
     198            )
     199        );
     200
     201        $url = bp_rewrites_get_url(
     202            array(
     203                'component_id' => 'groups',
     204                'single_item'  => 'george',
     205            )
     206        );
     207
     208        $this->go_to( $url );
    151209        $this->assertEquals( $g2, bp_get_current_group_id() );
    152210    }
Note: See TracChangeset for help on using the changeset viewer.