Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/23/2023 07:35:38 PM (4 years ago)
Author:
imath
Message:

Make BP_Core_Nav generate "BP Rewrites ready" navigation links

  • Remove all components $parent_url attributes when setting sub nav items.
  • Only use the bp_core_create_nav_link() $link attribute argument & the bp_core_create_subnav_link() $parent_url attribute argument if specified to preserve backward compatibility.
  • Migrates the Community search feature so that it uses BP Rewrites.
  • Perform some bp_loggedin_user_domain() in favor of bp_loggedin_user_url().
  • Update some PHPUnit tests.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/nav/bpCoreNewSubnavItem.php

    r13433 r13441  
    55 */
    66class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase {
     7        protected $permalink_structure = '';
     8
     9        public function set_up() {
     10                parent::set_up();
     11                $this->permalink_structure = get_option( 'permalink_structure', '' );
     12        }
     13
     14        public function tear_down() {
     15                $this->set_permalink_structure( $this->permalink_structure );
     16
     17                parent::tear_down();
     18        }
    719
    820        /**
    … …  
    1022         */
    1123        public function test_user_subnav() {
     24                $this->set_permalink_structure( '/%postname%/' );
    1225                $bp_options_nav = buddypress()->bp_options_nav;
    1326
    … …  
    1629                $this->set_current_user( $u );
    1730
    18                 $user_domain = bp_members_get_user_url( $u );
    19 
    20                 $this->go_to( $user_domain );
     31                $this->go_to( bp_members_get_user_url( $u ) );
    2132
    2233                bp_core_new_nav_item( array(
    2334                        'name'            => 'Foo Parent',
    2435                        'slug'            => 'foo-parent',
    25                         'link'            => trailingslashit( $user_domain . 'foo-parent' ),
    2636                        'screen_function' => 'foo_screen_function',
    2737                        'position'        => 10,
    … …  
    3141                        'name'            => 'Foo',
    3242                        'slug'            => 'foo',
    33                         'parent_url'      => trailingslashit( $user_domain . 'foo-parent' ),
     43                        'parent_url'      => bp_members_get_user_url(
     44                                $u,
     45                                array(
     46                                        'single_item_component' => 'foo-parent',
     47                                )
     48                        ),
    3449                        'parent_slug'     => 'foo-parent',
    3550                        'screen_function' => 'foo_screen_function',
    … …  
    3954                $expected = array(
    4055                        'name'              => 'Foo',
    41                         'link'              => trailingslashit( $user_domain . 'foo-parent/foo' ),
     56                        'link'              => bp_members_get_user_url(
     57                                $u,
     58                                array(
     59                                        'single_item_component' => 'foo-parent',
     60                                        'single_item_action'    => 'foo',
     61                                )
     62                        ),
    4263                        'slug'              => 'foo',
    4364                        'css_id'            => 'foo',
    … …  
    6384                        'slug' => 'foo',
    6485                        'parent_slug' => 'foo',
    65                         'parent_url' => 'foo',
    6686                        'screen_function' => 'foo',
    6787                ) ) );
    … …  
    7191                        'name' => 'foo',
    7292                        'parent_slug' => 'foo',
    73                         'parent_url' => 'foo',
    7493                        'screen_function' => 'foo',
    7594                ) ) );
    … …  
    7998                        'name' => 'foo',
    8099                        'slug' => 'foo',
    81                         'parent_url' => 'foo',
    82                         'screen_function' => 'foo',
    83                 ) ) );
    84 
    85                 // 'parent_url'
    86                 $this->assertFalse( bp_core_new_subnav_item( array(
    87                         'name' => 'foo',
    88                         'slug' => 'foo',
    89                         'parent_slug' => 'foo',
    90100                        'screen_function' => 'foo',
    91101                ) ) );
    … …  
    96106                        'slug' => 'foo',
    97107                        'parent_slug' => 'foo',
    98                         'parent_url' => 'foo',
    99108                ) ) );
    100109        }
    … …  
    179188                        'name' => 'Foo',
    180189                        'slug' => 'foo',
     190                        'url' => 'http://example.com/foo/',
    181191                        'screen_function' => 'foo',
    182192                        'default_subnav_slug' => 'bar',
    … …  
    191201                ) );
    192202
    193                 $this->assertSame( 'http://example.com/foo/', buddypress()->bp_options_nav['foo']['bar']['link'] );
     203                $this->assertSame( 'http://example.com/foo/bar/', buddypress()->bp_options_nav['foo']['bar']['link'] );
    194204
    195205                // clean up
    … …  
    202212         */
    203213        public function test_should_trailingslash_link_when_link_is_autogenerated_using_slug() {
     214                $this->set_permalink_structure( '/%postname%/' );
    204215                bp_core_new_nav_item( array(
    205216                        'name' => 'Foo',
    … …  
    225236         */
    226237        public function test_should_trailingslash_link_when_link_is_autogenerated_not_using_slug() {
     238                $this->set_permalink_structure( '/%postname%/' );
    227239                bp_core_new_nav_item( array(
    228240                        'name' => 'foo',
    … …  
    241253                ) );
    242254
    243                 $expected = bp_get_root_domain() . '/foo-parent/';
     255                $expected = bp_get_root_domain() . '/foo-parent/bar/';
    244256                $this->assertSame( $expected, buddypress()->bp_options_nav['foo-parent']['bar']['link'] );
    245257        }
Note: See TracChangeset for help on using the changeset viewer.