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 3fb28a23de Compat classes to handle Walker_Nav_Menu::walk() changes in WP 5.3
WordPress 5.3 modified the `Walker_Nav_Menu::walk()` signature adding a third parameter to the method that is using the spread operator. johnjamesjacoby quickly fixed the issue in [12497] when PHP >=5.6.

As our current PHP required version is 5.3, we need to provide a temporary compatibility mechanism to make sure our `BP_Walker_Nav_Menu` will not generate errors when the PHP version is lower than 5.6 before raising the PHP required version in our next major release.

props timothybjacobs, boonebgorges, imath

See #8163 (Trunk)


git-svn-id: https://buddypress.svn.wordpress.org/trunk@12498 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2019-11-29 03:46:56 +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 setUp() {
parent::setUp();
$this->reset_user_id = get_current_user_id();
$this->user_id = self::factory()->user->create();
$this->set_current_user( $this->user_id );
}
public function tearDown() {
parent::tearDown();
$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' => trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() ),
'css_id' => 'activity',
'class' => array( $expected[0] ),
),
(object) array(
'component_id' => 'xprofile',
'name' => 'Profile',
'slug' => 'profile',
'link' => trailingslashit( bp_loggedin_user_domain() . 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 );
}
}