- Timestamp:
- 11/03/2016 03:15:28 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r39105 r39108 18 18 19 19 protected static $supported_formats; 20 21 protected $forbidden_cat; 20 22 21 23 public static function wpSetUpBeforeClass( $factory ) { … … 1505 1507 } 1506 1508 1509 /** 1510 * @ticket 38505 1511 */ 1512 public function test_create_post_with_categories_that_cannot_be_assigned_by_current_user() { 1513 $cats = self::factory()->category->create_many( 2 ); 1514 $this->forbidden_cat = $cats[1]; 1515 1516 wp_set_current_user( self::$editor_id ); 1517 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1518 $params = $this->set_post_data( array( 1519 'password' => 'testing', 1520 'categories' => $cats, 1521 ) ); 1522 $request->set_body_params( $params ); 1523 1524 add_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 1525 $response = $this->server->dispatch( $request ); 1526 remove_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 1527 1528 $this->assertErrorResponse( 'rest_cannot_assign_term', $response, 403 ); 1529 } 1530 1531 public function revoke_assign_term( $caps, $cap, $user_id, $args ) { 1532 if ( 'assign_term' === $cap && isset( $args[0] ) && $this->forbidden_cat == $args[0] ) { 1533 $caps = array( 'do_not_allow' ); 1534 } 1535 return $caps; 1536 } 1537 1507 1538 public function test_update_item() { 1508 1539 wp_set_current_user( self::$editor_id ); … … 1949 1980 $new_data = $response->get_data(); 1950 1981 $this->assertEquals( array(), $new_data['categories'] ); 1982 } 1983 1984 /** 1985 * @ticket 38505 1986 */ 1987 public function test_update_post_with_categories_that_cannot_be_assigned_by_current_user() { 1988 $cats = self::factory()->category->create_many( 2 ); 1989 $this->forbidden_cat = $cats[1]; 1990 1991 wp_set_current_user( self::$editor_id ); 1992 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1993 $params = $this->set_post_data( array( 1994 'password' => 'testing', 1995 'categories' => $cats, 1996 ) ); 1997 $request->set_body_params( $params ); 1998 1999 add_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 2000 $response = $this->server->dispatch( $request ); 2001 remove_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 2002 2003 $this->assertErrorResponse( 'rest_cannot_assign_term', $response, 403 ); 1951 2004 } 1952 2005
Note: See TracChangeset
for help on using the changeset viewer.