Skip to:
Content

bbPress.org

Changeset 7779


Ignore:
Timestamp:
10/04/2026 07:31:31 AM (5 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover topic status functions.

Replace ten incomplete tests for topic statuses, stickies, and moderation transitions. Add checks for toggle and visibility lists, plus restoration of a pending topic after reopening.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

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

    r7475 r7779  
    1212        /**
    1313         * @covers ::bbp_get_topic_statuses
    14          * @todo   Implement test_bbp_get_topic_statuses().
    1514         */
    1615        public function test_bbp_get_topic_statuses() {
    17                 // Remove the following lines when you implement this test.
    18                 $this->markTestIncomplete(
    19                         'This test has not been implemented yet.'
    20                 );
     16                $statuses = bbp_get_topic_statuses();
     17
     18                $this->assertSame( array(
     19                        bbp_get_public_status_id(),
     20                        bbp_get_closed_status_id(),
     21                        bbp_get_spam_status_id(),
     22                        bbp_get_trash_status_id(),
     23                        bbp_get_pending_status_id(),
     24                ), array_keys( $statuses ) );
     25                $this->assertSame( array( 'Open', 'Closed', 'Spam', 'Trash', 'Pending' ), array_values( $statuses ) );
    2126        }
    2227
    2328        /**
    2429         * @covers ::bbp_get_topic_types
    25          * @todo   Implement test_bbp_get_topic_types().
    2630         */
    2731        public function test_bbp_get_topic_types() {
    28                 // Remove the following lines when you implement this test.
    29                 $this->markTestIncomplete(
    30                         'This test has not been implemented yet.'
    31                 );
     32                $types = bbp_get_topic_types();
     33
     34                $this->assertSame( array( 'unstick', 'stick', 'super' ), array_keys( $types ) );
     35                $this->assertSame( array( 'Normal', 'Sticky', 'Super Sticky' ), array_values( $types ) );
     36        }
     37
     38        /**
     39         * @covers ::bbp_get_topic_toggles
     40         */
     41        public function test_bbp_get_topic_toggles() {
     42                $this->assertSame( array(
     43                        'bbp_toggle_topic_close',
     44                        'bbp_toggle_topic_stick',
     45                        'bbp_toggle_topic_spam',
     46                        'bbp_toggle_topic_trash',
     47                        'bbp_toggle_topic_approve',
     48                ), bbp_get_topic_toggles() );
     49        }
     50
     51        /**
     52         * @covers ::bbp_get_public_topic_statuses
     53         * @covers ::bbp_get_non_public_topic_statuses
     54         */
     55        public function test_bbp_get_topic_visibility_statuses() {
     56                $this->assertSame( array(
     57                        bbp_get_public_status_id(),
     58                        bbp_get_closed_status_id(),
     59                ), bbp_get_public_topic_statuses() );
     60                $this->assertSame( array(
     61                        bbp_get_trash_status_id(),
     62                        bbp_get_spam_status_id(),
     63                        bbp_get_pending_status_id(),
     64                ), bbp_get_non_public_topic_statuses() );
    3265        }
    3366
    3467        /**
    3568         * @covers ::bbp_get_stickies
    36          * @todo   Implement test_bbp_get_stickies().
    3769         */
    3870        public function test_bbp_get_stickies() {
    39                 // Remove the following lines when you implement this test.
    40                 $this->markTestIncomplete(
    41                         'This test has not been implemented yet.'
    42                 );
     71                $forum_id = $this->factory->forum->create();
     72                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) );
     73
     74                $this->assertSame( array(), bbp_get_stickies( $forum_id ) );
     75                $this->assertTrue( bbp_stick_topic( $topic_id ) );
     76                $this->assertSame( array( $topic_id ), bbp_get_stickies( $forum_id ) );
     77                $this->assertSame( array(), bbp_get_stickies() );
    4378        }
    4479
    4580        /**
    4681         * @covers ::bbp_get_super_stickies
    47          * @todo   Implement test_bbp_get_super_stickies().
    4882         */
    4983        public function test_bbp_get_super_stickies() {
    50                 // Remove the following lines when you implement this test.
    51                 $this->markTestIncomplete(
    52                         'This test has not been implemented yet.'
    53                 );
     84                $forum_id = $this->factory->forum->create();
     85                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) );
     86
     87                $this->assertSame( array(), bbp_get_super_stickies() );
     88                $this->assertTrue( bbp_stick_topic( $topic_id, true ) );
     89                $this->assertSame( array( $topic_id ), bbp_get_super_stickies() );
     90                $this->assertSame( array( $topic_id ), bbp_get_stickies() );
    5491        }
    5592
    5693        /**
    5794         * @covers ::bbp_close_topic
    58          * @todo   Implement test_bbp_close_topic().
    5995         */
    6096        public function test_bbp_close_topic() {
    61                 // Remove the following lines when you implement this test.
    62                 $this->markTestIncomplete(
    63                         'This test has not been implemented yet.'
    64                 );
     97                $topic_id = $this->factory->topic->create();
     98
     99                $this->assertSame( $topic_id, bbp_close_topic( $topic_id ) );
     100                $this->assertSame( bbp_get_closed_status_id(), get_post_status( $topic_id ) );
     101                $this->assertSame( bbp_get_public_status_id(), get_post_meta( $topic_id, '_bbp_status', true ) );
     102                $this->assertFalse( bbp_close_topic( $topic_id ) );
    65103        }
    66104
    67105        /**
    68106         * @covers ::bbp_open_topic
    69          * @todo   Implement test_bbp_open_topic().
    70107         */
    71108        public function test_bbp_open_topic() {
    72                 // Remove the following lines when you implement this test.
    73                 $this->markTestIncomplete(
    74                         'This test has not been implemented yet.'
    75                 );
     109                $topic_id = $this->factory->topic->create();
     110
     111                $this->assertFalse( bbp_open_topic( $topic_id ) );
     112                bbp_close_topic( $topic_id );
     113                $this->assertSame( $topic_id, bbp_open_topic( $topic_id ) );
     114                $this->assertSame( bbp_get_public_status_id(), get_post_status( $topic_id ) );
     115                $this->assertSame( '', get_post_meta( $topic_id, '_bbp_status', true ) );
     116        }
     117
     118        /**
     119         * @covers ::bbp_close_topic
     120         * @covers ::bbp_open_topic
     121         */
     122        public function test_bbp_open_topic_restores_previous_pending_status() {
     123                $topic_id = $this->factory->topic->create( array( 'post_status' => bbp_get_pending_status_id() ) );
     124
     125                $this->assertSame( $topic_id, bbp_close_topic( $topic_id ) );
     126                $this->assertSame( bbp_get_pending_status_id(), get_post_meta( $topic_id, '_bbp_status', true ) );
     127                $this->assertSame( $topic_id, bbp_open_topic( $topic_id ) );
     128                $this->assertSame( bbp_get_pending_status_id(), get_post_status( $topic_id ) );
    76129        }
    77130
    … …  
    544597        /**
    545598         * @covers ::bbp_stick_topic
    546          * @todo   Implement test_bbp_stick_topic().
    547599         */
    548600        public function test_bbp_stick_topic() {
    549                 // Remove the following lines when you implement this test.
    550                 $this->markTestIncomplete(
    551                         'This test has not been implemented yet.'
    552                 );
     601                $forum_id = $this->factory->forum->create();
     602                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) );
     603
     604                $this->assertFalse( bbp_stick_topic( $forum_id ) );
     605                $this->assertTrue( bbp_stick_topic( $topic_id ) );
     606                $this->assertSame( array( $topic_id ), bbp_get_stickies( $forum_id ) );
     607                $this->assertTrue( bbp_stick_topic( $topic_id, true ) );
     608                $this->assertSame( array( $topic_id ), bbp_get_super_stickies() );
    553609        }
    554610
    555611        /**
    556612         * @covers ::bbp_approve_topic
    557          * @todo   Implement test_bbp_approve_topic().
    558613         */
    559614        public function test_bbp_approve_topic() {
    560                 // Remove the following lines when you implement this test.
    561                 $this->markTestIncomplete(
    562                         'This test has not been implemented yet.'
    563                 );
     615                $topic_id = $this->factory->topic->create( array( 'post_status' => bbp_get_pending_status_id() ) );
     616
     617                $this->assertSame( bbp_get_pending_status_id(), get_post_status( $topic_id ) );
     618                $this->assertSame( $topic_id, bbp_approve_topic( $topic_id ) );
     619                $this->assertSame( bbp_get_public_status_id(), get_post_status( $topic_id ) );
     620                $this->assertFalse( bbp_approve_topic( $topic_id ) );
    564621        }
    565622
    566623        /**
    567624         * @covers ::bbp_unapprove_topic
    568          * @todo   Implement test_bbp_unapprove_topic().
    569625         */
    570626        public function test_bbp_unapprove_topic() {
    571                 // Remove the following lines when you implement this test.
    572                 $this->markTestIncomplete(
    573                         'This test has not been implemented yet.'
    574                 );
     627                $topic_id = $this->factory->topic->create();
     628
     629                $this->assertSame( $topic_id, bbp_unapprove_topic( $topic_id ) );
     630                $this->assertSame( bbp_get_pending_status_id(), get_post_status( $topic_id ) );
     631                $this->assertFalse( bbp_unapprove_topic( $topic_id ) );
    575632        }
    576633
    577634        /**
    578635         * @covers ::bbp_unstick_topic
    579          * @todo   Implement test_bbp_unstick_topic().
    580636         */
    581637        public function test_bbp_unstick_topic() {
    582                 // Remove the following lines when you implement this test.
    583                 $this->markTestIncomplete(
    584                         'This test has not been implemented yet.'
    585                 );
     638                $forum_id = $this->factory->forum->create();
     639                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) );
     640
     641                $this->assertTrue( bbp_unstick_topic( $topic_id ) );
     642                bbp_stick_topic( $topic_id );
     643                $this->assertTrue( bbp_unstick_topic( $topic_id ) );
     644                $this->assertSame( array(), bbp_get_stickies( $forum_id ) );
     645                bbp_stick_topic( $topic_id, true );
     646                $this->assertTrue( bbp_unstick_topic( $topic_id ) );
     647                $this->assertSame( array(), bbp_get_super_stickies() );
    586648        }
    587649}
Note: See TracChangeset for help on using the changeset viewer.