Skip to:
Content

bbPress.org

Changeset 7782


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

Tests: Cover topic and reply revision templates.

Replace ten incomplete tests with real revision fixtures. Verify raw and formatted logs, output wrappers, appended content, revision retrieval, and formatted versus integer counts.

In trunk, for 2.7.

See #3695.

Location:
trunk/tests/phpunit/testcases
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/replies/template/revisions.php

    r5726 r7782  
    1212        /**
    1313         * @covers ::bbp_reply_content_append_revisions
    14          * @todo   Implement test_bbp_reply_content_append_revisions().
    1514         */
    1615        public function test_bbp_reply_content_append_revisions() {
    17                 // Remove the following lines when you implement this test.
    18                 $this->markTestIncomplete(
    19                         'This test has not been implemented yet.'
    20                 );
     16                $topic_id = $this->factory->topic->create();
     17                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     18
     19                $this->assertSame( 'Reply content', bbp_reply_content_append_revisions( 'Reply content', $reply_id ) );
     20                $revision_id = $this->create_reply_revision( $reply_id );
     21                update_post_meta( $reply_id, '_bbp_revision_log', array(
     22                        $revision_id => array( 'author' => 0, 'reason' => 'Updated.' ),
     23                ) );
     24                $this->assertSame( 'Reply content' . bbp_get_reply_revision_log( $reply_id ), bbp_reply_content_append_revisions( 'Reply content', $reply_id ) );
    2125        }
    2226
    … …  
    2428         * @covers ::bbp_reply_revision_log
    2529         * @covers ::bbp_get_reply_revision_log
    26          * @todo   Implement test_bbp_get_reply_revision_log().
    2730         */
    2831        public function test_bbp_get_reply_revision_log() {
    29                 // Remove the following lines when you implement this test.
    30                 $this->markTestIncomplete(
    31                         'This test has not been implemented yet.'
    32                 );
     32                $topic_id = $this->factory->topic->create();
     33                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     34                $this->assertFalse( bbp_get_reply_revision_log( $reply_id ) );
     35
     36                $revision_id = $this->create_reply_revision( $reply_id );
     37                update_post_meta( $reply_id, '_bbp_revision_log', array(
     38                        $revision_id => array( 'author' => 0, 'reason' => 'Clarified the answer.' ),
     39                ) );
     40                $log = bbp_get_reply_revision_log( $reply_id );
     41
     42                $this->assertStringContainsString( 'bbp-reply-revision-log-' . $reply_id, $log );
     43                $this->assertStringContainsString( 'item-' . $revision_id, $log );
     44                $this->assertStringContainsString( 'Clarified the answer.', $log );
     45                $this->expectOutputString( $log );
     46                bbp_reply_revision_log( $reply_id );
    3347        }
    3448
    3549        /**
    3650         * @covers ::bbp_get_reply_raw_revision_log
    37          * @todo   Implement test_bbp_get_reply_raw_revision_log().
    3851         */
    3952        public function test_bbp_get_reply_raw_revision_log() {
    40                 // Remove the following lines when you implement this test.
    41                 $this->markTestIncomplete(
    42                         'This test has not been implemented yet.'
    43                 );
     53                $topic_id = $this->factory->topic->create();
     54                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     55                $this->assertSame( array(), bbp_get_reply_raw_revision_log( $reply_id ) );
     56
     57                $log = array( 123 => array( 'author' => 0, 'reason' => 'Updated.' ) );
     58                update_post_meta( $reply_id, '_bbp_revision_log', $log );
     59                $this->assertSame( $log, bbp_get_reply_raw_revision_log( $reply_id ) );
    4460        }
    4561
    4662        /**
    4763         * @covers ::bbp_get_reply_revisions
    48          * @todo   Implement test_bbp_get_reply_revisions().
    4964         */
    5065        public function test_bbp_get_reply_revisions() {
    51                 // Remove the following lines when you implement this test.
    52                 $this->markTestIncomplete(
    53                         'This test has not been implemented yet.'
    54                 );
     66                $topic_id    = $this->factory->topic->create();
     67                $reply_id    = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     68                $revision_id = $this->create_reply_revision( $reply_id );
     69                $revisions   = bbp_get_reply_revisions( $reply_id );
     70
     71                $this->assertArrayHasKey( $revision_id, $revisions );
     72                $this->assertSame( $reply_id, $revisions[ $revision_id ]->post_parent );
    5573        }
    5674
    5775        /**
    5876         * @covers ::bbp_get_reply_revision_count
    59          * @todo   Implement test_bbp_get_reply_revision_count().
    6077         */
    6178        public function test_bbp_get_reply_revision_count() {
    62                 // Remove the following lines when you implement this test.
    63                 $this->markTestIncomplete(
    64                         'This test has not been implemented yet.'
    65                 );
     79                $topic_id = $this->factory->topic->create();
     80                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     81                $this->assertSame( '0', bbp_get_reply_revision_count( $reply_id ) );
     82
     83                $this->create_reply_revision( $reply_id );
     84                $this->assertSame( '1', bbp_get_reply_revision_count( $reply_id ) );
     85                $this->assertSame( 1, bbp_get_reply_revision_count( $reply_id, true ) );
     86        }
     87
     88        private function create_reply_revision( $reply_id ) {
     89                wp_update_post( array( 'ID' => $reply_id, 'post_content' => 'Updated reply content.' ) );
     90                $revisions = wp_get_post_revisions( $reply_id );
     91
     92                $this->assertNotEmpty( $revisions );
     93                return key( $revisions );
    6694        }
    6795}
  • trunk/tests/phpunit/testcases/topics/template/revisions.php

    r5726 r7782  
    1212        /**
    1313         * @covers ::bbp_topic_content_append_revisions
    14          * @todo   Implement test_bbp_topic_content_append_revisions().
    1514         */
    1615        public function test_bbp_topic_content_append_revisions() {
    17                 // Remove the following lines when you implement this test.
    18                 $this->markTestIncomplete(
    19                         'This test has not been implemented yet.'
    20                 );
     16                $topic_id = $this->factory->topic->create();
     17
     18                $this->assertSame( 'Topic content', bbp_topic_content_append_revisions( 'Topic content', $topic_id ) );
     19                $revision_id = $this->create_topic_revision( $topic_id );
     20                update_post_meta( $topic_id, '_bbp_revision_log', array(
     21                        $revision_id => array( 'author' => 0, 'reason' => 'Updated.' ),
     22                ) );
     23                $this->assertSame( 'Topic content' . bbp_get_topic_revision_log( $topic_id ), bbp_topic_content_append_revisions( 'Topic content', $topic_id ) );
    2124        }
    2225
    … …  
    2427         * @covers ::bbp_topic_revision_log
    2528         * @covers ::bbp_get_topic_revision_log
    26          * @todo   Implement test_bbp_get_topic_revision_log().
    2729         */
    2830        public function test_bbp_get_topic_revision_log() {
    29                 // Remove the following lines when you implement this test.
    30                 $this->markTestIncomplete(
    31                         'This test has not been implemented yet.'
    32                 );
     31                $topic_id = $this->factory->topic->create();
     32                $this->assertFalse( bbp_get_topic_revision_log( $topic_id ) );
     33
     34                $revision_id = $this->create_topic_revision( $topic_id );
     35                update_post_meta( $topic_id, '_bbp_revision_log', array(
     36                        $revision_id => array( 'author' => 0, 'reason' => 'Clarified the question.' ),
     37                ) );
     38                $log = bbp_get_topic_revision_log( $topic_id );
     39
     40                $this->assertStringContainsString( 'bbp-topic-revision-log-' . $topic_id, $log );
     41                $this->assertStringContainsString( 'item-' . $revision_id, $log );
     42                $this->assertStringContainsString( 'Clarified the question.', $log );
     43                $this->expectOutputString( $log );
     44                bbp_topic_revision_log( $topic_id );
    3345        }
    3446
    3547        /**
    3648         * @covers ::bbp_get_topic_raw_revision_log
    37          * @todo   Implement test_bbp_get_topic_raw_revision_log().
    3849         */
    3950        public function test_bbp_get_topic_raw_revision_log() {
    40                 // Remove the following lines when you implement this test.
    41                 $this->markTestIncomplete(
    42                         'This test has not been implemented yet.'
    43                 );
     51                $topic_id = $this->factory->topic->create();
     52                $this->assertSame( array(), bbp_get_topic_raw_revision_log( $topic_id ) );
     53
     54                $log = array( 123 => array( 'author' => 0, 'reason' => 'Updated.' ) );
     55                update_post_meta( $topic_id, '_bbp_revision_log', $log );
     56                $this->assertSame( $log, bbp_get_topic_raw_revision_log( $topic_id ) );
    4457        }
    4558
    4659        /**
    4760         * @covers ::bbp_get_topic_revisions
    48          * @todo   Implement test_bbp_get_topic_revisions().
    4961         */
    5062        public function test_bbp_get_topic_revisions() {
    51                 // Remove the following lines when you implement this test.
    52                 $this->markTestIncomplete(
    53                         'This test has not been implemented yet.'
    54                 );
     63                $topic_id    = $this->factory->topic->create();
     64                $revision_id = $this->create_topic_revision( $topic_id );
     65                $revisions   = bbp_get_topic_revisions( $topic_id );
     66
     67                $this->assertArrayHasKey( $revision_id, $revisions );
     68                $this->assertSame( $topic_id, $revisions[ $revision_id ]->post_parent );
    5569        }
    5670
    5771        /**
    5872         * @covers ::bbp_get_topic_revision_count
    59          * @todo   Implement test_bbp_get_topic_revision_count().
    6073         */
    6174        public function test_bbp_get_topic_revision_count() {
    62                 // Remove the following lines when you implement this test.
    63                 $this->markTestIncomplete(
    64                         'This test has not been implemented yet.'
    65                 );
     75                $topic_id = $this->factory->topic->create();
     76                $this->assertSame( '0', bbp_get_topic_revision_count( $topic_id ) );
     77
     78                $this->create_topic_revision( $topic_id );
     79                $this->assertSame( '1', bbp_get_topic_revision_count( $topic_id ) );
     80                $this->assertSame( 1, bbp_get_topic_revision_count( $topic_id, true ) );
     81        }
     82
     83        private function create_topic_revision( $topic_id ) {
     84                wp_update_post( array( 'ID' => $topic_id, 'post_content' => 'Updated topic content.' ) );
     85                $revisions = wp_get_post_revisions( $topic_id );
     86
     87                $this->assertNotEmpty( $revisions );
     88                return key( $revisions );
    6689        }
    6790}
Note: See TracChangeset for help on using the changeset viewer.