1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-22 20:56:55 +08:00
buddypress/tests/phpunit/testcases/core/nav/bpGetNavMenuItems.php
Mathieu Viet d769515ea4 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()`
3. 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



git-svn-id: https://buddypress.svn.wordpress.org/trunk@13433 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2023-03-07 04:28:08 +00:00

72 lines
1.7 KiB
PHP

<?php
/**
* @group core
* @group nav
*/
class BP_Tests_Core_Nav_BpGetNavMenuItems extends BP_UnitTestCase {
protected $permalink_structure = '';
public function set_up() {
parent::set_up();
$this->permalink_structure = get_option( 'permalink_structure', '' );
}
public function tear_down() {
$this->set_permalink_structure( $this->permalink_structure );
parent::tear_down();
}
/**
* @ticket BP7110
*/
public function test_top_level_link_should_point_to_displayed_user_for_loggedin_user() {
$users = self::factory()->user->create_many( 2 );
$this->set_current_user( $users[0] );
$this->set_permalink_structure( '/%postname%/' );
$user_1_domain = bp_members_get_user_url( $users[1] );
$this->go_to( $user_1_domain );
$found = bp_get_nav_menu_items();
// Find the Activity top-level item.
$activity_item = null;
foreach ( $found as $f ) {
if ( 'activity' === $f->css_id ) {
$activity_item = $f;
break;
}
}
$this->assertSame( trailingslashit( $user_1_domain ) . 'activity/', $activity_item->link );
}
/**
* @ticket BP7110
*/
public function test_top_level_link_should_point_to_displayed_user_for_loggedout_user() {
$user = self::factory()->user->create();
$this->set_current_user( 0 );
$this->set_permalink_structure( '/%postname%/' );
$user_domain = bp_members_get_user_url( $user );
$this->go_to( $user_domain );
$found = bp_get_nav_menu_items();
// Find the Activity top-level item.
$activity_item = null;
foreach ( $found as $f ) {
if ( 'activity' === $f->css_id ) {
$activity_item = $f;
break;
}
}
$this->assertSame( trailingslashit( $user_domain ) . 'activity/', $activity_item->link );
}
}