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
Renato Alves f15348c102 A user is no longer de-authenticated when making REST API requests.
We are introducing a new `BP_LoggedIn_User` class to fetch data about a BuddyPress logged-in user. This new addition fixes an issue where a user could be de-authenticated when making REST API requests.

Props dcavins, DJPaul, johnjamesjacoby, and imath.

Closes https://github.com/buddypress/buddypress/pull/395
See #9229 and #9145
Fixes #7658

git-svn-id: https://buddypress.svn.wordpress.org/trunk@14070 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2024-11-03 18:19:06 +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 );
wp_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();
wp_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 );
}
}