Skip to:
Content

bbPress.org

Changeset 7774


Ignore:
Timestamp:
10/03/2026 05:41:20 PM (5 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover forum status and type helpers.

Replace incomplete tests with assertions for forum status and type values, filters, actions, and metadata transitions. Cover the public and non-public forum post-status helpers.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/forums/functions/status.php

    r7671 r7774  
    1212        /**
    1313         * @covers ::bbp_get_forum_statuses
    14          * @todo   Implement test_bbp_get_forum_statuses().
    1514         */
    1615        public function test_bbp_get_forum_statuses() {
    17                 // Remove the following lines when you implement this test.
    18                 $this->markTestIncomplete(
    19                         'This test has not been implemented yet.'
    20                 );
     16                $forum_id = $this->factory->forum->create();
     17                $statuses = bbp_get_forum_statuses( $forum_id );
     18
     19                $this->assertSame( array( 'open', 'closed' ), array_keys( $statuses ) );
     20                $this->assertNotEmpty( $statuses['open'] );
     21                $this->assertNotEmpty( $statuses['closed'] );
     22
     23                $filter = function( $statuses, $filtered_forum_id ) use ( $forum_id ) {
     24                        $this->assertSame( $forum_id, $filtered_forum_id );
     25                        $statuses['custom'] = 'Custom status';
     26                        return $statuses;
     27                };
     28                add_filter( 'bbp_get_forum_statuses', $filter, 10, 2 );
     29                try {
     30                        $this->assertArrayHasKey( 'custom', bbp_get_forum_statuses( $forum_id ) );
     31                } finally {
     32                        remove_filter( 'bbp_get_forum_statuses', $filter );
     33                }
    2134        }
    2235
    2336        /**
    2437         * @covers ::bbp_get_forum_types
    25          * @todo   Implement test_bbp_get_forum_types().
    2638         */
    2739        public function test_bbp_get_forum_types() {
    28                 // Remove the following lines when you implement this test.
    29                 $this->markTestIncomplete(
    30                         'This test has not been implemented yet.'
    31                 );
     40                $forum_id = $this->factory->forum->create();
     41                $types    = bbp_get_forum_types( $forum_id );
     42
     43                $this->assertSame( array( 'forum', 'category' ), array_keys( $types ) );
     44                $this->assertNotEmpty( $types['forum'] );
     45                $this->assertNotEmpty( $types['category'] );
     46
     47                $filter = function( $types, $filtered_forum_id ) use ( $forum_id ) {
     48                        $this->assertSame( $forum_id, $filtered_forum_id );
     49                        $types['custom'] = 'Custom type';
     50                        return $types;
     51                };
     52                add_filter( 'bbp_get_forum_types', $filter, 10, 2 );
     53                try {
     54                        $this->assertArrayHasKey( 'custom', bbp_get_forum_types( $forum_id ) );
     55                } finally {
     56                        remove_filter( 'bbp_get_forum_types', $filter );
     57                }
     58        }
     59
     60        /**
     61         * @covers ::bbp_get_public_forum_statuses
     62         */
     63        public function test_bbp_get_public_forum_statuses() {
     64                $this->assertSame( array( bbp_get_public_status_id() ), bbp_get_public_forum_statuses() );
     65
     66                $filter = function( $statuses ) {
     67                        $statuses[] = bbp_get_private_status_id();
     68                        return $statuses;
     69                };
     70                add_filter( 'bbp_get_public_forum_statuses', $filter );
     71                try {
     72                        $this->assertSame( array( bbp_get_public_status_id(), bbp_get_private_status_id() ), bbp_get_public_forum_statuses() );
     73                } finally {
     74                        remove_filter( 'bbp_get_public_forum_statuses', $filter );
     75                }
     76        }
     77
     78        /**
     79         * @covers ::bbp_get_non_public_forum_statuses
     80         */
     81        public function test_bbp_get_non_public_forum_statuses() {
     82                $this->assertSame( array( bbp_get_private_status_id(), bbp_get_hidden_status_id() ), bbp_get_non_public_forum_statuses() );
     83
     84                $filter = function( $statuses ) {
     85                        $statuses[] = bbp_get_public_status_id();
     86                        return $statuses;
     87                };
     88                add_filter( 'bbp_get_non_public_forum_statuses', $filter );
     89                try {
     90                        $this->assertSame( array( bbp_get_private_status_id(), bbp_get_hidden_status_id(), bbp_get_public_status_id() ), bbp_get_non_public_forum_statuses() );
     91                } finally {
     92                        remove_filter( 'bbp_get_non_public_forum_statuses', $filter );
     93                }
    3294        }
    3395
    3496        /**
    3597         * @covers ::bbp_close_forum
    36          * @todo   Implement test_bbp_close_forum().
    3798         */
    3899        public function test_bbp_close_forum() {
    39                 // Remove the following lines when you implement this test.
    40                 $this->markTestIncomplete(
    41                         'This test has not been implemented yet.'
    42                 );
     100                $forum_id = $this->factory->forum->create();
     101                $events   = array();
     102                $before   = function( $id ) use ( &$events ) { $events[] = 'before:' . $id; };
     103                $after    = function( $id ) use ( &$events ) { $events[] = 'after:' . $id; };
     104
     105                $this->assertSame( 'open', bbp_get_forum_status( $forum_id ) );
     106                add_action( 'bbp_close_forum', $before );
     107                add_action( 'bbp_closed_forum', $after );
     108                try {
     109                        $this->assertSame( $forum_id, bbp_close_forum( $forum_id ) );
     110                } finally {
     111                        remove_action( 'bbp_close_forum', $before );
     112                        remove_action( 'bbp_closed_forum', $after );
     113                }
     114
     115                $this->assertSame( array( 'before:' . $forum_id, 'after:' . $forum_id ), $events );
     116                $this->assertSame( 'closed', bbp_get_forum_status( $forum_id ) );
     117                $this->assertSame( bbp_get_public_status_id(), get_post_status( $forum_id ) );
     118                $this->assertSame( 'forum', bbp_get_forum_type( $forum_id ) );
    43119        }
    44120
    45121        /**
    46122         * @covers ::bbp_open_forum
    47          * @todo   Implement test_bbp_open_forum().
    48123         */
    49124        public function test_bbp_open_forum() {
    50                 // Remove the following lines when you implement this test.
    51                 $this->markTestIncomplete(
    52                         'This test has not been implemented yet.'
    53                 );
     125                $forum_id = $this->factory->forum->create();
     126                bbp_close_forum( $forum_id );
     127                $events = array();
     128                $before = function( $id ) use ( &$events ) { $events[] = 'before:' . $id; };
     129                $after  = function( $id ) use ( &$events ) { $events[] = 'after:' . $id; };
     130
     131                $this->assertSame( 'closed', bbp_get_forum_status( $forum_id ) );
     132                add_action( 'bbp_open_forum', $before );
     133                add_action( 'bbp_opened_forum', $after );
     134                try {
     135                        $this->assertSame( $forum_id, bbp_open_forum( $forum_id ) );
     136                } finally {
     137                        remove_action( 'bbp_open_forum', $before );
     138                        remove_action( 'bbp_opened_forum', $after );
     139                }
     140
     141                $this->assertSame( array( 'before:' . $forum_id, 'after:' . $forum_id ), $events );
     142                $this->assertSame( 'open', bbp_get_forum_status( $forum_id ) );
     143                $this->assertSame( bbp_get_public_status_id(), get_post_status( $forum_id ) );
     144                $this->assertSame( 'forum', bbp_get_forum_type( $forum_id ) );
    54145        }
    55146
    56147        /**
    57148         * @covers ::bbp_categorize_forum
    58          * @todo   Implement test_bbp_categorize_forum().
    59149         */
    60150        public function test_bbp_categorize_forum() {
    61                 // Remove the following lines when you implement this test.
    62                 $this->markTestIncomplete(
    63                         'This test has not been implemented yet.'
    64                 );
     151                $forum_id = $this->factory->forum->create();
     152                $events   = array();
     153                $before   = function( $id ) use ( &$events ) { $events[] = 'before:' . $id; };
     154                $after    = function( $id ) use ( &$events ) { $events[] = 'after:' . $id; };
     155
     156                $this->assertSame( 'forum', bbp_get_forum_type( $forum_id ) );
     157                add_action( 'bbp_categorize_forum', $before );
     158                add_action( 'bbp_categorized_forum', $after );
     159                try {
     160                        $this->assertSame( $forum_id, bbp_categorize_forum( $forum_id ) );
     161                } finally {
     162                        remove_action( 'bbp_categorize_forum', $before );
     163                        remove_action( 'bbp_categorized_forum', $after );
     164                }
     165
     166                $this->assertSame( array( 'before:' . $forum_id, 'after:' . $forum_id ), $events );
     167                $this->assertSame( 'category', bbp_get_forum_type( $forum_id ) );
     168                $this->assertSame( 'open', bbp_get_forum_status( $forum_id ) );
     169                $this->assertSame( bbp_get_public_status_id(), get_post_status( $forum_id ) );
    65170        }
    66171
    67172        /**
    68173         * @covers ::bbp_normalize_forum
    69          * @todo   Implement test_bbp_normalize_forum().
    70174         */
    71175        public function test_bbp_normalize_forum() {
    72                 // Remove the following lines when you implement this test.
    73                 $this->markTestIncomplete(
    74                         'This test has not been implemented yet.'
    75                 );
     176                $forum_id = $this->factory->forum->create();
     177                bbp_categorize_forum( $forum_id );
     178                $events = array();
     179                $before = function( $id ) use ( &$events ) { $events[] = 'before:' . $id; };
     180                $after  = function( $id ) use ( &$events ) { $events[] = 'after:' . $id; };
     181
     182                $this->assertSame( 'category', bbp_get_forum_type( $forum_id ) );
     183                add_action( 'bbp_normalize_forum', $before );
     184                add_action( 'bbp_normalized_forum', $after );
     185                try {
     186                        $this->assertSame( $forum_id, bbp_normalize_forum( $forum_id ) );
     187                } finally {
     188                        remove_action( 'bbp_normalize_forum', $before );
     189                        remove_action( 'bbp_normalized_forum', $after );
     190                }
     191
     192                $this->assertSame( array( 'before:' . $forum_id, 'after:' . $forum_id ), $events );
     193                $this->assertSame( 'forum', bbp_get_forum_type( $forum_id ) );
     194                $this->assertSame( 'open', bbp_get_forum_status( $forum_id ) );
     195                $this->assertSame( bbp_get_public_status_id(), get_post_status( $forum_id ) );
    76196        }
    77197
Note: See TracChangeset for help on using the changeset viewer.