- Timestamp:
- 10/27/2016 02:56:28 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php
r38832 r38975 11 11 */ 12 12 class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase { 13 protected static $post_id; 14 protected static $page_id; 15 16 protected static $editor_id; 17 protected static $contributor_id; 18 19 public static function wpSetUpBeforeClass( $factory ) { 20 self::$post_id = $factory->post->create(); 21 self::$page_id = $factory->post->create( array( 'post_type' => 'page' ) ); 22 23 self::$editor_id = $factory->user->create( array( 24 'role' => 'editor', 25 ) ); 26 self::$contributor_id = $factory->user->create( array( 27 'role' => 'contributor', 28 ) ); 29 30 wp_update_post( array( 'post_content' => 'This content is better.', 'ID' => self::$post_id ) ); 31 wp_update_post( array( 'post_content' => 'This content is marvelous.', 'ID' => self::$post_id ) ); 32 } 33 34 public static function wpTearDownAfterClass() { 35 // Also deletes revisions. 36 wp_delete_post( self::$post_id, true ); 37 wp_delete_post( self::$page_id, true ); 38 39 self::delete_user( self::$editor_id ); 40 self::delete_user( self::$contributor_id ); 41 } 13 42 14 43 public function setUp() { 15 44 parent::setUp(); 16 $this->post_id = $this->factory->post->create(); 17 $this->page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 18 19 $this->editor_id = $this->factory->user->create( array( 20 'role' => 'editor', 21 ) ); 22 $this->contributor_id = $this->factory->user->create( array( 23 'role' => 'contributor', 24 ) ); 25 26 wp_update_post( array( 'post_content' => 'This content is better.', 'ID' => $this->post_id ) ); 27 wp_update_post( array( 'post_content' => 'This content is marvelous.', 'ID' => $this->post_id ) ); 28 $revisions = wp_get_post_revisions( $this->post_id ); 45 46 $revisions = wp_get_post_revisions( self::$post_id ); 29 47 $this->revision_1 = array_pop( $revisions ); 30 48 $this->revision_id1 = $this->revision_1->ID; … … 43 61 public function test_context_param() { 44 62 // Collection 45 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . $this->post_id . '/revisions' );63 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 46 64 $response = $this->server->dispatch( $request ); 47 65 $data = $response->get_data(); … … 49 67 $this->assertEqualSets( array( 'view', 'edit', 'embed' ), $data['endpoints'][0]['args']['context']['enum'] ); 50 68 // Single 51 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . $this->post_id . '/revisions/' . $this->revision_1->ID );69 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_1->ID ); 52 70 $response = $this->server->dispatch( $request ); 53 71 $data = $response->get_data(); … … 57 75 58 76 public function test_get_items() { 59 wp_set_current_user( $this->editor_id );60 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->post_id . '/revisions' );77 wp_set_current_user( self::$editor_id ); 78 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 61 79 $response = $this->server->dispatch( $request ); 62 80 $data = $response->get_data(); … … 74 92 public function test_get_items_no_permission() { 75 93 wp_set_current_user( 0 ); 76 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->post_id . '/revisions' );94 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 77 95 $response = $this->server->dispatch( $request ); 78 96 79 97 $this->assertErrorResponse( 'rest_cannot_read', $response, 401 ); 80 wp_set_current_user( $this->contributor_id );98 wp_set_current_user( self::$contributor_id ); 81 99 $response = $this->server->dispatch( $request ); 82 100 $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); … … 84 102 85 103 public function test_get_items_missing_parent() { 86 wp_set_current_user( $this->editor_id );104 wp_set_current_user( self::$editor_id ); 87 105 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions' ); 88 106 $response = $this->server->dispatch( $request ); … … 91 109 92 110 public function test_get_items_invalid_parent_post_type() { 93 wp_set_current_user( $this->editor_id );94 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->page_id . '/revisions' );111 wp_set_current_user( self::$editor_id ); 112 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$page_id . '/revisions' ); 95 113 $response = $this->server->dispatch( $request ); 96 114 $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 ); … … 98 116 99 117 public function test_get_item() { 100 wp_set_current_user( $this->editor_id );101 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->post_id . '/revisions/' . $this->revision_id1 );118 wp_set_current_user( self::$editor_id ); 119 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 102 120 $response = $this->server->dispatch( $request ); 103 121 $this->assertEquals( 200, $response->get_status() ); … … 122 140 123 141 public function test_get_item_embed_context() { 124 wp_set_current_user( $this->editor_id );125 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->post_id . '/revisions/' . $this->revision_id1 );142 wp_set_current_user( self::$editor_id ); 143 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 126 144 $request->set_param( 'context', 'embed' ); 127 145 $response = $this->server->dispatch( $request ); … … 141 159 public function test_get_item_no_permission() { 142 160 wp_set_current_user( 0 ); 143 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->post_id . '/revisions/' . $this->revision_id1 );161 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 144 162 145 163 $response = $this->server->dispatch( $request ); 146 164 $this->assertErrorResponse( 'rest_cannot_read', $response, 401 ); 147 wp_set_current_user( $this->contributor_id );165 wp_set_current_user( self::$contributor_id ); 148 166 $response = $this->server->dispatch( $request ); 149 167 $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); … … 151 169 152 170 public function test_get_item_missing_parent() { 153 wp_set_current_user( $this->editor_id );171 wp_set_current_user( self::$editor_id ); 154 172 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions/' . $this->revision_id1 ); 155 173 $response = $this->server->dispatch( $request ); … … 158 176 159 177 public function test_get_item_invalid_parent_post_type() { 160 wp_set_current_user( $this->editor_id );161 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->page_id . '/revisions/' . $this->revision_id1 );178 wp_set_current_user( self::$editor_id ); 179 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$page_id . '/revisions/' . $this->revision_id1 ); 162 180 $response = $this->server->dispatch( $request ); 163 181 $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 ); … … 165 183 166 184 public function test_delete_item() { 167 wp_set_current_user( $this->editor_id );168 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $this->post_id . '/revisions/' . $this->revision_id1 );185 wp_set_current_user( self::$editor_id ); 186 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 169 187 $response = $this->server->dispatch( $request ); 170 188 $this->assertEquals( 200, $response->get_status() ); … … 173 191 174 192 public function test_delete_item_no_permission() { 175 wp_set_current_user( $this->contributor_id );176 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $this->post_id . '/revisions/' . $this->revision_id1 );193 wp_set_current_user( self::$contributor_id ); 194 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 177 195 $response = $this->server->dispatch( $request ); 178 196 $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); … … 180 198 181 199 public function test_prepare_item() { 182 wp_set_current_user( $this->editor_id );183 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->post_id . '/revisions/' . $this->revision_id1 );200 wp_set_current_user( self::$editor_id ); 201 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 184 202 $response = $this->server->dispatch( $request ); 185 203 $this->assertEquals( 200, $response->get_status() ); … … 188 206 189 207 public function test_get_item_schema() { 190 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . $this->post_id . '/revisions' );208 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 191 209 $response = $this->server->dispatch( $request ); 192 210 $data = $response->get_data(); … … 208 226 209 227 public function test_create_item() { 210 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . $this->post_id . '/revisions' );228 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 211 229 $response = $this->server->dispatch( $request ); 212 230 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); … … 214 232 215 233 public function test_update_item() { 216 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . $this->post_id . '/revisions/' . $this->revision_id1 );234 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 217 235 $response = $this->server->dispatch( $request ); 218 236 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); … … 234 252 ) ); 235 253 236 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . $this->post_id . '/revisions' );254 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 237 255 238 256 $response = $this->server->dispatch( $request ); … … 244 262 wp_set_current_user( 1 ); 245 263 246 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->post_id . '/revisions/' . $this->revision_id1 );264 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 247 265 248 266 $response = $this->server->dispatch( $request );
Note: See TracChangeset
for help on using the changeset viewer.