Changeset 40629
- Timestamp:
- 05/11/2017 06:31:26 PM (8 years ago)
- Location:
- trunk/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php
r40628 r40629 14 14 */ 15 15 class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase { 16 const YOUTUBE_VIDEO_ID = 'i_cVJgIz_Cs'; 16 17 17 18 public function setUp() { … … 22 23 $this->server = $wp_rest_server = new Spy_REST_Server; 23 24 do_action( 'rest_api_init' ); 25 26 add_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 ); 24 27 } 25 28 26 29 public function tearDown() { 27 30 parent::tearDown(); 28 remove_filter( 'rest_url', array( $this, 'test_rest_url_for_leading_slash' ), 10, 2 ); 31 29 32 /** @var WP_REST_Server $wp_rest_server */ 30 33 global $wp_rest_server; 31 34 $wp_rest_server = null; 35 36 remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 ); 37 } 38 39 public function mock_embed_request( $preempt, $r, $url ) { 40 unset( $preempt, $r ); 41 42 // Mock request to YouTube Embed. 43 if ( false !== strpos( $url, self::YOUTUBE_VIDEO_ID ) ) { 44 return array( 45 'response' => array( 46 'code' => 200, 47 ), 48 'body' => wp_json_encode( 49 array( 50 'version' => '1.0', 51 'type' => 'video', 52 'provider_name' => 'YouTube', 53 'provider_url' => 'https://www.youtube.com', 54 'thumbnail_width' => 480, 55 'width' => 500, 56 'thumbnail_height' => 360, 57 'html' => '<iframe width="500" height="375" src="https://www.youtube.com/embed/' . self::YOUTUBE_VIDEO_ID . '?feature=oembed" frameborder="0" allowfullscreen></iframe>', 58 'author_name' => 'Jorge Rubira Santos', 59 'thumbnail_url' => 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', 60 'title' => 'No te olvides de poner el Where en el Delete From. (Una cancion para programadores)', 61 'height' => 375, 62 ) 63 ), 64 ); 65 } else { 66 return array( 67 'response' => array( 68 'code' => 404, 69 ), 70 ); 71 } 32 72 } 33 73 … … 110 150 'post_content' => 'Updated post content.', 111 151 ) ); 152 $post_revisions = array_values( wp_get_post_revisions( $post_id ) ); 153 $post_revision_id = $post_revisions[ count( $post_revisions ) - 1 ]->ID; 112 154 113 155 $page_id = $this->factory->post->create( array( … … 125 167 'post_content' => 'Updated page content.', 126 168 ) ); 169 $page_revisions = array_values( wp_get_post_revisions( $page_id ) ); 170 $page_revision_id = $page_revisions[ count( $page_revisions ) - 1 ]->ID; 127 171 128 172 $tag_id = $this->factory->tag->create( array( … … 166 210 'route' => '/oembed/1.0/embed', 167 211 'name' => 'oembeds', 212 'args' => array( 213 'url' => '?p=' . $post_id, 214 ), 168 215 ), 169 216 array( 170 217 'route' => '/oembed/1.0/proxy', 171 218 'name' => 'oembedProxy', 219 'args' => array( 220 'url' => 'https://www.youtube.com/watch?v=i_cVJgIz_Cs', 221 ), 172 222 ), 173 223 array( … … 184 234 ), 185 235 array( 186 'route' => '/wp/v2/posts/' . $post_id . '/revisions/ 1',236 'route' => '/wp/v2/posts/' . $post_id . '/revisions/' . $post_revision_id, 187 237 'name' => 'revision', 188 238 ), … … 200 250 ), 201 251 array( 202 'route' => '/wp/v2/pages/'. $page_id . '/revisions/ 1',252 'route' => '/wp/v2/pages/'. $page_id . '/revisions/' . $page_revision_id, 203 253 'name' => 'pageRevision', 204 254 ), … … 216 266 ), 217 267 array( 218 'route' => '/wp/v2/types/ ',268 'route' => '/wp/v2/types/post', 219 269 'name' => 'TypeModel', 220 270 ), … … 268 318 ), 269 319 array( 270 'route' => '/wp/v2/comments/ 1',320 'route' => '/wp/v2/comments/' . $comment_id, 271 321 'name' => 'CommentModel', 272 322 ), … … 286 336 foreach ( $routes_to_generate_data as $route ) { 287 337 $request = new WP_REST_Request( 'GET', $route['route'] ); 338 if ( isset( $route['args'] ) ) { 339 $request->set_query_params( $route['args'] ); 340 } 288 341 $response = $this->server->dispatch( $request ); 342 $status = $response->get_status(); 289 343 $data = $response->get_data(); 290 344 345 $this->assertEquals( 346 200, 347 $response->get_status(), 348 "HTTP $status from $route[route]: " . json_encode( $data ) 349 ); 291 350 $this->assertTrue( ! empty( $data ), $route['name'] . ' route should return data.' ); 292 351 … … 320 379 */ 321 380 private static $fixture_replacements = array( 381 'oembeds.html' => '<blockquote class="wp-embedded-content">...</blockquote>', 322 382 'PostsCollection.0.id' => 3, 323 383 'PostsCollection.0.guid.rendered' => 'http://example.org/?p=3', … … 332 392 'PostModel.guid.rendered' => 'http://example.org/?p=3', 333 393 'PostModel.link' => 'http://example.org/?p=3', 334 'postRevisions.0.author' => '2',394 'postRevisions.0.author' => 2, 335 395 'postRevisions.0.id' => 4, 336 396 'postRevisions.0.parent' => 3, … … 338 398 'postRevisions.0.guid.rendered' => 'http://example.org/?p=4', 339 399 'postRevisions.0._links.parent.0.href' => 'http://example.org/?rest_route=/wp/v2/posts/3', 400 'revision.author' => 2, 401 'revision.id' => 4, 402 'revision.parent' => 3, 403 'revision.slug' => '3-revision-v1', 404 'revision.guid.rendered' => 'http://example.org/?p=4', 340 405 'PagesCollection.0.id' => 5, 341 406 'PagesCollection.0.guid.rendered' => 'http://example.org/?page_id=5', … … 348 413 'PageModel.guid.rendered' => 'http://example.org/?page_id=5', 349 414 'PageModel.link' => 'http://example.org/?page_id=5', 350 'pageRevisions.0.author' => '2',415 'pageRevisions.0.author' => 2, 351 416 'pageRevisions.0.id' => 6, 352 417 'pageRevisions.0.parent' => 5, … … 354 419 'pageRevisions.0.guid.rendered' => 'http://example.org/?p=6', 355 420 'pageRevisions.0._links.parent.0.href' => 'http://example.org/?rest_route=/wp/v2/pages/5', 421 'pageRevision.author' => 2, 422 'pageRevision.id' => 6, 423 'pageRevision.parent' => 5, 424 'pageRevision.slug' => '5-revision-v1', 425 'pageRevision.guid.rendered' => 'http://example.org/?p=6', 356 426 'MediaCollection.0.id' => 7, 357 427 'MediaCollection.0.guid.rendered' => 'http://example.org/?attachment_id=7', … … 378 448 'CommentsCollection.0._links.self.0.href' => 'http://example.org/?rest_route=/wp/v2/comments/2', 379 449 'CommentsCollection.0._links.up.0.href' => 'http://example.org/?rest_route=/wp/v2/posts/3', 450 'CommentModel.id' => 2, 451 'CommentModel.post' => 3, 452 'CommentModel.link' => 'http://example.org/?p=3#comment-2', 380 453 ); 381 454 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r40628 r40629 3502 3502 3503 3503 mockedApiResponse.oembeds = { 3504 "code": "rest_missing_callback_param", 3505 "message": "Missing parameter(s): url", 3506 "data": { 3507 "status": 400, 3508 "params": [ 3509 "url" 3510 ] 3511 } 3504 "version": "1.0", 3505 "provider_name": "Test Blog", 3506 "provider_url": "http://example.org", 3507 "author_name": "Test Blog", 3508 "author_url": "http://example.org", 3509 "title": "REST API Client Fixture: Post", 3510 "type": "rich", 3511 "width": 600, 3512 "height": 338, 3513 "html": "<blockquote class=\"wp-embedded-content\">...</blockquote>" 3512 3514 }; 3513 3515 3514 3516 mockedApiResponse.oembedProxy = { 3515 "code": "rest_missing_callback_param", 3516 "message": "Missing parameter(s): url", 3517 "data": { 3518 "status": 400, 3519 "params": [ 3520 "url" 3521 ] 3522 } 3517 "version": "1.0", 3518 "type": "video", 3519 "provider_name": "YouTube", 3520 "provider_url": "https://www.youtube.com", 3521 "thumbnail_width": 480, 3522 "width": 500, 3523 "thumbnail_height": 360, 3524 "html": "<iframe width=\"500\" height=\"375\" src=\"https://www.youtube.com/embed/i_cVJgIz_Cs?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>", 3525 "author_name": "Jorge Rubira Santos", 3526 "thumbnail_url": "https://i.ytimg.com/vi/i_cVJgIz_Cs/hqdefault.jpg", 3527 "title": "No te olvides de poner el Where en el Delete From. (Una cancion para programadores)", 3528 "height": 375 3523 3529 }; 3524 3530 … … 3655 3661 mockedApiResponse.postRevisions = [ 3656 3662 { 3657 "author": "2",3663 "author": 2, 3658 3664 "date": "2017-02-14T00:00:00", 3659 3665 "date_gmt": "2017-02-14T00:00:00", … … 3686 3692 3687 3693 mockedApiResponse.revision = { 3688 "code": "rest_post_invalid_id", 3689 "message": "Invalid revision ID.", 3690 "data": { 3691 "status": 404 3694 "author": 2, 3695 "date": "2017-02-14T00:00:00", 3696 "date_gmt": "2017-02-14T00:00:00", 3697 "id": 4, 3698 "modified": "2017-02-14T00:00:00", 3699 "modified_gmt": "2017-02-14T00:00:00", 3700 "parent": 3, 3701 "slug": "3-revision-v1", 3702 "guid": { 3703 "rendered": "http://example.org/?p=4" 3704 }, 3705 "title": { 3706 "rendered": "REST API Client Fixture: Post" 3707 }, 3708 "content": { 3709 "rendered": "<p>Updated post content.</p>\n" 3710 }, 3711 "excerpt": { 3712 "rendered": "<p>REST API Client Fixture: Post</p>\n" 3692 3713 } 3693 3714 }; … … 3805 3826 mockedApiResponse.pageRevisions = [ 3806 3827 { 3807 "author": "2",3828 "author": 2, 3808 3829 "date": "2017-02-14T00:00:00", 3809 3830 "date_gmt": "2017-02-14T00:00:00", … … 3836 3857 3837 3858 mockedApiResponse.pageRevision = { 3838 "code": "rest_post_invalid_id", 3839 "message": "Invalid revision ID.", 3840 "data": { 3841 "status": 404 3859 "author": 2, 3860 "date": "2017-02-14T00:00:00", 3861 "date_gmt": "2017-02-14T00:00:00", 3862 "id": 6, 3863 "modified": "2017-02-14T00:00:00", 3864 "modified_gmt": "2017-02-14T00:00:00", 3865 "parent": 5, 3866 "slug": "5-revision-v1", 3867 "guid": { 3868 "rendered": "http://example.org/?p=6" 3869 }, 3870 "title": { 3871 "rendered": "REST API Client Fixture: Page" 3872 }, 3873 "content": { 3874 "rendered": "<p>Updated page content.</p>\n" 3875 }, 3876 "excerpt": { 3877 "rendered": "<p>REST API Client Fixture: Page</p>\n" 3842 3878 } 3843 3879 }; … … 4026 4062 4027 4063 mockedApiResponse.TypeModel = { 4028 "code": "rest_no_route", 4029 "message": "No route was found matching the URL and request method", 4030 "data": { 4031 "status": 404 4032 } 4064 "description": "", 4065 "hierarchical": false, 4066 "name": "Posts", 4067 "slug": "post", 4068 "taxonomies": [ 4069 "category", 4070 "post_tag" 4071 ], 4072 "rest_base": "posts" 4033 4073 }; 4034 4074 … … 4431 4471 4432 4472 mockedApiResponse.CommentModel = { 4433 "code": "rest_comment_invalid_id", 4434 "message": "Invalid comment ID.", 4435 "data": { 4436 "status": 404 4437 } 4473 "id": 2, 4474 "post": 3, 4475 "parent": 0, 4476 "author": 0, 4477 "author_name": "Internet of something or other", 4478 "author_url": "http://lights.example.org/", 4479 "date": "2017-02-14T00:00:00", 4480 "date_gmt": "2017-02-14T00:00:00", 4481 "content": { 4482 "rendered": "<p>This is a comment</p>\n" 4483 }, 4484 "link": "http://example.org/?p=3#comment-2", 4485 "status": "approved", 4486 "type": "comment", 4487 "author_avatar_urls": { 4488 "24": "http://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=24&d=mm&r=g", 4489 "48": "http://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=48&d=mm&r=g", 4490 "96": "http://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=96&d=mm&r=g" 4491 }, 4492 "meta": [] 4438 4493 }; 4439 4494
Note: See TracChangeset
for help on using the changeset viewer.