Changeset 61269
- Timestamp:
- 11/19/2025 06:01:22 AM (2 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
src/wp-includes/post-template.php (modified) (1 diff)
-
tests/phpunit/tests/post/getPostClass.php (modified) (1 diff)
-
tests/phpunit/tests/rest-api/rest-posts-controller.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-template.php
r60222 r61269 607 607 $classes = apply_filters( 'post_class', $classes, $css_class, $post->ID ); 608 608 609 return array_unique( $classes ); 609 $classes = array_unique( $classes ); 610 $classes = array_values( $classes ); 611 612 return $classes; 610 613 } 611 614 -
trunk/tests/phpunit/tests/post/getPostClass.php
r55745 r61269 136 136 $this->assertSame( $num_queries, get_num_queries() ); 137 137 } 138 139 /** 140 * @ticket 64247 141 */ 142 public function test_list_return_value_when_duplicate_classes() { 143 144 // Filter 'post_class' to add a duplicate which should be removed by `array_unique()`. 145 add_filter( 146 'post_class', 147 function ( $classes ) { 148 return array_merge( 149 array( 'duplicate-class', 'duplicate-class' ), 150 $classes 151 ); 152 } 153 ); 154 155 $class_list = get_post_class( 'original', $this->post_id ); 156 $this->assertTrue( array_is_list( $class_list ), 'Expected get_post_class() to return list.' ); 157 $this->assertContains( 'duplicate-class', $class_list ); 158 $this->assertContains( 'original', $class_list ); 159 } 138 160 } -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r60251 r61269 2774 2774 'Incorrect word count in the excerpt. Expected the excerpt to contain 44 words (43 words plus an ellipsis), but a different word count was found.' 2775 2775 ); 2776 } 2777 2778 /** 2779 * Test that the `class_list` property is a list. 2780 * 2781 * @ticket 64247 2782 * 2783 * @covers WP_REST_Posts_Controller::prepare_item_for_response 2784 */ 2785 public function test_class_list_is_list() { 2786 $post_id = self::factory()->post->create(); 2787 2788 // Filter 'post_class' to add a duplicate which should be removed by `array_unique()`. 2789 add_filter( 2790 'post_class', 2791 function ( $classes ) { 2792 return array_merge( 2793 array( 'duplicate-class', 'duplicate-class' ), 2794 $classes 2795 ); 2796 } 2797 ); 2798 2799 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 2800 $response = rest_do_request( $request ); 2801 $data = $response->get_data(); 2802 2803 $this->assertArrayHasKey( 'class_list', $data ); 2804 $this->assertContains( 'duplicate-class', $data['class_list'] ); 2805 $this->assertTrue( array_is_list( $data['class_list'] ), 'Expected class_list to be a list.' ); 2776 2806 } 2777 2807
Note: See TracChangeset
for help on using the changeset viewer.