Skip to:
Content

bbPress.org

Changeset 7801


Ignore:
Timestamp:
10/04/2026 09:22:02 AM (3 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover topic lifecycle hooks and metadata.

Replace seven topic-function stubs with assertions for revision logs, delete and trash action dispatch, and selective reply trashing.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

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

    r7800 r7801  
    1212        protected $old_current_user;
    1313    protected $keymaster_id;
     14
     15        private function assert_topic_action( $function, $hook ) {
     16                $topic_id = $this->factory->topic->create();
     17                $seen     = array();
     18                $callback = function ( $id ) use ( &$seen ) {
     19                        $seen[] = $id;
     20                };
     21                add_action( $hook, $callback );
     22
     23                try {
     24                        $this->assertFalse( $function( PHP_INT_MAX ) );
     25                        $function( $topic_id );
     26                        $this->assertSame( array( $topic_id ), $seen );
     27                } finally {
     28                        remove_action( $hook, $callback );
     29                }
     30        }
    1431
    1532        /**
    … …  
    538555        /**
    539556         * @covers ::bbp_update_topic_revision_log
    540          * @todo   Implement test_bbp_update_topic_revision_log().
    541557         */
    542558        public function test_bbp_update_topic_revision_log() {
    543                 // Remove the following lines when you implement this test.
    544                 $this->markTestIncomplete(
    545                         'This test has not been implemented yet.'
    546                 );
     559                $topic_id = $this->factory->topic->create();
     560                $user_id  = $this->factory->user->create();
     561                $args     = array( 'topic_id' => $topic_id, 'author_id' => $user_id, 'revision_id' => 17, 'reason' => 'Clarify wording' );
     562
     563                $this->assertNotFalse( bbp_update_topic_revision_log( $args ) );
     564                $log = bbp_get_topic_raw_revision_log( $topic_id );
     565                $this->assertSame( $user_id, $log[17]['author'] );
     566                $this->assertSame( 'Clarify wording', $log[17]['reason'] );
    547567        }
    548568
    549569        /**
    550570         * @covers ::bbp_delete_topic
    551          * @todo   Implement test_bbp_delete_topic().
    552571         */
    553572        public function test_bbp_delete_topic() {
    554                 // Remove the following lines when you implement this test.
    555                 $this->markTestIncomplete(
    556                         'This test has not been implemented yet.'
    557                 );
     573                $this->assert_topic_action( 'bbp_delete_topic', 'bbp_delete_topic' );
    558574        }
    559575
    … …  
    587603        /**
    588604         * @covers ::bbp_trash_topic
    589          * @todo   Implement test_bbp_trash_topic().
    590605         */
    591606        public function test_bbp_trash_topic() {
    592                 // Remove the following lines when you implement this test.
    593                 $this->markTestIncomplete(
    594                         'This test has not been implemented yet.'
    595                 );
     607                $this->assert_topic_action( 'bbp_trash_topic', 'bbp_trash_topic' );
    596608        }
    597609
    598610        /**
    599611         * @covers ::bbp_trash_topic_replies
    600          * @todo   Implement test_bbp_trash_topic_replies().
    601612         */
    602613        public function test_bbp_trash_topic_replies() {
    603                 // Remove the following lines when you implement this test.
    604                 $this->markTestIncomplete(
    605                         'This test has not been implemented yet.'
    606                 );
     614                $topic_id = $this->factory->topic->create();
     615                $public   = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     616                $trashed  = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     617                wp_trash_post( $trashed );
     618
     619                bbp_trash_topic_replies( $topic_id );
     620                $this->assertSame( bbp_get_trash_status_id(), get_post_status( $public ) );
     621                $this->assertSame( bbp_get_trash_status_id(), get_post_status( $trashed ) );
     622                $this->assertSame( array( $public ), get_post_meta( $topic_id, '_bbp_pre_trashed_replies', true ) );
    607623        }
    608624
    … …  
    658674        /**
    659675         * @covers ::bbp_deleted_topic
    660          * @todo   Implement test_bbp_deleted_topic().
    661676         */
    662677        public function test_bbp_deleted_topic() {
    663                 // Remove the following lines when you implement this test.
    664                 $this->markTestIncomplete(
    665                         'This test has not been implemented yet.'
    666                 );
     678                $this->assert_topic_action( 'bbp_deleted_topic', 'bbp_deleted_topic' );
    667679        }
    668680
    669681        /**
    670682         * @covers ::bbp_trashed_topic
    671          * @todo   Implement test_bbp_trashed_topic().
    672683         */
    673684        public function test_bbp_trashed_topic() {
    674                 // Remove the following lines when you implement this test.
    675                 $this->markTestIncomplete(
    676                         'This test has not been implemented yet.'
    677                 );
     685                $this->assert_topic_action( 'bbp_trashed_topic', 'bbp_trashed_topic' );
    678686        }
    679687
    680688        /**
    681689         * @covers ::bbp_untrashed_topic
    682          * @todo   Implement test_bbp_untrashed_topic().
    683690         */
    684691        public function test_bbp_untrashed_topic() {
    685                 // Remove the following lines when you implement this test.
    686                 $this->markTestIncomplete(
    687                         'This test has not been implemented yet.'
    688                 );
     692                $this->assert_topic_action( 'bbp_untrashed_topic', 'bbp_untrashed_topic' );
    689693        }
    690694
Note: See TracChangeset for help on using the changeset viewer.