getDashboardUrl.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @group link
  4. * @covers ::get_dashboard_url
  5. */
  6. class Tests_Link_GetDashboardUrl extends WP_UnitTestCase {
  7. public static $user_id = false;
  8. public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
  9. self::$user_id = $factory->user->create( array( 'role' => 'administrator' ) );
  10. }
  11. public static function wpTearDownAfterClass() {
  12. if ( is_multisite() ) {
  13. wpmu_delete_user( self::$user_id );
  14. } else {
  15. wp_delete_user( self::$user_id );
  16. }
  17. }
  18. /**
  19. * @ticket 39065
  20. */
  21. public function test_get_dashboard_url_for_current_site_user() {
  22. $this->assertSame( admin_url(), get_dashboard_url( self::$user_id ) );
  23. }
  24. /**
  25. * @ticket 39065
  26. */
  27. public function test_get_dashboard_url_for_user_with_no_sites() {
  28. add_filter( 'get_blogs_of_user', '__return_empty_array' );
  29. $expected = is_multisite() ? user_admin_url() : admin_url();
  30. $this->assertSame( $expected, get_dashboard_url( self::$user_id ) );
  31. }
  32. /**
  33. * @ticket 39065
  34. * @group ms-required
  35. */
  36. public function test_get_dashboard_url_for_network_administrator_with_no_sites() {
  37. grant_super_admin( self::$user_id );
  38. add_filter( 'get_blogs_of_user', '__return_empty_array' );
  39. $expected = admin_url();
  40. $result = get_dashboard_url( self::$user_id );
  41. revoke_super_admin( self::$user_id );
  42. $this->assertSame( $expected, $result );
  43. }
  44. /**
  45. * @ticket 39065
  46. * @group ms-required
  47. */
  48. public function test_get_dashboard_url_for_administrator_of_different_site() {
  49. $site_id = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
  50. remove_user_from_blog( self::$user_id, get_current_blog_id() );
  51. $expected = get_admin_url( $site_id );
  52. $result = get_dashboard_url( self::$user_id );
  53. remove_user_from_blog( self::$user_id, $site_id );
  54. add_user_to_blog( get_current_blog_id(), self::$user_id, 'administrator' );
  55. wp_delete_site( $site_id );
  56. $this->assertSame( $expected, $result );
  57. }
  58. }