| 80 | |
| 81 | /** |
| 82 | * @group bp_moderate |
| 83 | */ |
| 84 | public function test_administrator_can_bp_moderate() { |
| 85 | $u = self::factory()->user->create( |
| 86 | array( |
| 87 | 'role' => 'administrator', |
| 88 | ) |
| 89 | ); |
| 90 | |
| 91 | $this->set_current_user( $u ); |
| 92 | |
| 93 | $this->assertTrue( bp_current_user_can( 'bp_moderate' ), 'Administrator can `bp_moderate` on default WordPress config' ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @group bp_moderate |
| 98 | */ |
| 99 | public function test_administrator_can_bp_moderate_emails() { |
| 100 | $u1 = self::factory()->user->create( |
| 101 | array( |
| 102 | 'role' => 'administrator', |
| 103 | ) |
| 104 | ); |
| 105 | $u2 = self::factory()->user->create( |
| 106 | array( |
| 107 | 'role' => 'administrator', |
| 108 | ) |
| 109 | ); |
| 110 | |
| 111 | $this->set_current_user( $u1 ); |
| 112 | |
| 113 | $email = self::factory()->post->create( |
| 114 | array( |
| 115 | 'post_type' => 'bp-email', |
| 116 | ) |
| 117 | ); |
| 118 | |
| 119 | $this->assertTrue( current_user_can( 'edit_post', $email ), 'Administrator should be able to edit emails they created' ); |
| 120 | |
| 121 | $this->set_current_user( $u2 ); |
| 122 | |
| 123 | $this->assertTrue( current_user_can( 'edit_post', $email ), 'Administrator should be able to edit emails others created when BuddyPress is not network activated' ); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * @group bp_moderate |
| 128 | */ |
| 129 | public function test_administrator_can_bp_moderate_network_activated() { |
| 130 | if ( ! is_multisite() ) { |
| 131 | $this->markTestSkipped( __METHOD__ . ' requires multisite.' ); |
| 132 | } |
| 133 | |
| 134 | $u1 = self::factory()->user->create( |
| 135 | array( |
| 136 | 'role' => 'administrator', |
| 137 | ) |
| 138 | ); |
| 139 | grant_super_admin( $u1 ); |
| 140 | |
| 141 | $u2 = self::factory()->user->create( |
| 142 | array( |
| 143 | 'role' => 'administrator', |
| 144 | ) |
| 145 | ); |
| 146 | |
| 147 | add_filter( 'bp_is_network_activated', '__return_true' ); |
| 148 | |
| 149 | // Swith & restore to reset the roles. |
| 150 | switch_to_blog( $this->blog_id ); |
| 151 | restore_current_blog(); |
| 152 | |
| 153 | $this->set_current_user( $u1 ); |
| 154 | $this->assertTrue( bp_current_user_can( 'bp_moderate' ), 'Only Super Admins can `bp_moderate` when BuddyPress is network activated' ); |
| 155 | |
| 156 | $this->set_current_user( $u2 ); |
| 157 | $this->assertFalse( bp_current_user_can( 'bp_moderate' ), 'Regular Admins cannot `bp_moderate` when BuddyPress is network activated' ); |
| 158 | |
| 159 | grant_super_admin( $u2 ); |
| 160 | $this->assertTrue( bp_current_user_can( 'bp_moderate' ), 'Only Super Admins can `bp_moderate` when BuddyPress is network activated' ); |
| 161 | |
| 162 | remove_filter( 'bp_is_network_activated', '__return_true' ); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @group bp_moderate |
| 167 | */ |
| 168 | public function test_administrator_can_bp_moderate_emails_network_activated() { |
| 169 | if ( ! is_multisite() ) { |
| 170 | $this->markTestSkipped( __METHOD__ . ' requires multisite.' ); |
| 171 | } |
| 172 | |
| 173 | $u1 = self::factory()->user->create( |
| 174 | array( |
| 175 | 'role' => 'administrator', |
| 176 | ) |
| 177 | ); |
| 178 | grant_super_admin( $u1 ); |
| 179 | |
| 180 | $u2 = self::factory()->user->create( |
| 181 | array( |
| 182 | 'role' => 'administrator', |
| 183 | ) |
| 184 | ); |
| 185 | |
| 186 | $email = self::factory()->post->create( |
| 187 | array( |
| 188 | 'post_type' => 'bp-email', |
| 189 | ) |
| 190 | ); |
| 191 | |
| 192 | add_filter( 'bp_is_network_activated', '__return_true' ); |
| 193 | |
| 194 | // Swith & restore to reset the roles. |
| 195 | switch_to_blog( $this->blog_id ); |
| 196 | restore_current_blog(); |
| 197 | |
| 198 | $this->set_current_user( $u1 ); |
| 199 | $this->assertTrue( current_user_can( 'edit_post', $email ), 'Super Admins should be able to edit emails they created' ); |
| 200 | |
| 201 | $this->set_current_user( $u2 ); |
| 202 | $this->assertFalse( current_user_can( 'edit_post', $email ), 'Administrator should not be able to edit emails others created when BuddyPress is network activated' ); |
| 203 | |
| 204 | grant_super_admin( $u2 ); |
| 205 | $this->assertTrue( current_user_can( 'edit_post', $email ), 'Super Admins should be able to edit emails others created' ); |
| 206 | |
| 207 | remove_filter( 'bp_is_network_activated', '__return_true' ); |
| 208 | } |