Tests: Move the wp_list_pages() test for CSS classes to a more appropriate place.

Back when this test was introduced, `wp_list_pages()` did not have its own test class.

It does now, so the test can be moved there, instead of being hidden among `get_pages()` tests.

Includes:
* Updating the test name for clarity.
* Adding an unique message for each assertion.

Follow-up to [27755], [28400].

See #57841.

git-svn-id: https://develop.svn.wordpress.org/trunk@55588 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2023-03-24 14:58:39 +00:00
parent dfc078d19d
commit 1de4538a38
2 changed files with 53 additions and 33 deletions
-33
View File
@@ -740,39 +740,6 @@ class Tests_Post_GetPages extends WP_UnitTestCase {
}
public function test_wp_list_pages_classes() {
$type = 'taco';
register_post_type(
$type,
array(
'hierarchical' => true,
'public' => true,
)
);
$posts = self::factory()->post->create_many( 2, array( 'post_type' => $type ) );
$post_id = reset( $posts );
$this->go_to( "/?p=$post_id&post_type=$type" );
$this->assertSame( $post_id, get_queried_object_id() );
$output = wp_list_pages(
array(
'echo' => false,
'title_li' => '',
'post_type' => $type,
)
);
$this->assertNotEmpty( $output );
$this->assertSame( 2, substr_count( $output, 'class="page_item ' ) );
$this->assertStringContainsString( 'current_page_item', $output );
$this->assertSame( 1, substr_count( $output, 'current_page_item' ) );
_unregister_post_type( $type );
}
/**
* @ticket 12821
*/
+53
View File
@@ -448,4 +448,57 @@ class Tests_Post_wpListPages extends WP_UnitTestCase {
$this->assertSame( $expected, wp_list_pages( $args ) );
}
public function test_wp_list_pages_classes_with_hierarchical_cpt() {
$args = array(
'echo' => false,
'post_type' => 'taco',
);
register_post_type(
$args['post_type'],
array(
'hierarchical' => true,
'public' => true,
)
);
$posts = self::factory()->post->create_many( 2, array( 'post_type' => $args['post_type'] ) );
$post_id = reset( $posts );
$this->go_to( "/?p={$post_id}&post_type={$args['post_type']}" );
$this->assertSame(
$post_id,
get_queried_object_id(),
'The queried object ID should match the ID of the requested CPT item.'
);
$output = wp_list_pages( $args );
_unregister_post_type( $args['post_type'] );
$this->assertNotEmpty(
$output,
'The output should not be empty.'
);
$this->assertSame(
2,
substr_count( $output, 'class="page_item ' ),
'The number of "page_item" classes should be equal to the total CPT items count.'
);
$this->assertStringContainsString(
'current_page_item',
$output,
'The output should contain the "current_page_item" class.'
);
$this->assertSame(
1,
substr_count( $output, 'current_page_item' ),
'The output should contain exactly one "current_page_item" class.'
);
}
}