Skip to content

Commit

Permalink
fix more tests?
Browse files Browse the repository at this point in the history
  • Loading branch information
John Spellman committed Apr 13, 2023
1 parent 4be7cd2 commit 0ed0d24
Showing 1 changed file with 133 additions and 56 deletions.
189 changes: 133 additions & 56 deletions tests/phpunit/test-emitter-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}

/**
Expand All @@ -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()
);
}
}

/**
Expand All @@ -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()
);
}
}

/**
Expand All @@ -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()
);
}
}

/**
Expand All @@ -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()
);
}
}

/**
Expand All @@ -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()
);
}
}

/**
Expand All @@ -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()
);
}
}

/**
Expand Down

0 comments on commit 0ed0d24

Please sign in to comment.