Skip to:
Content

bbPress.org

Changeset 7789


Ignore:
Timestamp:
10/04/2026 08:32:13 AM (6 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover core update lifecycle helpers.

Replace eight incomplete stubs with checks for install and update detection, plugin activation state, version bumps, activation redirects, and keymaster promotion.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/update.php

    r7753 r7789  
    1010        /**
    1111         * @covers ::bbp_is_install
    12          * @todo   Implement test_bbp_is_install().
    1312         */
    1413        public function test_bbp_is_install() {
    15                 // Remove the following lines when you implement this test.
    16                 $this->markTestIncomplete(
    17                         'This test has not been implemented yet.'
    18                 );
     14                delete_option( '_bbp_db_version' );
     15                $this->assertTrue( bbp_is_install() );
     16
     17                update_option( '_bbp_db_version', bbp_get_db_version() );
     18                $this->assertFalse( bbp_is_install() );
    1919        }
    2020
    2121        /**
    2222         * @covers ::bbp_is_update
    23          * @todo   Implement test_bbp_is_update().
    2423         */
    2524        public function test_bbp_is_update() {
    26                 // Remove the following lines when you implement this test.
    27                 $this->markTestIncomplete(
    28                         'This test has not been implemented yet.'
    29                 );
     25                $current_version = (int) bbp_get_db_version();
     26                update_option( '_bbp_db_version', $current_version - 1 );
     27                $this->assertTrue( bbp_is_update() );
     28
     29                update_option( '_bbp_db_version', $current_version );
     30                $this->assertFalse( bbp_is_update() );
     31
     32                update_option( '_bbp_db_version', $current_version + 1 );
     33                $this->assertFalse( bbp_is_update() );
    3034        }
    3135
    3236        /**
    3337         * @covers ::bbp_is_activation
    34          * @todo   Implement test_bbp_is_activation().
    3538         */
    3639        public function test_bbp_is_activation() {
    37                 // Remove the following lines when you implement this test.
    38                 $this->markTestIncomplete(
    39                         'This test has not been implemented yet.'
    40                 );
     40                global $pagenow;
     41
     42                $old_screen  = isset( $GLOBALS['current_screen'] ) ? $GLOBALS['current_screen'] : null;
     43                $old_pagenow = $pagenow;
     44                $old_request = $_REQUEST;
     45                $old_get     = $_GET;
     46                $old_post    = $_POST;
     47                $basename    = bbpress()->basename;
     48
     49                try {
     50                        set_current_screen( 'plugins' );
     51                        $pagenow = 'plugins.php';
     52                        $_REQUEST['action'] = 'activate';
     53                        $_GET['plugin'] = $basename;
     54                        $this->assertTrue( bbp_is_activation() );
     55
     56                        $_GET['plugin'] = 'another/plugin.php';
     57                        $this->assertFalse( bbp_is_activation() );
     58
     59                        $_REQUEST['action'] = '-1';
     60                        $_REQUEST['action2'] = 'activate-selected';
     61                        $_POST['checked'] = array( $basename );
     62                        $this->assertTrue( bbp_is_activation() );
     63
     64                        $pagenow = 'index.php';
     65                        $this->assertFalse( bbp_is_activation() );
     66                } finally {
     67                        $GLOBALS['current_screen'] = $old_screen;
     68                        $pagenow = $old_pagenow;
     69                        $_REQUEST = $old_request;
     70                        $_GET = $old_get;
     71                        $_POST = $old_post;
     72                }
    4173        }
    4274
    4375        /**
    4476         * @covers ::bbp_is_deactivation
    45          * @todo   Implement test_bbp_is_deactivation().
    4677         */
    4778        public function test_bbp_is_deactivation() {
    48                 // Remove the following lines when you implement this test.
    49                 $this->markTestIncomplete(
    50                         'This test has not been implemented yet.'
    51                 );
     79                global $pagenow;
     80
     81                $old_screen  = isset( $GLOBALS['current_screen'] ) ? $GLOBALS['current_screen'] : null;
     82                $old_pagenow = $pagenow;
     83                $old_request = $_REQUEST;
     84                $old_get     = $_GET;
     85                $old_post    = $_POST;
     86                $basename    = bbpress()->basename;
     87
     88                try {
     89                        set_current_screen( 'plugins' );
     90                        $pagenow = 'plugins.php';
     91                        $_REQUEST['action'] = 'deactivate';
     92                        $_GET['plugin'] = $basename;
     93                        $this->assertTrue( bbp_is_deactivation() );
     94
     95                        $_GET['plugin'] = 'another/plugin.php';
     96                        $this->assertFalse( bbp_is_deactivation() );
     97
     98                        $_REQUEST['action'] = '-1';
     99                        $_REQUEST['action2'] = 'deactivate-selected';
     100                        $_POST['checked'] = array( $basename );
     101                        $this->assertTrue( bbp_is_deactivation() );
     102
     103                        $pagenow = 'index.php';
     104                        $this->assertFalse( bbp_is_deactivation() );
     105                } finally {
     106                        $GLOBALS['current_screen'] = $old_screen;
     107                        $pagenow = $old_pagenow;
     108                        $_REQUEST = $old_request;
     109                        $_GET = $old_get;
     110                        $_POST = $old_post;
     111                }
    52112        }
    53113
    54114        /**
    55115         * @covers ::bbp_version_bump
    56          * @todo   Implement test_bbp_version_bump().
    57116         */
    58117        public function test_bbp_version_bump() {
    59                 // Remove the following lines when you implement this test.
    60                 $this->markTestIncomplete(
    61                         'This test has not been implemented yet.'
    62                 );
     118                update_option( '_bbp_db_version', 1 );
     119                bbp_version_bump();
     120                $this->assertSame( (int) bbp_get_db_version(), (int) bbp_get_db_version_raw() );
    63121        }
    64122
    … …  
    227285        /**
    228286         * @covers ::bbp_version_updater
    229          * @todo   Implement test_bbp_version_updater().
    230287         */
    231288        public function test_bbp_version_updater() {
    232                 // Remove the following lines when you implement this test.
    233                 $this->markTestIncomplete(
    234                         'This test has not been implemented yet.'
    235                 );
     289                delete_option( '_bbp_db_version' );
     290                update_option( 'rewrite_rules', array( 'sentinel' => 'saved' ) );
     291
     292                bbp_version_updater();
     293
     294                $this->assertSame( (int) bbp_get_db_version(), (int) bbp_get_db_version_raw() );
     295                $this->assertFalse( get_option( 'rewrite_rules' ) );
    236296        }
    237297
    … …  
    251311        /**
    252312         * @covers ::bbp_add_activation_redirect
    253          * @todo   Implement test_bbp_add_activation_redirect().
    254313         */
    255314        public function test_bbp_add_activation_redirect() {
    256                 // Remove the following lines when you implement this test.
    257                 $this->markTestIncomplete(
    258                         'This test has not been implemented yet.'
    259                 );
     315                $old_user = get_current_user_id();
     316                $old_get  = $_GET;
     317                $user_id  = $this->factory->user->create();
     318                $this->set_current_user( $user_id );
     319
     320                try {
     321                        bbp_add_activation_redirect();
     322                        $this->assertTrue( (bool) get_user_option( '_bbp_activation_redirect', $user_id ) );
     323
     324                        delete_user_option( $user_id, '_bbp_activation_redirect' );
     325                        $_GET['activate-multi'] = '1';
     326                        bbp_add_activation_redirect();
     327                        $this->assertFalse( (bool) get_user_option( '_bbp_activation_redirect', $user_id ) );
     328                } finally {
     329                        $_GET = $old_get;
     330                        $this->set_current_user( $old_user );
     331                }
    260332        }
    261333
    262334        /**
    263335         * @covers ::bbp_make_current_user_keymaster
    264          * @todo   Implement test_bbp_make_current_user_keymaster().
    265336         */
    266337        public function test_bbp_make_current_user_keymaster() {
    267                 // Remove the following lines when you implement this test.
    268                 $this->markTestIncomplete(
    269                         'This test has not been implemented yet.'
    270                 );
     338                $old_user = get_current_user_id();
     339                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     340                if ( is_multisite() ) {
     341                        grant_super_admin( $user_id );
     342                }
     343                $this->set_current_user( $user_id );
     344                $forum_role = bbp_get_user_role( $user_id );
     345                if ( $forum_role ) {
     346                        get_userdata( $user_id )->remove_role( $forum_role );
     347                }
     348
     349                try {
     350                        $this->assertFalse( bbp_get_user_role( $user_id ) );
     351                        bbp_make_current_user_keymaster();
     352                        $this->assertSame( bbp_get_keymaster_role(), bbp_get_user_role( $user_id ) );
     353
     354                        bbp_make_current_user_keymaster();
     355                        $this->assertSame( bbp_get_keymaster_role(), bbp_get_user_role( $user_id ) );
     356                } finally {
     357                        $this->set_current_user( $old_user );
     358                        if ( is_multisite() ) {
     359                                revoke_super_admin( $user_id );
     360                        }
     361                }
    271362        }
    272363}
Note: See TracChangeset for help on using the changeset viewer.