Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query block enhanced pagination: Simplify test setup #55805

Merged
merged 1 commit into from Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 5 additions & 41 deletions phpunit/blocks/render-query-test.php
Expand Up @@ -10,45 +10,10 @@
*/
class Tests_Blocks_RenderQueryBlock extends WP_UnitTestCase {

private static $post_1;
private static $post_2;
private static $post_3;
private static $posts;

public function set_up() {
parent::set_up();

self::$post_1 = self::factory()->post->create_and_get(
array(
'post_type' => 'post',
'post_status' => 'publish',
'post_name' => 'post-1',
'post_title' => 'Post 1',
'post_content' => 'Post 1 content',
'post_excerpt' => 'Post 1',
)
);

self::$post_2 = self::factory()->post->create_and_get(
array(
'post_type' => 'post',
'post_status' => 'publish',
'post_name' => 'post-2',
'post_title' => 'Post 2',
'post_content' => 'Post 2 content',
'post_excerpt' => 'Post 2',
)
);

self::$post_3 = self::factory()->post->create_and_get(
array(
'post_type' => 'post',
'post_status' => 'publish',
'post_name' => 'post-2',
'post_title' => 'Post 2',
'post_content' => 'Post 2 content',
'post_excerpt' => 'Post 2',
)
);
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$posts = $factory->post->create_many( 3 );

register_block_type(
'test/plugin-block',
Expand All @@ -60,9 +25,8 @@ public function set_up() {
);
}

public function tear_down() {
public static function wpTearDownAfterClass() {
unregister_block_type( 'test/plugin-block' );
parent::tear_down();
}

/**
Expand Down Expand Up @@ -109,7 +73,7 @@ public function test_rendering_query_with_enhanced_pagination() {
$this->assertSame( true, $p->get_attribute( 'data-wp-interactive' ) );

$p->next_tag( array( 'class_name' => 'wp-block-post' ) );
$this->assertSame( 'post-template-item-' . self::$post_2->ID, $p->get_attribute( 'data-wp-key' ) );
$this->assertSame( 'post-template-item-' . self::$posts[1], $p->get_attribute( 'data-wp-key' ) );

$p->next_tag( array( 'class_name' => 'wp-block-query-pagination-previous' ) );
$this->assertSame( 'query-pagination-previous', $p->get_attribute( 'data-wp-key' ) );
Expand Down