Ticket #44468: 44468.diff
File 44468.diff, 3.5 KB (added by , 6 years ago) |
---|
-
tests/phpunit/tests/user/capabilities.php
215 215 216 216 } 217 217 218 final private function _getSingleSiteDynamicPrimitiveCaps() { 219 return array( 220 'install_languages' => array( 'administrator' ), 221 ); 222 } 223 224 final private function _getMultiSiteDynamicPrimitiveCaps() { 225 return array( 226 'install_languages' => array(), 227 ); 228 } 229 218 230 final private function _getSingleSiteMetaCaps() { 219 231 return array( 220 232 'create_sites' => array(), … … 292 304 } 293 305 294 306 protected function getAllCapsAndRoles() { 295 return $this->getPrimitiveCapsAndRoles() + $this->get MetaCapsAndRoles();307 return $this->getPrimitiveCapsAndRoles() + $this->getDynamicPrimitiveCapsAndRoles() + $this->getMetaCapsAndRoles(); 296 308 } 297 309 298 310 protected function getPrimitiveCapsAndRoles() { … … 303 315 } 304 316 } 305 317 318 protected function getDynamicPrimitiveCapsAndRoles() { 319 if ( is_multisite() ) { 320 return $this->_getMultiSiteDynamicPrimitiveCaps(); 321 } else { 322 return $this->_getSingleSiteDynamicPrimitiveCaps(); 323 } 324 } 325 306 326 protected function getMetaCapsAndRoles() { 307 327 if ( is_multisite() ) { 308 328 return $this->_getMultiSiteMetaCaps(); … … 319 339 sort( $multi_primitive ); 320 340 $this->assertEquals( $single_primitive, $multi_primitive ); 321 341 342 343 $single_dynamic_primitive = array_keys( $this->_getSingleSiteDynamicPrimitiveCaps() ); 344 $multi_dynamic_primitive = array_keys( $this->_getMultiSiteDynamicPrimitiveCaps() ); 345 sort( $single_dynamic_primitive ); 346 sort( $multi_dynamic_primitive ); 347 $this->assertEquals( $single_dynamic_primitive, $multi_dynamic_primitive ); 348 322 349 $single_meta = array_keys( $this->_getSingleSiteMetaCaps() ); 323 350 $multi_meta = array_keys( $this->_getMultiSiteMetaCaps() ); 324 351 sort( $single_meta ); … … 396 423 } 397 424 398 425 /** 426 * Test the tests. All dynamic primitive capabilities are checked twice against the user, 427 * once with the 'user_has_cap' filters applied and once without. An administrator user 428 * is used for the test. Note that super admin capabilities in multisite are skipped since 429 * they cannot be tested with this method. 430 * 431 * @group capTestTests 432 */ 433 public function testDynamicPrimitiveCapsTestsAreCorrect() { 434 $user = self::$users['administrator']; 435 436 $caps = $this->getDynamicPrimitiveCapsAndRoles(); 437 438 $filtered = array(); 439 foreach ( $caps as $cap => $roles ) { 440 if ( empty( $roles ) ) { 441 continue; 442 } 443 444 if ( $user->has_cap( $cap ) ) { 445 $filtered[] = $cap; 446 } 447 } 448 449 remove_all_filters( 'user_has_cap' ); 450 451 $unfiltered_granted = array(); 452 $unfiltered_revoked = array(); 453 foreach ( $caps as $cap => $roles ) { 454 if ( empty( $roles ) ) { 455 continue; 456 } 457 458 if ( $user->has_cap( $cap ) ) { 459 $unfiltered_granted[] = $cap; 460 } else { 461 $unfiltered_revoked[] = $cap; 462 } 463 } 464 465 $missing_dynamic_primitive_cap_checks = array_diff( $unfiltered_revoked, $filtered ); 466 $this->assertSame( array(), $missing_dynamic_primitive_cap_checks, 'These dynamic primitive capabilities are not correctly granted' ); 467 468 $incorrect_dynamic_primitive_cap_checks = array_intersect( $filtered, $unfiltered_granted ); 469 $this->assertSame( array(), $incorrect_dynamic_primitive_cap_checks, 'These capabilities are not dynamic primitive' ); 470 } 471 472 /** 399 473 * Test the tests. All meta capabilities should have a condition in the `map_meta_cap()` 400 474 * function that handles the capability. 401 475 *