You appear to be a bot. Output may be restricted
Description
Helper function to test the output of a page which uses `WP_Posts_List_Table`.
Usage
Tests_Admin_wpPostsListTable::_test_list_hierarchical_page( $args, $expected_ids );
Parameters
- $args
- ( array ) required – Query args for the list of pages.
- $expected_ids
- ( array ) required – Expected IDs of pages returned.
Returns
void
Source
File name: wordpress-develop-tests/phpunit/tests/admin/wpPostsListTable.php
Lines:
1 to 53 of 53
protected function _test_list_hierarchical_page( array $args, array $expected_ids ) { if ( PHP_VERSION_ID >= 80100 ) { /* * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in * via hooked in filter functions until a more structural solution to the * "missing input validation" conundrum has been architected and implemented. */ $this->expectDeprecation(); $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' ); } $matches = array(); $_REQUEST['paged'] = $args['paged']; $GLOBALS['per_page'] = $args['posts_per_page']; $args = array_merge( array( 'post_type' => 'page', ), $args ); // Mimic the behaviour of `wp_edit_posts_query()`: if ( ! isset( $args['orderby'] ) ) { $args['orderby'] = 'menu_order title'; $args['order'] = 'asc'; $args['posts_per_page'] = -1; $args['posts_per_archive_page'] = -1; } // Effectively ignore the output until retrieving it later via `getActualOutput()`. $this->expectOutputRegex( '`.`' ); $pages = new WP_Query( $args ); $this->table->set_hierarchical_display( true ); $this->table->display_rows( $pages->posts ); $output = $this->getActualOutput(); // Clean up. unset( $_REQUEST['paged'] ); unset( $GLOBALS['per_page'] ); preg_match_all( '|<tr[^>]*>|', $output, $matches ); $this->assertCount( count( $expected_ids ), array_keys( $matches[0] ) ); foreach ( $expected_ids as $id ) { $this->assertStringContainsString( sprintf( 'id="post-%d"', $id ), $output ); } }