Skip to:
Content

bbPress.org

Changeset 7795


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

Tests: Cover four admin repair routines.

Replace repair stubs with assertions for stale sticky relationships, closed-topic metadata, topic-parent metadata, and self-referential reply ancestry.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

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

    r7762 r7795  
    911911        /**
    912912         * @covers ::bbp_admin_repair_sticky
    913          * @todo   Implement test_bbp_admin_repair_sticky().
    914913         */
    915914        public function test_bbp_admin_repair_sticky() {
    916                 // Remove the following lines when you implement this test.
    917                 $this->markTestIncomplete(
    918                         'This test has not been implemented yet.'
    919                 );
     915                $first_forum  = $this->factory->forum->create();
     916                $second_forum = $this->factory->forum->create();
     917                $topic_id     = $this->factory->topic->create( array( 'post_parent' => $first_forum ) );
     918                update_post_meta( $first_forum, '_bbp_sticky_topics', array( $topic_id ) );
     919                update_post_meta( $second_forum, '_bbp_sticky_topics', array( $topic_id ) );
     920
     921                $this->assertSame( 0, bbp_admin_repair_sticky()[0] );
     922                $this->assertSame( array( $topic_id ), get_post_meta( $first_forum, '_bbp_sticky_topics', true ) );
     923                $this->assertSame( '', get_post_meta( $second_forum, '_bbp_sticky_topics', true ) );
    920924        }
    921925
    922926        /**
    923927         * @covers ::bbp_admin_repair_closed_topics
    924          * @todo   Implement test_bbp_admin_repair_closed_topics().
    925928         */
    926929        public function test_bbp_admin_repair_closed_topics() {
    927                 // Remove the following lines when you implement this test.
    928                 $this->markTestIncomplete(
    929                         'This test has not been implemented yet.'
    930                 );
     930                $topic_id = $this->factory->topic->create( array( 'post_status' => bbp_get_closed_status_id() ) );
     931                delete_post_meta( $topic_id, '_bbp_status' );
     932
     933                $result = bbp_admin_repair_closed_topics();
     934                $this->assertSame( 0, $result[0] );
     935                $this->assertStringContainsString( '1 closed topic repaired', $result[1] );
     936                $this->assertSame( 'publish', get_post_meta( $topic_id, '_bbp_status', true ) );
     937                $this->assertStringContainsString( '0 closed topics repaired', bbp_admin_repair_closed_topics()[1] );
    931938        }
    932939
    … …  
    9991006        /**
    10001007         * @covers ::bbp_admin_repair_topic_meta
    1001          * @todo   Implement test_bbp_admin_repair_topic_meta().
    10021008         */
    10031009        public function test_bbp_admin_repair_topic_meta() {
    1004                 // Remove the following lines when you implement this test.
    1005                 $this->markTestIncomplete(
    1006                         'This test has not been implemented yet.'
    1007                 );
     1010                $forum_id = $this->factory->forum->create();
     1011                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) );
     1012                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     1013                update_post_meta( $topic_id, '_bbp_topic_id', 999 );
     1014                update_post_meta( $reply_id, '_bbp_topic_id', 999 );
     1015
     1016                $this->assertSame( 0, bbp_admin_repair_topic_meta()[0] );
     1017                $this->assertSame( (string) $topic_id, get_post_meta( $topic_id, '_bbp_topic_id', true ) );
     1018                $this->assertSame( (string) $topic_id, get_post_meta( $reply_id, '_bbp_topic_id', true ) );
    10081019        }
    10091020
    10101021        /**
    10111022         * @covers ::bbp_admin_repair_reply_menu_order
    1012          * @todo   Implement test_bbp_admin_repair_reply_menu_order().
    10131023         */
    10141024        public function test_bbp_admin_repair_reply_menu_order() {
    1015                 // Remove the following lines when you implement this test.
    1016                 $this->markTestIncomplete(
    1017                         'This test has not been implemented yet.'
    1018                 );
     1025                $topic_id = $this->factory->topic->create();
     1026                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     1027                update_post_meta( $reply_id, '_bbp_reply_to', $reply_id );
     1028
     1029                $this->assertSame( 1, bbp_admin_repair_reply_menu_order()[0] );
     1030                $this->assertFalse( metadata_exists( 'post', $reply_id, '_bbp_reply_to' ) );
    10191031        }
    10201032
Note: See TracChangeset for help on using the changeset viewer.