Changeset 42343 for trunk/tests/phpunit/tests/user/mapMetaCap.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user/mapMetaCap.php
r40525 r42343 20 20 self::$super_admins = $GLOBALS['super_admins']; 21 21 } 22 $user = new WP_User( self::$user_id );22 $user = new WP_User( self::$user_id ); 23 23 $GLOBALS['super_admins'] = array( $user->user_login ); 24 24 25 25 register_post_type( self::$post_type ); 26 26 27 self::$post_id = $factory->post->create( array( 28 'post_type' => self::$post_type, 29 'post_status' => 'private', 30 'post_author' => self::$author_id, 31 ) ); 27 self::$post_id = $factory->post->create( 28 array( 29 'post_type' => self::$post_type, 30 'post_status' => 'private', 31 'post_author' => self::$author_id, 32 ) 33 ); 32 34 } 33 35 … … 49 51 function test_capability_type_post_with_no_extra_caps() { 50 52 51 register_post_type( self::$post_type, array( 52 'capability_type' => 'post', 53 ) ); 53 register_post_type( 54 self::$post_type, array( 55 'capability_type' => 'post', 56 ) 57 ); 54 58 $post_type_object = get_post_type_object( self::$post_type ); 55 59 56 60 $this->assertTrue( $post_type_object->map_meta_cap ); 57 61 58 $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ), 59 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 60 $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ), 61 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 62 63 $this->assertEquals( array( 'read_private_posts' ), 64 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 65 $this->assertEquals( array( 'read_private_posts' ), 66 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 67 68 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 69 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 70 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 71 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 62 $this->assertEquals( 63 array( 'edit_others_posts', 'edit_private_posts' ), 64 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) 65 ); 66 $this->assertEquals( 67 array( 'edit_others_posts', 'edit_private_posts' ), 68 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) 69 ); 70 71 $this->assertEquals( 72 array( 'read_private_posts' ), 73 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) 74 ); 75 $this->assertEquals( 76 array( 'read_private_posts' ), 77 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) 78 ); 79 80 $this->assertEquals( 81 array( 'delete_others_posts', 'delete_private_posts' ), 82 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) 83 ); 84 $this->assertEquals( 85 array( 'delete_others_posts', 'delete_private_posts' ), 86 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) 87 ); 72 88 } 73 89 74 90 function test_custom_capability_type_with_map_meta_cap() { 75 register_post_type( self::$post_type, array( 76 'capability_type' => 'book', 77 'map_meta_cap' => true, 78 ) ); 79 80 $post_type_object = get_post_type_object( self::$post_type ); 81 82 $this->assertEquals( array( 'edit_others_books', 'edit_private_books' ), 83 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 84 $this->assertEquals( array( 'edit_others_books', 'edit_private_books' ), 85 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 86 87 $this->assertEquals( array( 'read_private_books' ), 88 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 89 $this->assertEquals( array( 'read_private_books' ), 90 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 91 92 $this->assertEquals( array( 'delete_others_books', 'delete_private_books' ), 93 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 94 $this->assertEquals( array( 'delete_others_books', 'delete_private_books' ), 95 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 91 register_post_type( 92 self::$post_type, array( 93 'capability_type' => 'book', 94 'map_meta_cap' => true, 95 ) 96 ); 97 98 $post_type_object = get_post_type_object( self::$post_type ); 99 100 $this->assertEquals( 101 array( 'edit_others_books', 'edit_private_books' ), 102 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) 103 ); 104 $this->assertEquals( 105 array( 'edit_others_books', 'edit_private_books' ), 106 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) 107 ); 108 109 $this->assertEquals( 110 array( 'read_private_books' ), 111 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) 112 ); 113 $this->assertEquals( 114 array( 'read_private_books' ), 115 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) 116 ); 117 118 $this->assertEquals( 119 array( 'delete_others_books', 'delete_private_books' ), 120 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) 121 ); 122 $this->assertEquals( 123 array( 'delete_others_books', 'delete_private_books' ), 124 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) 125 ); 96 126 } 97 127 98 128 function test_capability_type_post_with_one_renamed_cap() { 99 register_post_type( self::$post_type, array( 100 'capability_type' => 'post', 101 'capabilities' => array( 'edit_posts' => 'edit_books' ), 102 ) ); 129 register_post_type( 130 self::$post_type, array( 131 'capability_type' => 'post', 132 'capabilities' => array( 'edit_posts' => 'edit_books' ), 133 ) 134 ); 103 135 104 136 $post_type_object = get_post_type_object( self::$post_type ); … … 106 138 $this->assertFalse( $post_type_object->map_meta_cap ); 107 139 108 $this->assertEquals( array( 'edit_post' ), 109 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 110 $this->assertEquals( array( 'edit_post' ), 111 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 112 113 $this->assertEquals( array( 'read_post' ), 114 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 115 $this->assertEquals( array( 'read_post' ), 116 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 117 118 $this->assertEquals( array( 'delete_post' ), 119 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 120 $this->assertEquals( array( 'delete_post' ), 121 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 140 $this->assertEquals( 141 array( 'edit_post' ), 142 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) 143 ); 144 $this->assertEquals( 145 array( 'edit_post' ), 146 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) 147 ); 148 149 $this->assertEquals( 150 array( 'read_post' ), 151 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) 152 ); 153 $this->assertEquals( 154 array( 'read_post' ), 155 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) 156 ); 157 158 $this->assertEquals( 159 array( 'delete_post' ), 160 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) 161 ); 162 $this->assertEquals( 163 array( 'delete_post' ), 164 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) 165 ); 122 166 } 123 167 124 168 function test_capability_type_post_map_meta_cap_true_with_renamed_cap() { 125 register_post_type( self::$post_type, array( 126 'capability_type' => 'post', 127 'map_meta_cap' => true, 128 'capabilities' => array( 129 'edit_post' => 'edit_book', // maps back to itself. 130 'edit_others_posts' => 'edit_others_books', 131 ), 132 ) ); 169 register_post_type( 170 self::$post_type, array( 171 'capability_type' => 'post', 172 'map_meta_cap' => true, 173 'capabilities' => array( 174 'edit_post' => 'edit_book', // maps back to itself. 175 'edit_others_posts' => 'edit_others_books', 176 ), 177 ) 178 ); 133 179 134 180 $post_type_object = get_post_type_object( self::$post_type ); … … 136 182 $this->assertTrue( $post_type_object->map_meta_cap ); 137 183 138 $this->assertEquals( array( 'edit_others_books', 'edit_private_posts' ), 139 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 140 $this->assertEquals( array( 'edit_others_books', 'edit_private_posts' ), 141 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 142 143 $this->assertEquals( array( 'read_private_posts' ), 144 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 145 $this->assertEquals( array( 'read_private_posts' ), 146 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 147 148 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 149 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 150 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 151 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 184 $this->assertEquals( 185 array( 'edit_others_books', 'edit_private_posts' ), 186 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) 187 ); 188 $this->assertEquals( 189 array( 'edit_others_books', 'edit_private_posts' ), 190 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) 191 ); 192 193 $this->assertEquals( 194 array( 'read_private_posts' ), 195 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) 196 ); 197 $this->assertEquals( 198 array( 'read_private_posts' ), 199 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) 200 ); 201 202 $this->assertEquals( 203 array( 'delete_others_posts', 'delete_private_posts' ), 204 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) 205 ); 206 $this->assertEquals( 207 array( 'delete_others_posts', 'delete_private_posts' ), 208 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) 209 ); 152 210 } 153 211 154 212 function test_capability_type_post_with_all_meta_caps_renamed() { 155 register_post_type( self::$post_type, array( 156 'capability_type' => 'post', 157 'capabilities' => array( 158 'edit_post' => 'edit_book', 159 'read_post' => 'read_book', 160 'delete_post' => 'delete_book', 161 ), 162 ) ); 213 register_post_type( 214 self::$post_type, array( 215 'capability_type' => 'post', 216 'capabilities' => array( 217 'edit_post' => 'edit_book', 218 'read_post' => 'read_book', 219 'delete_post' => 'delete_book', 220 ), 221 ) 222 ); 163 223 164 224 $post_type_object = get_post_type_object( self::$post_type ); … … 166 226 $this->assertFalse( $post_type_object->map_meta_cap ); 167 227 168 $this->assertEquals( array( 'edit_book' ), 169 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 170 $this->assertEquals( array( 'edit_book' ), 171 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 172 173 $this->assertEquals( array( 'read_book' ), 174 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 175 $this->assertEquals( array( 'read_book' ), 176 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 177 178 $this->assertEquals( array( 'delete_book' ), 179 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 180 $this->assertEquals( array( 'delete_book' ), 181 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 228 $this->assertEquals( 229 array( 'edit_book' ), 230 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) 231 ); 232 $this->assertEquals( 233 array( 'edit_book' ), 234 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) 235 ); 236 237 $this->assertEquals( 238 array( 'read_book' ), 239 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) 240 ); 241 $this->assertEquals( 242 array( 'read_book' ), 243 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) 244 ); 245 246 $this->assertEquals( 247 array( 'delete_book' ), 248 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) 249 ); 250 $this->assertEquals( 251 array( 'delete_book' ), 252 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) 253 ); 182 254 } 183 255 184 256 function test_capability_type_post_with_all_meta_caps_renamed_mapped() { 185 register_post_type( self::$post_type, array( 186 'capability_type' => 'post', 187 'map_meta_cap' => true, 188 'capabilities' => array( 189 'edit_post' => 'edit_book', 190 'read_post' => 'read_book', 191 'delete_post' => 'delete_book', 192 ), 193 ) ); 257 register_post_type( 258 self::$post_type, array( 259 'capability_type' => 'post', 260 'map_meta_cap' => true, 261 'capabilities' => array( 262 'edit_post' => 'edit_book', 263 'read_post' => 'read_book', 264 'delete_post' => 'delete_book', 265 ), 266 ) 267 ); 194 268 195 269 $post_type_object = get_post_type_object( self::$post_type ); … … 197 271 $this->assertTrue( $post_type_object->map_meta_cap ); 198 272 199 $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ), 200 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 201 $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ), 202 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 203 204 $this->assertEquals( array( 'read_private_posts' ), 205 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 206 $this->assertEquals( array( 'read_private_posts' ), 207 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 208 209 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 210 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 211 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 212 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 273 $this->assertEquals( 274 array( 'edit_others_posts', 'edit_private_posts' ), 275 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) 276 ); 277 $this->assertEquals( 278 array( 'edit_others_posts', 'edit_private_posts' ), 279 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) 280 ); 281 282 $this->assertEquals( 283 array( 'read_private_posts' ), 284 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) 285 ); 286 $this->assertEquals( 287 array( 'read_private_posts' ), 288 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) 289 ); 290 291 $this->assertEquals( 292 array( 'delete_others_posts', 'delete_private_posts' ), 293 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) 294 ); 295 $this->assertEquals( 296 array( 'delete_others_posts', 'delete_private_posts' ), 297 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) 298 ); 213 299 } 214 300 … … 248 334 */ 249 335 function test_authorless_posts_capabilties() { 250 $post_id = self::factory()->post->create( array( 'post_author' => 0, 'post_type' => 'post', 'post_status' => 'publish' ) ); 251 $editor = self::factory()->user->create( array( 'role' => 'editor' ) ); 336 $post_id = self::factory()->post->create( 337 array( 338 'post_author' => 0, 339 'post_type' => 'post', 340 'post_status' => 'publish', 341 ) 342 ); 343 $editor = self::factory()->user->create( array( 'role' => 'editor' ) ); 252 344 253 345 $this->assertEquals( array( 'edit_others_posts', 'edit_published_posts' ), map_meta_cap( 'edit_post', $editor, $post_id ) ); … … 262 354 */ 263 355 function test_only_users_who_can_manage_options_can_delete_page_on_front() { 264 $post_id = self::factory()->post->create( array( 265 'post_type' => 'page', 266 'post_status' => 'publish', 267 ) ); 356 $post_id = self::factory()->post->create( 357 array( 358 'post_type' => 'page', 359 'post_status' => 'publish', 360 ) 361 ); 268 362 269 363 update_option( 'page_on_front', $post_id ); … … 280 374 */ 281 375 function test_only_users_who_can_manage_options_can_delete_page_for_posts() { 282 $post_id = self::factory()->post->create( array( 283 'post_type' => 'page', 284 'post_status' => 'publish', 285 ) ); 376 $post_id = self::factory()->post->create( 377 array( 378 'post_type' => 'page', 379 'post_status' => 'publish', 380 ) 381 ); 286 382 287 383 update_option( 'page_for_posts', $post_id );
Note: See TracChangeset
for help on using the changeset viewer.