| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @group link |
| 5 | */ |
| 6 | class Tests_Link_GetDashboardUrl extends WP_UnitTestCase { |
| 7 | |
| 8 | /** |
| 9 | * @ticket 39065 |
| 10 | */ |
| 11 | public function test_get_dashboard_url_for_current_site_user() { |
| 12 | $user_id = self::factory()->user->create(); |
| 13 | |
| 14 | $this->assertEquals( admin_url(), get_dashboard_url( $user_id ) ); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * @ticket 39065 |
| 19 | */ |
| 20 | public function test_get_dashboard_url_for_user_with_no_sites() { |
| 21 | $user_id = self::factory()->user->create(); |
| 22 | |
| 23 | add_filter( 'get_blogs_of_user', '__return_empty_array' ); |
| 24 | |
| 25 | $expected = is_multisite() ? user_admin_url() : admin_url(); |
| 26 | |
| 27 | $this->assertEquals( $expected, get_dashboard_url( $user_id ) ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @ticket 39065 |
| 32 | */ |
| 33 | public function test_get_dashboard_url_for_network_administrator_with_no_sites() { |
| 34 | if ( ! is_multisite() ) { |
| 35 | $this->markTestSkipped( 'Test only runs in multisite.' ); |
| 36 | } |
| 37 | |
| 38 | $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); |
| 39 | grant_super_admin( $user_id ); |
| 40 | |
| 41 | add_filter( 'get_blogs_of_user', '__return_empty_array' ); |
| 42 | |
| 43 | $this->assertEquals( admin_url(), get_dashboard_url( $user_id ) ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @ticket 39065 |
| 48 | */ |
| 49 | public function test_get_dashboard_url_for_administrator_of_different_site() { |
| 50 | if ( ! is_multisite() ) { |
| 51 | $this->markTestSkipped( 'Test only runs in multisite.' ); |
| 52 | } |
| 53 | |
| 54 | $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); |
| 55 | remove_user_from_blog( $user_id, get_current_blog_id() ); |
| 56 | |
| 57 | $site_id = self::factory()->blog->create( array( 'user_id' => $user_id ) ); |
| 58 | |
| 59 | $this->assertEquals( get_admin_url( $site_id ), get_dashboard_url( $user_id ) ); |
| 60 | } |
| 61 | } |