Make WordPress Core

Changeset 53556


Ignore:
Timestamp:
06/22/2022 04:50:14 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Tests: Improve the test for sticky posts not being moved to the front in sitemaps.

  • Give the test method a most descriptive name.
  • Use a single assertion for the URL list instead of a foreach loop to provide more context in case of failure.
  • Add a failure message to each assertion, as there are multiple assertions used in the test.

Follow-up to [53548].

See #55633.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/sitemaps/wpSitemapsPosts.php

    r53550 r53556  
    6464
    6565    /**
     66     * Callback for 'wp_sitemaps_posts_show_on_front_entry' filter.
     67     */
     68    public function _show_on_front_entry( $sitemap_entry ) {
     69        $sitemap_entry['lastmod'] = wp_date( DATE_W3C, time() );
     70
     71        return $sitemap_entry;
     72    }
     73
     74    /**
    6675     * Tests that sticky posts are not moved to the front of the first page of the post sitemap.
    6776     *
    6877     * @ticket 55633
    6978     */
    70     public function test_posts_sticky_posts() {
     79    public function test_posts_sticky_posts_not_moved_to_front() {
    7180        $factory = self::factory();
    7281
     
    8089        $url_list = $posts_provider->get_url_list( 1, 'post' );
    8190
    82         $this->assertCount( count( $post_ids ), $url_list );
     91        $this->assertCount( count( $post_ids ), $url_list, 'The post count did not match.' );
     92
     93        $expected = array();
     94
     95        foreach ( $post_ids as $post_id ) {
     96            $expected[] = array( 'loc' => home_url( "?p={$post_id}" ) );
     97        }
     98
    8399        // Check that the URL list is still in the order of the post IDs (i.e., sticky post wasn't moved to the front).
    84         foreach ( $post_ids as $idx => $post_id ) {
    85             $this->assertSame( array( 'loc' => home_url( "?p={$post_id}" ) ), $url_list[ $idx ] );
    86         }
    87     }
    88 
    89     /**
    90      * Callback for 'wp_sitemaps_posts_show_on_front_entry' filter.
    91      */
    92     public function _show_on_front_entry( $sitemap_entry ) {
    93         $sitemap_entry['lastmod'] = wp_date( DATE_W3C, time() );
    94 
    95         return $sitemap_entry;
     100        $this->assertSame( $expected, $url_list, 'The post order did not match.' );
    96101    }
    97102}
Note: See TracChangeset for help on using the changeset viewer.