Make WordPress Core


Ignore:
Timestamp:
07/23/2022 03:40:10 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Revisions: Correct the function name for retrieving the last revision ID and total count.

Includes:

  • Renaming the function to wp_get_last_revision_id_and_total_count().
  • Making the default value for $post consistent with wp_get_post_revisions().
  • Making WP_Error codes more specific and using them in test assertions.
  • Adjusting the function description per the documentation standards.

Follow-up to [53759].

Props JustinSainton, SergeyBiryukov.
See #55857.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/revisions.php

    r53759 r53769  
    657657
    658658        /**
    659          * Tests that wp_get_lastest_revision_id_and_total_count() returns last revision id and total count.
     659         * Tests that wp_get_last_revision_id_and_total_count() returns the last revision ID and total count.
    660660         *
    661661         * @ticket 55857
     
    675675                $post_revisions     = wp_get_post_revisions( $post_id );
    676676                $last_post_revision = current( $post_revisions );
    677                 $revision           = wp_get_lastest_revision_id_and_total_count( $post_id );
     677                $revision           = wp_get_last_revision_id_and_total_count( $post_id );
    678678
    679679                $this->assertSame(
    680680                        $last_post_revision->ID,
    681681                        $revision['revision'],
    682                         'Failed asserting latest revision id.'
     682                        'The last revision ID does not match.'
    683683                );
    684684
     
    686686                        count( $post_revisions ),
    687687                        $revision['count'],
    688                         'Failed asserting total count of revision.'
    689                 );
    690         }
    691 
    692         /**
    693          * Tests that wp_get_lastest_revision_id_and_total_count() when no revisions.
     688                        'The total count of revisions does not match.'
     689                );
     690        }
     691
     692        /**
     693         * Tests that wp_get_last_revision_id_and_total_count() returns a WP_Error when no revisions exist.
    694694         *
    695695         * @ticket 55857
    696696         */
    697697        public function test_wp_get_last_revision_id_and_total_count_no_revisions() {
    698                 $revision = wp_get_lastest_revision_id_and_total_count( null );
    699                 $this->assertWPError( $revision, 'Invalid Post, non existing revisions.' );
    700                 $this->assertSame( $revision->get_error_message(), 'Invalid post.' );
     698                $revision = wp_get_last_revision_id_and_total_count( null );
     699
     700                $this->assertWPError( $revision, 'Invalid post, no revisions should exist.' );
     701                $this->assertSame( $revision->get_error_code(), 'invalid_post' );
    701702
    702703                add_filter( 'wp_revisions_to_keep', '__return_zero' );
    703704                $post_id  = self::factory()->post->create();
    704                 $revision = wp_get_lastest_revision_id_and_total_count( $post_id );
    705                 $this->assertWPError( $revision, 'Revisions should be not enabled.' );
    706                 $this->assertSame( $revision->get_error_message(), 'Revisions not enabled.' );
     705                $revision = wp_get_last_revision_id_and_total_count( $post_id );
     706
     707                $this->assertWPError( $revision, 'Revisions should not be enabled.' );
     708                $this->assertSame( $revision->get_error_code(), 'revisions_not_enabled' );
    707709        }
    708710
Note: See TracChangeset for help on using the changeset viewer.