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/class-bp-walker-nav-menu.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

50 lines
1.5 KiB
PHP

<?php
/**
* @group core
* @group BP_Walker_Nav_Menu
*/
class BP_Tests_Walker_Nav_Menu extends BP_UnitTestCase {
protected $reset_user_id;
protected $user_id;
public function set_up() {
parent::set_up();
$this->reset_user_id = get_current_user_id();
$this->user_id = self::factory()->user->create();
wp_set_current_user( $this->user_id );
}
public function tear_down() {
wp_set_current_user( $this->reset_user_id );
parent::tear_down();
}
public function test_walk_method() {
$expected = array( 'activity-class', 'xprofile-class' );
$items = array(
(object) array(
'component_id' => 'activity',
'name' => 'Activity',
'slug' => 'activity',
'link' => bp_loggedin_user_url( array( 'single_item_component' => bp_get_activity_slug() ) ),
'css_id' => 'activity',
'class' => array( $expected[0] ),
),
(object) array(
'component_id' => 'xprofile',
'name' => 'Profile',
'slug' => 'profile',
'link' => bp_loggedin_user_url( array( 'single_item_component' => bp_get_profile_slug() ) ),
'css_id' => 'xprofile',
'class' => array( $expected[1] ),
),
);
$args = (object) array( 'before' => '', 'link_before' => '', 'after' => '', 'link_after' => '' );
$walker = new BP_Walker_Nav_Menu();
$output = $walker->walk( $items, -1, $args );
preg_match_all( '/class=["\']?([^"\']*)["\' ]/is', $output, $classes );
$this->assertSame( $classes[1], $expected );
}
}