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/routing/root-profiles.php
Mathieu Viet 122a4b6e79 Stop using BP Legacy URL parser in favor of the new BP Rewrites API
- Deprecate `bp_core_set_uri_globals()`. This function is moved inside the BP Classic compatibility plugin.
- Introduce the new `bp_register_nav` action to hook to when globalizing Members single item navigations from the `BP_Component` class.
- Improve `bp_get_component_navigations()` so that Avatar/Cover images navigation items are moved inside the Profile sub nav if the Extended profile component is active.
- Register Avatar/Cover images Ajax actions so that these actions trigger our new URL Parser inside Ajax context.
- Improve the `BP_Core_Nav::add_nav()` method so that any BP action variable slugs can be customized.
- Improve Members & Groups component canonical redirections.
- Handle slugs customization persistency using directory pages post metas.
- Introduce a new repair tool to reset all slugs to BuddyPress default one.
- Adapt some PHPUnit tests to better handle our new URL parser.

Props Props r-a-y, johnjamesjacoby, boonebgorges

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



git-svn-id: https://buddypress.svn.wordpress.org/trunk@13468 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2023-05-03 06:18:23 +00:00

95 lines
2.6 KiB
PHP

<?php
/**
* @group members
* @group routing
* @group root_profiles
*/
class BP_Tests_Routing_Members_Root_Profiles extends BP_UnitTestCase {
protected $old_current_user = 0;
protected $u;
protected $permalink_structure = '';
public function set_up() {
parent::set_up();
add_filter( 'bp_core_enable_root_profiles', '__return_true' );
$this->old_current_user = get_current_user_id();
$uid = self::factory()->user->create( array(
'user_login' => 'boone',
'user_nicename' => 'boone',
) );
$this->u = new WP_User( $uid );
$this->set_current_user( $uid );
$this->permalink_structure = get_option( 'permalink_structure', '' );
}
public function tear_down() {
parent::tear_down();
$this->set_current_user( $this->old_current_user );
$this->set_permalink_structure( $this->permalink_structure );
remove_filter( 'bp_core_enable_root_profiles', '__return_true' );
}
public function test_members_directory() {
$this->set_permalink_structure( '/%postname%/' );
$this->go_to( home_url( bp_get_members_root_slug() ) );
$pages = bp_core_get_directory_pages();
$component_id = bp_current_component();
$this->assertEquals( bp_get_members_root_slug(), $pages->{$component_id}->slug );
}
public function test_member_permalink() {
$this->set_permalink_structure( '/%postname%/' );
$domain = home_url( $this->u->user_nicename );
$this->go_to( $domain );
$this->assertTrue( bp_is_user() );
$this->assertTrue( bp_is_my_profile() );
$this->assertEquals( $this->u->ID, bp_displayed_user_id() );
}
/**
* @ticket BP6475
*/
public function test_member_permalink_when_members_page_is_nested_under_wp_page() {
$this->markTestSkipped();
/**
* This is no more supported in BuddyPress.
*/
$this->set_permalink_structure( '/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$members_page_id = bp_core_get_directory_page_id( 'members' );
wp_update_post( array(
'ID' => $members_page_id,
'post_parent' => $p,
) );
$url = bp_members_get_user_url( $this->u->ID );
$this->go_to( $url );
$this->assertTrue( bp_is_user() );
$this->assertTrue( bp_is_my_profile() );
$this->assertEquals( $this->u->ID, bp_displayed_user_id() );
}
public function test_member_activity_page() {
$this->set_permalink_structure( '/%postname%/' );
$url = home_url( $this->u->user_nicename ) . '/' . bp_get_activity_slug();
$this->go_to( $url );
$this->assertTrue( bp_is_user() );
$this->assertTrue( bp_is_my_profile() );
$this->assertEquals( $this->u->ID, bp_displayed_user_id() );
$this->assertTrue( bp_is_activity_component() );
}
}