wordpress-develop/tests/phpunit/tests/sitemaps/sitemaps-posts.php
Sergey Biryukov 164b22cf6a Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.
This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-02 00:35:36 +00:00

73 lines
1.9 KiB
PHP

<?php
/**
* @group sitemaps
*/
class Test_WP_Sitemaps_Posts extends WP_UnitTestCase {
/**
* Tests getting sitemap entries for post type page with 'posts' homepage.
*
* Ensures that an entry is added even if there are no pages.
*
* @ticket 50571
*/
public function test_get_sitemap_entries_homepage() {
update_option( 'show_on_front', 'posts' );
$posts_provider = new WP_Sitemaps_Posts();
$post_list = $posts_provider->get_sitemap_entries();
$expected = array(
array(
'loc' => home_url( '/?sitemap=posts&sitemap-subtype=page&paged=1' ),
),
);
$this->assertSame( $expected, $post_list );
}
/**
* Test ability to filter object subtypes.
*/
public function test_filter_sitemaps_post_types() {
$posts_provider = new WP_Sitemaps_Posts();
// Return an empty array to show that the list of subtypes is filterable.
add_filter( 'wp_sitemaps_post_types', '__return_empty_array' );
$subtypes = $posts_provider->get_object_subtypes();
$this->assertSame( array(), $subtypes, 'Could not filter posts subtypes.' );
}
/**
* Test `wp_sitemaps_posts_show_on_front_entry` filter.
*/
public function test_posts_show_on_front_entry() {
$posts_provider = new WP_Sitemaps_Posts();
update_option( 'show_on_front', 'page' );
add_filter( 'wp_sitemaps_posts_show_on_front_entry', array( $this, '_show_on_front_entry' ) );
$url_list = $posts_provider->get_url_list( 1, 'page' );
$this->assertSame( array(), $url_list );
update_option( 'show_on_front', 'posts' );
$url_list = $posts_provider->get_url_list( 1, 'page' );
$sitemap_entry = array_shift( $url_list );
$this->assertTrue( isset( $sitemap_entry['lastmod'] ) );
}
/**
* Callback for 'wp_sitemaps_posts_show_on_front_entry' filter.
*/
public function _show_on_front_entry( $sitemap_entry ) {
$sitemap_entry['lastmod'] = wp_date( DATE_W3C, time() );
return $sitemap_entry;
}
}