- Timestamp:
- 12/17/2018 05:21:05 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43917
- Property svn:mergeinfo changed
-
trunk/tests/phpunit/tests/rest-api/rest-blocks-controller.php
r44150 r44268 30 30 31 31 /** 32 * Our fake user 's ID.33 * 34 * @since 5.0.0 35 * 36 * @var int37 */ 38 protected static $user_id ;32 * Our fake user IDs, keyed by their role. 33 * 34 * @since 5.0.0 35 * 36 * @var array 37 */ 38 protected static $user_ids; 39 39 40 40 /** … … 51 51 'post_status' => 'publish', 52 52 'post_title' => 'My cool block', 53 'post_content' => '<!-- wp: core/paragraph --><p>Hello!</p><!-- /wp:core/paragraph -->',53 'post_content' => '<!-- wp:paragraph --><p>Hello!</p><!-- /wp:paragraph -->', 54 54 ) 55 55 ); 56 56 57 self::$user_id = $factory->user->create(58 array(59 'role' => 'editor',60 )57 self::$user_ids = array( 58 'editor' => $factory->user->create( array( 'role' => 'editor' ) ), 59 'author' => $factory->user->create( array( 'role' => 'author' ) ), 60 'contributor' => $factory->user->create( array( 'role' => 'contributor' ) ), 61 61 ); 62 62 } … … 70 70 wp_delete_post( self::$post_id ); 71 71 72 self::delete_user( self::$user_id ); 72 foreach ( self::$user_ids as $user_id ) { 73 self::delete_user( $user_id ); 74 } 73 75 } 74 76 … … 115 117 public function test_capabilities( $action, $role, $expected_status ) { 116 118 if ( $role ) { 117 $user_id = $this->factory->user->create( array( 'role' => $role ) );119 $user_id = self::$user_ids[ $role ]; 118 120 wp_set_current_user( $user_id ); 119 121 } else { … … 127 129 array( 128 130 'title' => 'Test', 129 'content' => '<!-- wp: core/paragraph --><p>Test</p><!-- /wp:core/paragraph -->',131 'content' => '<!-- wp:paragraph --><p>Test</p><!-- /wp:paragraph -->', 130 132 ) 131 133 ); … … 150 152 'post_status' => 'publish', 151 153 'post_title' => 'My cool block', 152 'post_content' => '<!-- wp: core/paragraph --><p>Hello!</p><!-- /wp:core/paragraph -->',154 'post_content' => '<!-- wp:paragraph --><p>Hello!</p><!-- /wp:paragraph -->', 153 155 'post_author' => $user_id, 154 156 ) … … 159 161 array( 160 162 'title' => 'Test', 161 'content' => '<!-- wp: core/paragraph --><p>Test</p><!-- /wp:core/paragraph -->',163 'content' => '<!-- wp:paragraph --><p>Test</p><!-- /wp:paragraph -->', 162 164 ) 163 165 ); … … 180 182 array( 181 183 'title' => 'Test', 182 'content' => '<!-- wp: core/paragraph --><p>Test</p><!-- /wp:core/paragraph -->',184 'content' => '<!-- wp:paragraph --><p>Test</p><!-- /wp:paragraph -->', 183 185 ) 184 186 ); … … 197 199 $this->fail( "'$action' is not a valid action." ); 198 200 } 199 200 if ( isset( $user_id ) ) { 201 self::delete_user( $user_id ); 202 } 201 } 202 203 /** 204 * Check that the raw title and content of a block can be accessed when there 205 * is no set schema, and that the rendered content of a block is not included 206 * in the response. 207 */ 208 public function test_content() { 209 wp_set_current_user( self::$user_ids['author'] ); 210 211 $request = new WP_REST_Request( 'GET', '/wp/v2/blocks/' . self::$post_id ); 212 $response = rest_get_server()->dispatch( $request ); 213 $data = $response->get_data(); 214 215 $this->assertEquals( 216 array( 217 'raw' => 'My cool block', 218 ), 219 $data['title'] 220 ); 221 $this->assertEquals( 222 array( 223 'raw' => '<!-- wp:paragraph --><p>Hello!</p><!-- /wp:paragraph -->', 224 'protected' => false, 225 ), 226 $data['content'] 227 ); 203 228 } 204 229 }
Note: See TracChangeset
for help on using the changeset viewer.