mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user