Make WordPress Core


Ignore:
Timestamp:
03/24/2023 02:58:39 PM (20 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/wpListPages.php

    r52010 r55588  
    449449        $this->assertSame( $expected, wp_list_pages( $args ) );
    450450    }
     451
     452    public function test_wp_list_pages_classes_with_hierarchical_cpt() {
     453        $args = array(
     454            'echo'      => false,
     455            'post_type' => 'taco',
     456        );
     457
     458        register_post_type(
     459            $args['post_type'],
     460            array(
     461                'hierarchical' => true,
     462                'public'       => true,
     463            )
     464        );
     465
     466        $posts   = self::factory()->post->create_many( 2, array( 'post_type' => $args['post_type'] ) );
     467        $post_id = reset( $posts );
     468
     469        $this->go_to( "/?p={$post_id}&post_type={$args['post_type']}" );
     470
     471        $this->assertSame(
     472            $post_id,
     473            get_queried_object_id(),
     474            'The queried object ID should match the ID of the requested CPT item.'
     475        );
     476
     477        $output = wp_list_pages( $args );
     478
     479        _unregister_post_type( $args['post_type'] );
     480
     481        $this->assertNotEmpty(
     482            $output,
     483            'The output should not be empty.'
     484        );
     485
     486        $this->assertSame(
     487            2,
     488            substr_count( $output, 'class="page_item ' ),
     489            'The number of "page_item" classes should be equal to the total CPT items count.'
     490        );
     491
     492        $this->assertStringContainsString(
     493            'current_page_item',
     494            $output,
     495            'The output should contain the "current_page_item" class.'
     496        );
     497
     498        $this->assertSame(
     499            1,
     500            substr_count( $output, 'current_page_item' ),
     501            'The output should contain exactly one "current_page_item" class.'
     502        );
     503    }
    451504}
Note: See TracChangeset for help on using the changeset viewer.