sitemaps-users.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * @group sitemaps
  4. */
  5. class Test_WP_Sitemaps_Users extends WP_UnitTestCase {
  6. /**
  7. * List of user IDs.
  8. *
  9. * @var array
  10. */
  11. public static $users;
  12. /**
  13. * Editor ID for use in some tests.
  14. *
  15. * @var int
  16. */
  17. public static $editor_id;
  18. /**
  19. * Set up fixtures.
  20. *
  21. * @param WP_UnitTest_Factory $factory A WP_UnitTest_Factory object.
  22. */
  23. public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
  24. self::$users = $factory->user->create_many( 10, array( 'role' => 'editor' ) );
  25. self::$editor_id = self::$users[0];
  26. }
  27. /**
  28. * Test getting a URL list for a users sitemap page via
  29. * WP_Sitemaps_Users::get_url_list().
  30. */
  31. public function test_get_url_list_users() {
  32. // Set up the user to an editor to assign posts to other users.
  33. wp_set_current_user( self::$editor_id );
  34. // Create a set of posts for each user and generate the expected URL list data.
  35. $expected = array_map(
  36. static function ( $user_id ) {
  37. $post = self::factory()->post->create_and_get( array( 'post_author' => $user_id ) );
  38. return array(
  39. 'loc' => get_author_posts_url( $user_id ),
  40. );
  41. },
  42. self::$users
  43. );
  44. $user_provider = new WP_Sitemaps_Users();
  45. $url_list = $user_provider->get_url_list( 1 );
  46. $this->assertSameSets( $expected, $url_list );
  47. }
  48. }