Skip to:
Content

BuddyPress.org

Ticket #7931: 7931.unit-test.patch

File 7931.unit-test.patch, 1.6 KB (added by r-a-y, 7 years ago)
  • tests/phpunit/testcases/core/nav/bpCoreNewSubnavItem.php

     
    335335
    336336                $this->assertSame( 'bar', buddypress()->bp_options_nav['parent']['foo']['css_id'] );
    337337        }
     338
     339        /**
     340         * @ticket BP7931
     341         */
     342        public function test_subnav_should_not_404_on_early_bp_setup_nav_priority() {
     343                $u = self::factory()->user->create();
     344                $old_current_user = get_current_user_id();
     345                $this->set_current_user( $u );
     346
     347                $user_domain = bp_core_get_user_domain( $u );
     348
     349                // Register a subnav on 'bp_setup_nav' hook early (at priority zero).
     350                add_action( 'bp_setup_nav', function() use ( $user_domain ) {
     351                        /*
     352                         * Emulate a subnav screen.
     353                         *
     354                         * The bp_core_load_template() call is imperative for our 404 check to work!
     355                         */
     356                        $screen = function() {
     357                                bp_core_load_template ('members/single/plugins');
     358                        };
     359
     360                        // Register the subnav.
     361                        bp_core_new_subnav_item( array (
     362                                'name'            => 'Testing',
     363                                'slug'            => 'testing',
     364                                'parent_url'      => $user_domain . bp_get_profile_slug (). '/',
     365                                'parent_slug'     => bp_get_profile_slug (),
     366                                'screen_function' => $screen,
     367                                'position'        => 20
     368                        ) );
     369                }, 0 );
     370
     371                // Emulate visit to our new subnav page.
     372                $this->go_to( $user_domain . bp_get_profile_slug () . '/testing/' );
     373
     374                // Assert that subnav page does not 404.
     375                $this->assertFalse( is_404() );
     376
     377                $this->set_current_user( $old_current_user );
     378        }
    338379}