| 84 | | // Set up data for endpoints. |
| 85 | | $post_id = $this->factory->post->create(); |
| 86 | | $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
| 87 | | $tag_id = $this->factory->tag->create( array( 'name' => 'test' ) ); |
| | 90 | $post_id = $this->factory->post->create( array( |
| | 91 | 'post_name' => 'restapi-client-fixture-post', |
| | 92 | 'post_title' => 'REST API Client Fixture: Post', |
| | 93 | 'post_content' => 'REST API Client Fixture: Post', |
| | 94 | 'post_excerpt' => 'REST API Client Fixture: Post', |
| | 95 | 'post_author' => 0, |
| | 96 | ) ); |
| | 97 | wp_update_post( array( |
| | 98 | 'ID' => $post_id, |
| | 99 | 'post_content' => 'Updated post content.', |
| | 100 | ) ); |
| | 101 | |
| | 102 | $page_id = $this->factory->post->create( array( |
| | 103 | 'post_type' => 'page', |
| | 104 | 'post_name' => 'restapi-client-fixture-page', |
| | 105 | 'post_title' => 'REST API Client Fixture: Page', |
| | 106 | 'post_content' => 'REST API Client Fixture: Page', |
| | 107 | 'post_excerpt' => 'REST API Client Fixture: Page', |
| | 108 | 'post_date' => '2017-02-14 00:00:00', |
| | 109 | 'post_date_gmt' => '2017-02-14 00:00:00', |
| | 110 | 'post_author' => 0, |
| | 111 | ) ); |
| | 112 | wp_update_post( array( |
| | 113 | 'ID' => $page_id, |
| | 114 | 'post_content' => 'Updated page content.', |
| | 115 | ) ); |
| | 116 | |
| | 117 | $tag_id = $this->factory->tag->create( array( |
| | 118 | 'name' => 'REST API Client Fixture: Tag', |
| | 119 | 'slug' => 'restapi-client-fixture-tag', |
| | 120 | 'description' => 'REST API Client Fixture: Tag', |
| | 121 | ) ); |
| | 122 | |
| | 295 | |
| | 296 | /** |
| | 297 | * This array contains normalized versions of object IDs and other values |
| | 298 | * that can change depending on how PHPUnit is executed. For details on |
| | 299 | * how they were generated, see #39264. |
| | 300 | */ |
| | 301 | private static $fixture_replacements = array( |
| | 302 | 'PostsCollection.0.id' => 3, |
| | 303 | 'PostsCollection.0.guid.rendered' => 'http://example.org/?p=3', |
| | 304 | 'PostsCollection.0.link' => 'http://example.org/?p=3', |
| | 305 | 'PostsCollection.0._links.self.0.href' => 'http://example.org/?rest_route=/wp/v2/posts/3', |
| | 306 | 'PostsCollection.0._links.replies.0.href' => 'http://example.org/?rest_route=%2Fwp%2Fv2%2Fcomments&post=3', |
| | 307 | 'PostsCollection.0._links.version-history.0.href' => 'http://example.org/?rest_route=/wp/v2/posts/3/revisions', |
| | 308 | 'PostsCollection.0._links.wp:attachment.0.href' => 'http://example.org/?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3', |
| | 309 | 'PostsCollection.0._links.wp:term.0.href' => 'http://example.org/?rest_route=%2Fwp%2Fv2%2Fcategories&post=3', |
| | 310 | 'PostsCollection.0._links.wp:term.1.href' => 'http://example.org/?rest_route=%2Fwp%2Fv2%2Ftags&post=3', |
| | 311 | 'PostModel.id' => 3, |
| | 312 | 'PostModel.guid.rendered' => 'http://example.org/?p=3', |
| | 313 | 'PostModel.link' => 'http://example.org/?p=3', |
| | 314 | 'postRevisions.0.author' => '2', |
| | 315 | 'postRevisions.0.id' => 4, |
| | 316 | 'postRevisions.0.parent' => 3, |
| | 317 | 'postRevisions.0.slug' => '3-revision-v1', |
| | 318 | 'postRevisions.0.guid.rendered' => 'http://example.org/?p=4', |
| | 319 | 'postRevisions.0._links.parent.0.href' => 'http://example.org/?rest_route=/wp/v2/posts/3', |
| | 320 | 'PagesCollection.0.id' => 5, |
| | 321 | 'PagesCollection.0.guid.rendered' => 'http://example.org/?page_id=5', |
| | 322 | 'PagesCollection.0.link' => 'http://example.org/?page_id=5', |
| | 323 | 'PagesCollection.0._links.self.0.href' => 'http://example.org/?rest_route=/wp/v2/pages/5', |
| | 324 | 'PagesCollection.0._links.replies.0.href' => 'http://example.org/?rest_route=%2Fwp%2Fv2%2Fcomments&post=5', |
| | 325 | 'PagesCollection.0._links.version-history.0.href' => 'http://example.org/?rest_route=/wp/v2/pages/5/revisions', |
| | 326 | 'PagesCollection.0._links.wp:attachment.0.href' => 'http://example.org/?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5', |
| | 327 | 'PageModel.id' => 5, |
| | 328 | 'PageModel.guid.rendered' => 'http://example.org/?page_id=5', |
| | 329 | 'PageModel.link' => 'http://example.org/?page_id=5', |
| | 330 | 'pageRevisions.0.author' => '2', |
| | 331 | 'pageRevisions.0.id' => 6, |
| | 332 | 'pageRevisions.0.parent' => 5, |
| | 333 | 'pageRevisions.0.slug' => '5-revision-v1', |
| | 334 | 'pageRevisions.0.guid.rendered' => 'http://example.org/?p=6', |
| | 335 | 'pageRevisions.0._links.parent.0.href' => 'http://example.org/?rest_route=/wp/v2/pages/5', |
| | 336 | 'MediaCollection.0.id' => 7, |
| | 337 | 'MediaCollection.0.guid.rendered' => 'http://example.org/?attachment_id=7', |
| | 338 | 'MediaCollection.0.link' => 'http://example.org/?attachment_id=7', |
| | 339 | 'MediaCollection.0._links.self.0.href' => 'http://example.org/?rest_route=/wp/v2/media/7', |
| | 340 | 'MediaCollection.0._links.replies.0.href' => 'http://example.org/?rest_route=%2Fwp%2Fv2%2Fcomments&post=7', |
| | 341 | 'MediaModel.id' => 7, |
| | 342 | 'MediaModel.guid.rendered' => 'http://example.org/?attachment_id=7', |
| | 343 | 'MediaModel.link' => 'http://example.org/?attachment_id=7', |
| | 344 | 'TagsCollection.0.id' => 2, |
| | 345 | 'TagsCollection.0._links.self.0.href' => 'http://example.org/?rest_route=/wp/v2/tags/2', |
| | 346 | 'TagsCollection.0._links.wp:post_type.0.href' => 'http://example.org/?rest_route=%2Fwp%2Fv2%2Fposts&tags=2', |
| | 347 | 'TagModel.id' => 2, |
| | 348 | 'UsersCollection.1.id' => 2, |
| | 349 | 'UsersCollection.1.link' => 'http://example.org/?author=2', |
| | 350 | 'UsersCollection.1._links.self.0.href' => 'http://example.org/?rest_route=/wp/v2/users/2', |
| | 351 | 'UserModel.id' => 2, |
| | 352 | 'UserModel.link' => 'http://example.org/?author=2', |
| | 353 | 'me.id' => 2, |
| | 354 | 'me.link' => 'http://example.org/?author=2', |
| | 355 | 'CommentsCollection.0.id' => 2, |
| | 356 | 'CommentsCollection.0.post' => 3, |
| | 357 | 'CommentsCollection.0.link' => 'http://example.org/?p=3#comment-2', |
| | 358 | 'CommentsCollection.0._links.self.0.href' => 'http://example.org/?rest_route=/wp/v2/comments/2', |
| | 359 | 'CommentsCollection.0._links.up.0.href' => 'http://example.org/?rest_route=/wp/v2/posts/3', |
| | 360 | ); |
| | 361 | |
| | 362 | private function normalize_fixture( $data, $path ) { |
| | 363 | if ( isset( self::$fixture_replacements[ $path ] ) ) { |
| | 364 | return self::$fixture_replacements[ $path ]; |
| | 365 | } |
| | 366 | |
| | 367 | if ( ! is_array( $data ) ) { |
| | 368 | return $data; |
| | 369 | } |
| | 370 | |
| | 371 | foreach ( $data as $key => $value ) { |
| | 372 | if ( is_string( $value ) && ( |
| | 373 | 'date' === $key || |
| | 374 | 'date_gmt' === $key || |
| | 375 | 'modified' === $key || |
| | 376 | 'modified_gmt' === $key |
| | 377 | ) ) { |
| | 378 | $data[ $key ] = '2017-02-14T00:00:00'; |
| | 379 | } else { |
| | 380 | $data[ $key ] = $this->normalize_fixture( $value, "$path.$key" ); |
| | 381 | } |
| | 382 | } |
| | 383 | |
| | 384 | return $data; |
| | 385 | } |