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'] = '
Pages- Parent 1
+
+ $expected = '
- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['default'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_depth() {
- $args = array(
+ $args = array(
'echo' => false,
'depth' => 1,
);
- $expected['depth'] = '- Pages
- Parent 1
-- Parent 2
-- Parent 3
+
+ $expected = '- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['depth'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_show_date() {
- $args = array(
+ $args = array(
'echo' => false,
'depth' => 1,
'show_date' => true,
);
- $date = date( get_option( 'date_format' ), $this->time );
- $expected['show_date'] = '- Pages
- Parent 1 ' . $date . '
-- Parent 2 ' . $date . '
-- Parent 3 ' . $date . '
+ $date = date( get_option( 'date_format' ), self::$time );
+
+ $expected = '- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['show_date'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_date_format() {
- $args = array(
+ $args = array(
'echo' => false,
'show_date' => true,
'date_format' => 'l, F j, Y',
);
- $date = date( $args['date_format'], $this->time );
- $expected['date_format'] = '- Pages
- Parent 1 ' . $date . '
+ $date = date( $args['date_format'], self::$time );
+
+ $expected = '
- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['date_format'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_child_of() {
- $args = array(
+ $args = array(
'echo' => false,
- 'child_of' => 2,
+ 'child_of' => self::$parent_2,
);
- $expected['child_of'] = '- Pages
- Child 1
-- Child 2
-- Child 3
+
+ $expected = '- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['child_of'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_exclude() {
- $args = array(
+ $args = array(
'echo' => false,
- 'exclude' => '2, 2',
+ 'exclude' => self::$parent_2,
);
- $expected['exclude'] = '- Pages
- Parent 1
+
+ $expected = '
- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['exclude'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_title_li() {
- $args = array(
+ $args = array(
'echo' => false,
'depth' => 1,
'title_li' => 'PageTitle',
);
- $expected['title_li'] = '- PageTitle
- Parent 1
-- Parent 2
-- Parent 3
+
+ $expected = '- PageTitle
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['title_li'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_echo() {
- $args = array(
+ $args = array(
'echo' => true,
'depth' => 1,
);
- $expected['echo'] = '- Pages
- Parent 1
-- Parent 2
-- Parent 3
+
+ $expected = '- Pages
';
- $this->expectOutputString( $expected['echo'] );
+ $this->expectOutputString( $expected );
wp_list_pages( $args );
}
function test_wp_list_pages_authors() {
- $args = array(
+ $args = array(
'echo' => false,
- 'authors' => '2',
+ 'authors' => self::$author,
);
- $expected['authors'] = '- Pages
- Parent 3
+
+ $expected = '- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['authors'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_number() {
- $args = array(
+ $args = array(
'echo' => false,
'number' => 1,
);
- $expected['number'] = '- Pages
- Child 1
+
+ $expected = '- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['number'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_sort_column() {
- $args = array(
+ $args = array(
'echo' => false,
'sort_column' => 'post_author',
'sort_order' => 'DESC',
);
- $expected['sort_column'] = '- Pages
- Parent 3
+
+ $expected = '
- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['sort_column'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_link_before() {
- $args = array(
+ $args = array(
'echo' => false,
'link_before' => 'BEFORE',
);
- $expected['link_before'] = '- Pages
- BEFOREParent 1
+
+ $expected = '
- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['link_before'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_link_after() {
- $args = array(
+ $args = array(
'echo' => false,
'link_after' => 'AFTER',
);
- $expected['link_after'] = '- Pages
- Parent 1AFTER
+
+ $expected = '
- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['link_after'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_include() {
- $args = array(
+ $args = array(
'echo' => false,
- 'include' => '1,3',
+ 'include' => self::$parent_1 . ',' . self::$parent_3,
);
- $expected['include'] = '- Pages
- Parent 1
-- Parent 3
+
+ $expected = '- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['include'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_exclude_tree() {
- $args = array(
+ $args = array(
'echo' => false,
- 'exclude_tree' => '2, 3',
+ 'exclude_tree' => self::$parent_2 . ',' . self::$parent_3,
);
- $expected['exclude'] = '- Pages
- Parent 1
+
+ $expected = '
- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['exclude'], $actual );
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
function test_wp_list_pages_discarded_whitespace() {
- $args = array(
+ $args = array(
'echo' => false,
'item_spacing' => 'discard',
);
- $expected['default'] = '- Pages
';
- $actual = wp_list_pages( $args );
- $this->AssertEquals( $expected['default'], $actual );
+
+ $expected = '- Pages
';
+
+ $this->AssertEquals( $expected, wp_list_pages( $args ) );
}
}