diff --git a/tests/phpunit/test-emitter-rest-api.php b/tests/phpunit/test-emitter-rest-api.php index a1152509..9d868406 100644 --- a/tests/phpunit/test-emitter-rest-api.php +++ b/tests/phpunit/test-emitter-rest-api.php @@ -67,24 +67,45 @@ public function test_get_posts_embed() { $response = $this->server->dispatch( $request ); $data = $this->server->response_to_data( $response, true ); $this->assertCount( 3, $data ); - $this->assertArrayValues( - array( - 'blog-1-rest-post-collection', - 'blog-1-rest-post-' . $this->post_id1, - 'blog-1-rest-post-' . $this->post_id2, - 'blog-1-rest-post-' . $this->post_id3, - 'blog-1-rest-comment-collection', - 'blog-1-rest-comment-' . $this->comment_id1, - 'blog-1-rest-comment-post-' . $this->post_id1, - 'blog-1-rest-category-collection', - 'blog-1-rest-term-1', - 'blog-1-rest-post_tag-collection', - 'blog-1-rest-term-' . $this->tag_id2, - 'blog-1-rest-user-' . $this->user_id1, - 'blog-1-rest-user-' . $this->user_id2, - ), - Emitter::get_rest_api_surrogate_keys() - ); + if ( ! is_multisite() ) { + $this->assertArrayValues( + array( + 'rest-post-collection', + 'rest-post-' . $this->post_id1, + 'rest-post-' . $this->post_id2, + 'rest-post-' . $this->post_id3, + 'rest-comment-collection', + 'rest-comment-' . $this->comment_id1, + 'rest-comment-post-' . $this->post_id1, + 'rest-category-collection', + 'rest-term-1', + 'rest-post_tag-collection', + 'rest-term-' . $this->tag_id2, + 'rest-user-' . $this->user_id1, + 'rest-user-' . $this->user_id2, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } else { + $this->assertArrayValues( + array( + 'blog-1-rest-post-collection', + 'blog-1-rest-post-' . $this->post_id1, + 'blog-1-rest-post-' . $this->post_id2, + 'blog-1-rest-post-' . $this->post_id3, + 'blog-1-rest-comment-collection', + 'blog-1-rest-comment-' . $this->comment_id1, + 'blog-1-rest-comment-post-' . $this->post_id1, + 'blog-1-rest-category-collection', + 'blog-1-rest-term-1', + 'blog-1-rest-post_tag-collection', + 'blog-1-rest-term-' . $this->tag_id2, + 'blog-1-rest-user-' . $this->user_id1, + 'blog-1-rest-user-' . $this->user_id2, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } } /** @@ -95,12 +116,21 @@ public function test_get_posts_no_results() { $request->set_param( 'author', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); $response = $this->server->dispatch( $request ); $this->assertCount( 0, $response->get_data() ); - $this->assertArrayValues( - array( - 'blog-1-rest-post-collection', - ), - Emitter::get_rest_api_surrogate_keys() - ); + if ( ! is_multisite() ) { + $this->assertArrayValues( + array( + 'rest-post-collection', + ), + Emitter::get_rest_api_surrogate_keys() + ); + } else { + $this->assertArrayValues( + array( + 'blog-1-rest-post-collection', + ), + Emitter::get_rest_api_surrogate_keys() + ); + } } /** @@ -111,12 +141,21 @@ public function test_get_post() { $response = $this->server->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( $this->post_id2, $data['id'] ); - $this->assertArrayValues( - array( - 'blog-1-rest-post-' . $this->post_id2, - ), - Emitter::get_rest_api_surrogate_keys() - ); + if ( ! is_multisite() ) { + $this->assertArrayValues( + array( + 'rest-post-' . $this->post_id2, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } else { + $this->assertArrayValues( + array( + 'blog-1-rest-post-' . $this->post_id2, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } } /** @@ -126,13 +165,23 @@ public function test_get_pages() { $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); $response = $this->server->dispatch( $request ); $this->assertCount( 1, $response->get_data() ); - $this->assertArrayValues( - array( - 'blog-1-rest-page-collection', - 'blog-1-rest-post-' . $this->page_id1, - ), - Emitter::get_rest_api_surrogate_keys() - ); + if ( ! is_multisite() ) { + $this->assertArrayValues( + array( + 'rest-page-collection', + 'rest-post-' . $this->page_id1, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } else { + $this->assertArrayValues( + array( + 'blog-1-rest-page-collection', + 'blog-1-rest-post-' . $this->page_id1, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } } /** @@ -143,12 +192,21 @@ public function test_get_page() { $response = $this->server->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( $this->page_id1, $data['id'] ); - $this->assertArrayValues( - array( - 'blog-1-rest-post-' . $this->page_id1, - ), - Emitter::get_rest_api_surrogate_keys() - ); + if ( ! is_multisite() ) { + $this->assertArrayValues( + array( + 'rest-post-' . $this->page_id1, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } else { + $this->assertArrayValues( + array( + 'blog-1-rest-post-' . $this->page_id1, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } } /** @@ -158,13 +216,23 @@ public function test_get_media() { $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); $response = $this->server->dispatch( $request ); $this->assertCount( 1, $response->get_data() ); - $this->assertArrayValues( - array( - 'blog-1-rest-attachment-collection', - 'blog-1-rest-post-' . $this->attachment_id1, - ), - Emitter::get_rest_api_surrogate_keys() - ); + if ( ! is_multisite() ) { + $this->assertArrayValues( + array( + 'rest-attachment-collection', + 'rest-post-' . $this->attachment_id1, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } else { + $this->assertArrayValues( + array( + 'blog-1-rest-attachment-collection', + 'blog-1-rest-post-' . $this->attachment_id1, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } } /** @@ -175,12 +243,21 @@ public function test_get_medii() { $response = $this->server->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( $this->attachment_id1, $data['id'] ); - $this->assertArrayValues( - array( - 'blog-1-rest-post-' . $this->attachment_id1, - ), - Emitter::get_rest_api_surrogate_keys() - ); + if ( ! is_multisite() ) { + $this->assertArrayValues( + array( + 'rest-post-' . $this->attachment_id1, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } else { + $this->assertArrayValues( + array( + 'blog-1-rest-post-' . $this->attachment_id1, + ), + Emitter::get_rest_api_surrogate_keys() + ); + } } /**