1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-21 20:54:17 +08:00
buddypress/tests/phpunit/testcases/admin/functions.php
Paul Gibbs 78800bc676 Retire Legacy Forums.
"Legacy Forums" is what we now call the bundled version of bbPress 1 that has shipped with BuddyPress for over nine years. The Legacy Forums codebase/features are many years stagnant, and it has been almost completely hidden from the UI for the past five years.

Legacy Forums were replaced by bbPress 2, which is its own plugin, and we've been promoting its integration with BuddyPress for a long time. Most significantly, bbPress 1 only runs on WordPress versions older than 4.7, because of a BackPress conflict (which is nested inside bbPress 1) with WordPress 4.7's `WP_Taxonomy` class.

If your site is still using Legacy Forums, you will need to migrate to bbPress 2 to run BuddyPress 3.0. See https://bpdevel.wordpress.com/2017/12/07/legacy-forums-support-will-be/ for more information.

Fixes #5351
See #7502

git-svn-id: https://buddypress.svn.wordpress.org/trunk@11763 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2017-12-08 00:22:09 +00:00

247 lines
7.2 KiB
PHP

<?php
/**
* @group admin
*/
class BP_Tests_Admin_Functions extends BP_UnitTestCase {
protected $old_current_user = 0;
public function setUp() {
parent::setUp();
$this->old_current_user = get_current_user_id();
$this->set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
if ( ! function_exists( 'bp_admin' ) ) {
require_once( BP_PLUGIN_DIR . 'bp-core/bp-core-admin.php' );
}
if ( ! function_exists( 'bp_new_site' ) ) {
bp_admin();
}
}
public function tearDown() {
parent::tearDown();
$this->set_current_user( $this->old_current_user );
}
public function test_bp_admin_list_table_current_bulk_action() {
$_REQUEST['action'] = 'foo';
$_REQUEST['action2'] = '-1';
$this->assertEquals( bp_admin_list_table_current_bulk_action(), 'foo' );
$_REQUEST['action'] = '-1';
$_REQUEST['action2'] = 'foo';
$this->assertEquals( bp_admin_list_table_current_bulk_action(), 'foo' );
$_REQUEST['action'] = 'bar';
$_REQUEST['action2'] = 'foo';
$this->assertEquals( bp_admin_list_table_current_bulk_action(), 'foo' );
}
/**
* @group bp_core_admin_get_active_components_from_submitted_settings
*/
public function test_bp_core_admin_get_active_components_from_submitted_settings() {
$get_action = isset( $_GET['action'] ) ? $_GET['action'] : null;
$ac = buddypress()->active_components;
// Standard deactivation from All screen
unset( $_GET['action'] );
buddypress()->active_components = array(
'activity' => 1,
'friends' => 1,
'groups' => 1,
'members' => 1,
'messages' => 1,
'settings' => 1,
'xprofile' => 1,
);
$submitted = array(
'groups' => 1,
'members' => 1,
'messages' => 1,
'settings' => 1,
'xprofile' => 1,
);
$this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted ), array( 'groups' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) );
// Activating deactivated components from the Inactive screen
$_GET['action'] = 'inactive';
buddypress()->active_components = array(
'activity' => 1,
'members' => 1,
'messages' => 1,
'settings' => 1,
'xprofile' => 1,
);
$submitted2 = array(
'groups' => 1,
);
$this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted2 ), array( 'activity' => 1, 'groups' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) );
// Deactivating from the Retired screen
$_GET['action'] = 'retired';
buddypress()->active_components = array(
'activity' => 1,
'members' => 1,
'messages' => 1,
'settings' => 1,
'xprofile' => 1,
);
$submitted4 = array();
$this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted4 ), array( 'activity' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) );
// reset
if ( $get_action ) {
$_GET['action'] = $get_action;
} else {
unset( $_GET['action'] );
}
buddypress()->active_components = $ac;
}
/**
* @group BP6244
* @group bp_core_admin_get_active_components_from_submitted_settings
*/
public function test_bp_core_admin_get_active_components_from_submitted_settings_should_keep_custom_component_directory_page() {
$bp = buddypress();
$reset_active_components = $bp->active_components;
// Create and activate the foo component
$bp->foo = new BP_Component;
$bp->foo->id = 'foo';
$bp->foo->slug = 'foo';
$bp->foo->name = 'Foo';
$bp->active_components[ $bp->foo->id ] = 1;
$new_page_ids = array( $bp->foo->id => self::factory()->post->create( array(
'post_type' => 'page',
'post_title' => $bp->foo->name,
'post_name' => $bp->foo->slug,
) ) );
$page_ids = array_merge( $new_page_ids, bp_core_get_directory_page_ids( 'all' ) );
bp_core_update_directory_page_ids( $page_ids );
$bp->active_components = bp_core_admin_get_active_components_from_submitted_settings( $reset_active_components );
bp_core_add_page_mappings( $bp->active_components );
$this->assertContains( $bp->foo->id, array_keys( bp_core_get_directory_page_ids( 'all' ) ) );
// Reset buddypress() vars
$bp->active_components = $reset_active_components;
}
/**
* @group bp_core_activation_notice
*/
public function test_bp_core_activation_notice_register_activate_pages_notcreated_signup_allowed() {
$bp = buddypress();
$reset_bp_pages = $bp->pages;
$reset_admin_notices = $bp->admin->notices;
// Reset pages
$bp->pages = bp_core_get_directory_pages();
add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
bp_core_activation_notice();
remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
$missing_pages = array();
foreach( buddypress()->admin->notices as $notice ) {
preg_match_all( '/<strong>(.+?)<\/strong>/', $notice['message'], $missing_pages );
}
$this->assertContains( 'Register', $missing_pages[1] );
$this->assertContains( 'Activate', $missing_pages[1] );
// Reset buddypress() vars
$bp->pages = $reset_bp_pages;
$bp->admin->notices = $reset_admin_notices;
}
/**
* @group bp_core_activation_notice
*/
public function test_bp_core_activation_notice_register_activate_pages_created_signup_allowed() {
$bp = buddypress();
$reset_bp_pages = $bp->pages;
$reset_admin_notices = $bp->admin->notices;
add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
$ac = buddypress()->active_components;
bp_core_add_page_mappings( array_keys( $ac ) );
// Reset pages
$bp->pages = bp_core_get_directory_pages();
bp_core_activation_notice();
remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
$missing_pages = array();
foreach( buddypress()->admin->notices as $notice ) {
if ( false !== strpos( $notice['message'], 'BuddyPress is almost ready' ) ) {
continue;
}
preg_match_all( '/<strong>(.+?)<\/strong>/', $notice['message'], $missing_pages );
}
$this->assertEmpty( $missing_pages );
// Reset buddypress() vars
$bp->pages = $reset_bp_pages;
$bp->admin->notices = $reset_admin_notices;
}
/**
* @ticket BP6936
*/
public function test_email_type_descriptions_should_match_when_split_terms_exist() {
global $wpdb;
// Delete all existing email types and descriptions.
$emails = get_posts( array(
'fields' => 'ids',
'post_type' => bp_get_email_post_type(),
) );
foreach ( $emails as $email ) {
wp_delete_post( $email, true );
}
$descriptions = get_terms( bp_get_email_tax_type(), array(
'fields' => 'ids',
'hide_empty' => false,
) );
foreach ( $descriptions as $description ) {
wp_delete_term( (int) $description, bp_get_email_tax_type() );
}
// Fake the existence of split terms by offsetting the term_taxonomy table.
$wpdb->insert( $wpdb->term_taxonomy, array( 'term_id' => 9999, 'taxonomy' => 'post_tag', 'description' => 'foo description', 'parent' => 0, 'count' => 0 ) );
require_once( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-admin-schema.php' );
bp_core_install_emails();
$d_terms = get_terms( bp_get_email_tax_type(), array(
'hide_empty' => false,
) );
$correct_descriptions = bp_email_get_type_schema( 'description' );
foreach ( $d_terms as $d_term ) {
$correct_description = $correct_descriptions[ $d_term->slug ];
$this->assertSame( $correct_description, $d_term->description );
}
}
}