Make WordPress Core

Changeset 55588 for trunk


Ignore:
Timestamp:
03/24/2023 02:58:39 PM (14 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.

Location:
trunk/tests/phpunit/tests/post
Files:
2 edited

Legend:

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

    r55583 r55588  
    741741    }
    742742
    743     public function test_wp_list_pages_classes() {
    744         $type = 'taco';
    745         register_post_type(
    746             $type,
    747             array(
    748                 'hierarchical' => true,
    749                 'public'       => true,
    750             )
    751         );
    752 
    753         $posts   = self::factory()->post->create_many( 2, array( 'post_type' => $type ) );
    754         $post_id = reset( $posts );
    755 
    756         $this->go_to( "/?p=$post_id&post_type=$type" );
    757 
    758         $this->assertSame( $post_id, get_queried_object_id() );
    759 
    760         $output = wp_list_pages(
    761             array(
    762                 'echo'      => false,
    763                 'title_li'  => '',
    764                 'post_type' => $type,
    765             )
    766         );
    767 
    768         $this->assertNotEmpty( $output );
    769         $this->assertSame( 2, substr_count( $output, 'class="page_item ' ) );
    770         $this->assertStringContainsString( 'current_page_item', $output );
    771         $this->assertSame( 1, substr_count( $output, 'current_page_item' ) );
    772 
    773         _unregister_post_type( $type );
    774     }
    775 
    776743    /**
    777744     * @ticket 12821
  • 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.