Skip to:
Content

bbPress.org

Changeset 7798


Ignore:
Timestamp:
10/04/2026 09:11:46 AM (5 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover the admin reset page and guards.

Initialize the bbPress admin test dependency so this file runs independently, then replace stale reset stubs with page-rendering and non-resetting request assertions.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/admin/tools.php

    r7797 r7798  
    1818                bbp_set_user_role( $this->keymaster_id, bbp_get_keymaster_role() );
    1919
     20                if ( ! function_exists( 'bbp_admin' ) ) {
     21                        require_once BBP_PLUGIN_DIR . 'includes/admin/actions.php';
     22                }
     23                bbp_admin();
     24
    2025                if ( ! function_exists( 'bbp_admin_repair_page' ) ) {
    2126                        require_once BBP_PLUGIN_DIR . 'includes/admin/tools/repair.php';
    2227                        require_once BBP_PLUGIN_DIR . 'includes/admin/tools/upgrade.php';
     28                }
     29                if ( ! function_exists( 'bbp_admin_reset_page' ) ) {
     30                        require_once BBP_PLUGIN_DIR . 'includes/admin/tools/reset.php';
    2331                }
    2432        }
    … …  
    11291137
    11301138        /**
    1131          * @covers ::bbp_admin_reset
    1132          * @todo   Implement test_bbp_admin_reset().
    1133          */
    1134         public function test_bbp_admin_reset() {
    1135                 // Remove the following lines when you implement this test.
    1136                 $this->markTestIncomplete(
    1137                         'This test has not been implemented yet.'
    1138                 );
     1139         * @covers ::bbp_admin_reset_page
     1140         */
     1141        public function test_bbp_admin_reset_page() {
     1142                ob_start();
     1143                bbp_admin_reset_page();
     1144                $output = ob_get_clean();
     1145
     1146                $this->assertStringContainsString( 'name="bbpress-are-you-sure"', $output );
     1147                $this->assertStringContainsString( 'name="_wpnonce"', $output );
     1148                $this->assertStringContainsString( 'Reset bbPress', $output );
    11391149        }
    11401150
    11411151        /**
    11421152         * @covers ::bbp_admin_reset_handler
    1143          * @todo   Implement test_bbp_admin_reset_handler().
    11441153         */
    11451154        public function test_bbp_admin_reset_handler() {
    1146                 // Remove the following lines when you implement this test.
    1147                 $this->markTestIncomplete(
    1148                         'This test has not been implemented yet.'
    1149                 );
     1155                $old_method = isset( $_SERVER['REQUEST_METHOD'] ) ? $_SERVER['REQUEST_METHOD'] : null;
     1156                $old_post   = $_POST;
     1157
     1158                try {
     1159                        $_SERVER['REQUEST_METHOD'] = 'GET';
     1160                        $_POST = array( 'bbpress-are-you-sure' => '1' );
     1161                        $this->assertNull( bbp_admin_reset_handler() );
     1162                        $_SERVER['REQUEST_METHOD'] = 'POST';
     1163                        $_POST = array();
     1164                        $this->assertNull( bbp_admin_reset_handler() );
     1165                } finally {
     1166                        $_POST = $old_post;
     1167                        if ( null === $old_method ) {
     1168                                unset( $_SERVER['REQUEST_METHOD'] );
     1169                        } else {
     1170                                $_SERVER['REQUEST_METHOD'] = $old_method;
     1171                        }
     1172                }
    11501173        }
    11511174}
Note: See TracChangeset for help on using the changeset viewer.