• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress develop tests

WordPress develop tests

WordPress develop tests a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Tests_Admin_includesListTable::_test_list_hierarchical_page() – Helper function to test the output of a page which uses `WP_Posts_List_Table`.

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_includesListTable::_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/includesListTable.php


Lines:

1 to 41 of 41
  protected function _test_list_hierarchical_page( array $args, array $expected_ids ) {
    $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;
    }

    $pages = new WP_Query( $args );

    ob_start();
    $this->table->set_hierarchical_display( true );
    $this->table->display_rows( $pages->posts );
    $output = ob_get_clean();

    // 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->assertContains( sprintf( 'id="post-%d"', $id ), $output );
    }
  }
 

 View on GitHub

Published: 26th November 2019 | Last updated: 27th November 2019

Primary Sidebar

Information

Function name: Tests_Admin_includesListTable::_test_list_hierarchical_page
Class ref: Tests_Admin_includesListTable
Plugin ref: WordPress develop tests
Version: 5.3
Sourcefile: phpunit/tests/admin/includesListTable.php
File ref: phpunit/tests/admin/includesListTable.php
Deprecated?: No
API Letters: A,I,T

Footer

WordPress develop tests
WordPress develop tests
WordPress develop tests a2z
WordPress 5.6.2
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  develop.wp-a2z.org
© Copyright WordPress develop tests 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites