| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @group link |
| 5 | */ |
| 6 | class Tests_Link_GetDashboardUrl extends WP_UnitTestCase { |
| 7 | static $user_id = false; |
| 8 | |
| 9 | public static function wpSetUpBeforeClass( $factory ) { |
| 10 | self::$user_id = $factory->user->create( array( 'role' => 'administrator' ) ); |
| 11 | } |
| 12 | |
| 13 | public static function wpTearDownAfterClass() { |
| 14 | wpmu_delete_user( self::$user_id ); |
| 15 | |
| 16 | global $wp_rewrite; |
| 17 | $wp_rewrite->init(); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * @ticket 39065 |
| 22 | */ |
| 23 | public function test_get_dashboard_url_for_current_site_user() { |
| 24 | $this->assertEquals( admin_url(), get_dashboard_url( self::$user_id ) ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @ticket 39065 |
| 29 | */ |
| 30 | public function test_get_dashboard_url_for_user_with_no_sites() { |
| 31 | add_filter( 'get_blogs_of_user', '__return_empty_array' ); |
| 32 | |
| 33 | $expected = is_multisite() ? user_admin_url() : admin_url(); |
| 34 | |
| 35 | $this->assertEquals( $expected, get_dashboard_url( self::$user_id ) ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @ticket 39065 |
| 40 | */ |
| 41 | public function test_get_dashboard_url_for_network_administrator_with_no_sites() { |
| 42 | if ( ! is_multisite() ) { |
| 43 | $this->markTestSkipped( 'Test only runs in multisite.' ); |
| 44 | } |
| 45 | |
| 46 | grant_super_admin( self::$user_id ); |
| 47 | |
| 48 | add_filter( 'get_blogs_of_user', '__return_empty_array' ); |
| 49 | |
| 50 | $expected = admin_url(); |
| 51 | $result = get_dashboard_url( self::$user_id ); |
| 52 | |
| 53 | revoke_super_admin( self::$user_id ); |
| 54 | |
| 55 | $this->assertEquals( $expected, $result ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @ticket 39065 |
| 60 | */ |
| 61 | public function test_get_dashboard_url_for_administrator_of_different_site() { |
| 62 | if ( ! is_multisite() ) { |
| 63 | $this->markTestSkipped( 'Test only runs in multisite.' ); |
| 64 | } |
| 65 | |
| 66 | $site_id = self::factory()->blog->create( array( 'user_id' => self::$user_id ) ); |
| 67 | |
| 68 | remove_user_from_blog( self::$user_id, get_current_blog_id() ); |
| 69 | |
| 70 | $expected = get_admin_url( $site_id ); |
| 71 | $result = get_dashboard_url( self::$user_id ); |
| 72 | |
| 73 | remove_user_from_blog( self::$user_id, $site_id ); |
| 74 | add_user_to_blog( get_current_blog_id(), self::$user_id, 'administrator'); |
| 75 | |
| 76 | wpmu_delete_blog( $site_id, true ); |
| 77 | |
| 78 | $this->assertEquals( $expected, $result ); |
| 79 | } |
| 80 | } |