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
Mathieu Viet 7085a6c040 Improve Components Member's single item navigation generation
- Edit the `BP_Component` Class so that it globalize navigation items before registering it.
- Introduce `bp_get_component_navigations()`, a new function that will be used to get Member's single navigation customizable slugs within the BuddyPress settings area.
- Perform all remaining `bp_loggedin_user_domain()` replacements (55) in favor of the `bp_loggedin_user_url()` function which uses BP Rewrites to build URLs.
- Improve `bp_loggedin_user_link()` by adding a new `$chunks` array of arguments to output escaped URL in templates.
- Adapt some PHPUnit testcases.

Props r-a-y, johnjamesjacoby, boonebgorges

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



git-svn-id: https://buddypress.svn.wordpress.org/trunk@13442 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2023-03-27 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();
$this->set_current_user( $this->user_id );
}
public function tear_down() {
parent::tear_down();
$this->set_current_user( $this->reset_user_id );
}
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 );
}
}