From 1de4538a3809fffc8bf2852e0d8067fc35e03984 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 24 Mar 2023 14:58:39 +0000 Subject: [PATCH] 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 --- tests/phpunit/tests/post/getPages.php | 33 --------------- tests/phpunit/tests/post/wpListPages.php | 53 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/tests/phpunit/tests/post/getPages.php b/tests/phpunit/tests/post/getPages.php index 70b3382603..5ce9dc05e2 100644 --- a/tests/phpunit/tests/post/getPages.php +++ b/tests/phpunit/tests/post/getPages.php @@ -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 */ diff --git a/tests/phpunit/tests/post/wpListPages.php b/tests/phpunit/tests/post/wpListPages.php index f59585a71c..5bd1b7c9dc 100644 --- a/tests/phpunit/tests/post/wpListPages.php +++ b/tests/phpunit/tests/post/wpListPages.php @@ -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.' + ); + } }