From 617372e21edb88fa7f2f50f9a20cf7e1d90b54f4 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 15 Dec 2017 11:15:00 +0000 Subject: [PATCH] Improve performance of `wp_list_pages()` tests. The changeset also removes the use of hardcoded post/author IDs. Props frank-klein. Fixes #42903. git-svn-id: https://develop.svn.wordpress.org/trunk@42402 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/post/listPages.php | 412 ++++++++++++++----------- 1 file changed, 225 insertions(+), 187 deletions(-) diff --git a/tests/phpunit/tests/post/listPages.php b/tests/phpunit/tests/post/listPages.php index 1261d909b1..2c5a9a26c2 100644 --- a/tests/phpunit/tests/post/listPages.php +++ b/tests/phpunit/tests/post/listPages.php @@ -1,63 +1,85 @@ 0, - 'show_date' => '', - 'date_format' => get_option('date_format'), - 'child_of' => 0, - 'exclude' => '', - 'title_li' => __('Pages'), - 'echo' => 1, - 'authors' => '', - 'sort_column' => 'menu_order, post_title', - 'link_before' => '', - 'link_after' => '', - 'walker' => '', - 'item_spacing' => 'preserve', - 'include' => '', - 'post_type' => 'page', - 'post_status' => 'publish', - ); - */ - function setUp() { - parent::setUp(); - global $wpdb; - $wpdb->query( 'TRUNCATE ' . $wpdb->prefix . 'posts' ); - $this->time = time(); - $post_date = date( 'Y-m-d H:i:s', $this->time ); - $pages = array(); - self::factory()->user->create(); - $pages[] = self::factory()->post->create( + /** + * Parent page id. + * + * @var int + */ + public static $parent_2; + + /** + * Parent page id. + * + * @var int + */ + public static $parent_3; + + /** + * Child page ids. + * + * @var array + */ + public static $children = array(); + + /** + * Current timestamp cache, so that it is consistent across posts. + * + * @var int + */ + public static $time; + + public static function wpSetupBeforeClass() { + self::$time = time(); + + $post_date = date( 'Y-m-d H:i:s', self::$time ); + + self::$parent_1 = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 1', 'post_date' => $post_date, ) ); - $pages[] = self::factory()->post->create( + + self::$author = self::factory()->user->create( array( 'role' => 'author' ) ); + + self::$parent_2 = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 2', 'post_date' => $post_date, ) ); - $pages[] = self::factory()->post->create( + + self::$parent_3 = self::factory()->post->create( array( + 'post_author' => self::$author, 'post_type' => 'page', 'post_title' => 'Parent 3', - 'post_author' => '2', 'post_date' => $post_date, ) ); - foreach ( $pages as $page ) { - $this->pages[ $page ] = self::factory()->post->create( + foreach ( array( self::$parent_1, self::$parent_2, self::$parent_3 ) as $page ) { + self::$children[ $page ][] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', @@ -65,7 +87,7 @@ class Tests_List_Pages extends WP_UnitTestCase { 'post_date' => $post_date, ) ); - $this->pages[ $page ] = self::factory()->post->create( + self::$children[ $page ][] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', @@ -73,7 +95,7 @@ class Tests_List_Pages extends WP_UnitTestCase { 'post_date' => $post_date, ) ); - $this->pages[ $page ] = self::factory()->post->create( + self::$children[ $page ][] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', @@ -85,316 +107,332 @@ class Tests_List_Pages extends WP_UnitTestCase { } function test_wp_list_pages_default() { - $args = array( + $args = array( 'echo' => false, ); - $expected['default'] = '