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/core.php
Renato Alves ab4b490524 The is_home() returns false on BuddyPress pages.
This change addresses an issue where `is_home` returned `true` on BuddyPress pages (except if a BuddyPress component was set as the front page).

Props r-a-y.

Fixes #9300 (14.0)

git-svn-id: https://buddypress.svn.wordpress.org/branches/14.0@14144 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2025-12-15 02:57:47 +00:00

53 lines
1.4 KiB
PHP

<?php
/**
* @group core
* @group routing
*/
class BP_Tests_Routing_Core extends BP_UnitTestCase {
protected $old_current_user = 0;
protected $permalink_structure = '';
public function set_up() {
parent::set_up();
$this->old_current_user = get_current_user_id();
$this->set_current_user( self::factory()->user->create( array( 'role' => 'subscriber' ) ) );
$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 );
}
public function test_wordpress_page() {
$this->set_permalink_structure( '/%postname%/' );
$this->go_to( '/' );
$this->assertEmpty( bp_current_component() );
}
/**
* @ticket BP9300
*/
public function test_buddypress_directory_is_home_false() {
$this->set_permalink_structure( '/%postname%/' );
$is_home_value = null;
// Capture the is_home value during pre_get_posts for the main query.
$callback = function ( $query ) use ( &$is_home_value ) {
if ( $query->is_main_query() ) {
$is_home_value = $query->is_home;
}
};
add_action( 'pre_get_posts', $callback );
$this->go_to( bp_get_members_directory_permalink() );
remove_action( 'pre_get_posts', $callback );
$this->assertFalse( $is_home_value, 'is_home should be false for a BuddyPress directory page on the main query.' );
}
}