Skip to:
Content

bbPress.org


Ignore:
Timestamp:
10/01/2026 12:18:13 AM (4 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Expand common, search, user, and admin coverage.

Replace 58 incomplete placeholders with assertions for common helpers, search requests, user templates, and safe admin-tool paths. Add search-type and request-sanitization coverage, with fixtures restored after each test.

In trunk, for 2.7.
See #3695.

File:
1 edited

Legend:

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

    r7467 r7762  
    3030
    3131        /**
    32          * @covers ::bbp_admin_repair
    33          * @todo   Implement test_bbp_admin_repair().
     32         * @covers ::bbp_admin_repair_page
    3433         */
    3534        public function test_bbp_admin_repair() {
    36                 // Remove the following lines when you implement this test.
    37                 $this->markTestIncomplete(
    38                         'This test has not been implemented yet.'
    39                 );
     35                $original_get   = $_GET;
     36                $original_tools = bbp_admin()->tools;
     37                $_GET           = array( 'page' => 'bbp-repair' );
     38                bbp_register_default_repair_tools();
     39
     40                try {
     41                        ob_start();
     42                        bbp_admin_repair_page();
     43                        $output = ob_get_clean();
     44
     45                        $this->assertStringContainsString( 'name="page" value="bbp-repair"', $output );
     46                        $this->assertStringContainsString( 'name="checked[]"', $output );
     47                        $this->assertStringContainsString( 'name="_wpnonce"', $output );
     48                } finally {
     49                        $_GET              = $original_get;
     50                        bbp_admin()->tools = $original_tools;
     51                }
    4052        }
    4153
    4254        /**
    4355         * @covers ::bbp_admin_repair_handler
    44          * @todo   Implement test_bbp_admin_repair_handler().
     56         * @ticket 3695
    4557         */
    4658        public function test_bbp_admin_repair_handler() {
    47                 // Remove the following lines when you implement this test.
    48                 $this->markTestIncomplete(
    49                         'This test has not been implemented yet.'
    50                 );
     59                $original_get             = $_GET;
     60                $original_method          = isset( $_SERVER['REQUEST_METHOD'] ) ? $_SERVER['REQUEST_METHOD'] : null;
     61                $_GET                     = array( 'action' => 'not-run' );
     62                $_SERVER['REQUEST_METHOD'] = 'GET';
     63
     64                try {
     65                        $this->assertNull( bbp_admin_repair_handler() );
     66                } finally {
     67                        $_GET = $original_get;
     68                        if ( is_null( $original_method ) ) {
     69                                unset( $_SERVER['REQUEST_METHOD'] );
     70                        } else {
     71                                $_SERVER['REQUEST_METHOD'] = $original_method;
     72                        }
     73                }
    5174        }
    5275
    5376        /**
    5477         * @covers ::bbp_admin_tools_repair_help
    55          * @todo   Implement test_bbp_admin_tools_repair_help().
     78         * @ticket 3695
    5679         */
    5780        public function test_bbp_admin_tools_repair_help() {
    58                 // Remove the following lines when you implement this test.
    59                 $this->markTestIncomplete(
    60                         'This test has not been implemented yet.'
    61                 );
     81                $previous = get_current_screen();
     82                set_current_screen( 'tools_page_bbp-repair' );
     83
     84                try {
     85                        bbp_admin_tools_repair_help();
     86                        $tabs = get_current_screen()->get_help_tabs();
     87                        $this->assertArrayHasKey( 'repair_forums', $tabs );
     88                        $this->assertStringContainsString( 'bbPress: Repair Forums', $tabs['repair_forums']['content'] );
     89                        $this->assertStringContainsString( 'bbPress Documentation', get_current_screen()->get_help_sidebar() );
     90                } finally {
     91                        $GLOBALS['current_screen'] = $previous;
     92                }
    6293        }
    6394
    6495        /**
    6596         * @covers ::bbp_admin_tools_reset_help
    66          * @todo   Implement test_bbp_admin_tools_reset_help().
     97         * @ticket 3695
    6798         */
    6899        public function test_bbp_admin_tools_reset_help() {
    69                 // Remove the following lines when you implement this test.
    70                 $this->markTestIncomplete(
    71                         'This test has not been implemented yet.'
    72                 );
     100                $previous = get_current_screen();
     101                set_current_screen( 'tools_page_bbp-reset' );
     102
     103                try {
     104                        bbp_admin_tools_reset_help();
     105                        $tabs = get_current_screen()->get_help_tabs();
     106                        $this->assertArrayHasKey( 'reset_forums', $tabs );
     107                        $this->assertStringContainsString( 'bbPress: Reset Forums', $tabs['reset_forums']['content'] );
     108                } finally {
     109                        $GLOBALS['current_screen'] = $previous;
     110                }
    73111        }
    74112
    75113        /**
    76114         * @covers ::bbp_admin_tools_converter_help
    77          * @todo   Implement test_bbp_admin_tools_converter_help().
     115         * @ticket 3695
    78116         */
    79117        public function test_bbp_admin_tools_converter_help() {
    80                 // Remove the following lines when you implement this test.
    81                 $this->markTestIncomplete(
    82                         'This test has not been implemented yet.'
    83                 );
     118                $previous = get_current_screen();
     119                set_current_screen( 'tools_page_bbp-converter' );
     120
     121                try {
     122                        bbp_admin_tools_converter_help();
     123                        $tabs = get_current_screen()->get_help_tabs();
     124                        $this->assertSame( array( 'overview', 'database_settings', 'importer_options' ), array_keys( $tabs ) );
     125                        $this->assertStringContainsString( 'bbPress: Import Forums', $tabs['overview']['content'] );
     126                } finally {
     127                        $GLOBALS['current_screen'] = $previous;
     128                }
    84129        }
    85130
    86131        /**
    87132         * @covers ::bbp_admin_tools_feedback
    88          * @todo   Implement test_bbp_admin_tools_feedback().
     133         * @ticket 3695
    89134         */
    90135        public function test_bbp_admin_tools_feedback() {
    91                 // Remove the following lines when you implement this test.
    92                 $this->markTestIncomplete(
    93                         'This test has not been implemented yet.'
    94                 );
     136                $notices = bbp_admin()->notices;
     137
     138                try {
     139                        bbp_admin_tools_feedback( 'Repair complete', 'success', false );
     140                        $this->assertStringContainsString( 'notice success', end( bbp_admin()->notices ) );
     141                        $this->assertStringContainsString( '<p>Repair complete</p>', end( bbp_admin()->notices ) );
     142                        $this->assertStringNotContainsString( 'is-dismissible', end( bbp_admin()->notices ) );
     143                        $this->assertFalse( bbp_admin_tools_feedback( array( 'invalid' ) ) );
     144                } finally {
     145                        bbp_admin()->notices = $notices;
     146                }
    95147        }
    96148
    97149        /**
    98150         * @covers ::bbp_admin_repair_list
    99          * @todo   Implement test_bbp_admin_repair_list().
     151         * @ticket 3695
    100152         */
    101153        public function test_bbp_admin_repair_list() {
    102                 // Remove the following lines when you implement this test.
    103                 $this->markTestIncomplete(
    104                         'This test has not been implemented yet.'
    105                 );
     154                $original_get   = $_GET;
     155                $original_tools = bbp_admin()->tools;
     156                $_GET           = array( 's' => 'Recount' );
     157                bbp_register_default_repair_tools();
     158
     159                try {
     160                        $list = bbp_admin_repair_list();
     161                        $this->assertNotEmpty( $list );
     162                        foreach ( $list as $tool ) {
     163                                $this->assertSame( 'repair', $tool['type'] );
     164                                $this->assertStringContainsString( 'recount', strtolower( $tool['title'] ) );
     165                        }
     166                } finally {
     167                        $_GET              = $original_get;
     168                        bbp_admin()->tools = $original_tools;
     169                }
    106170        }
    107171
Note: See TracChangeset for help on using the changeset viewer.